ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • Elasticsearch에서 AWS OpenSearch로의 마이그레이션
    DB 2024. 9. 28. 10:26

    1. 현재 환경 분석

    1.1 Elasticsearch 버전 확인

    • 명령어: curl -X GET "localhost:9200"
    • 결과 분석: 버전 호환성 확인 (OpenSearch는 Elasticsearch 7.10.2 버전과 호환)

    1.2 데이터 볼륨 및 인덱스 구조 파악

    • 명령어:
    curl -X GET "localhost:9200/_cat/indices?v"
    curl -X GET "localhost:9200/_cat/shards?v"

     

    • 결과 분석: 총 데이터 크기, 인덱스 수, 샤드 분포 확인

    1.3 플러그인 및 커스텀 설정 식별

    • 명령어:
    curl -X GET "localhost:9200/_cat/plugins?v"
    curl -X GET "localhost:9200/_nodes/settings?pretty"

     

    • 결과 분석: 사용 중인 플러그인 목록 작성, 커스텀 설정 문서화

    2. AWS OpenSearch 환경 설정

    2.1 OpenSearch 도메인 생성

    AWS 관리 콘솔 사용 또는 AWS CLI 명령어:

    aws opensearch create-domain --domain-name my-domain --engine-version OpenSearch_1.3 --cluster-config InstanceType=r6g.large.search,InstanceCount=3 --ebs-options EBSEnabled=true,VolumeType=gp3,VolumeSize=100 --node-to-node-encryption-options Enabled=true --encryption-at-rest-options Enabled=true --domain-endpoint-options EnforceHTTPS=true --advanced-security-options Enabled=true,InternalUserDatabaseEnabled=true,MasterUserOptions='{MasterUserName=admin,MasterUserPassword=YOUR-PASSWORD}' --access-policies '{"Version":"2012-10-17","Statement":[{"Effect":"Allow","Principal":{"AWS":["*"]},"Action":["es:*"],"Resource":"arn:aws:es:REGION:ACCOUNT-ID:domain/my-domain/*"}]}'

    2.2 네트워크 설정

    • VPC, 서브넷, 보안 그룹 구성 (AWS 관리 콘솔 또는 AWS CLI 사용)

    3. 데이터 마이그레이션 전략 수립

    3.1 스냅샷 생성 및 복원

    • Elasticsearch에서 스냅샷 생성:
    PUT /_snapshot/my_backup
    {
      "type": "fs",
      "settings": {
        "location": "/path/to/snapshot/directory"
      }
    }
    
    PUT /_snapshot/my_backup/snapshot_1?wait_for_completion=true
    • OpenSearch로 스냅샷 복원:
     
    POST /_snapshot/my_backup/snapshot_1/_restore

     

    3.2 실시간 데이터 복제 (Logstash 사용)

    • Logstash 구성 파일 (logstash.conf):
       
    input {
      elasticsearch {
        hosts => ["http://old-elasticsearch:9200"]
        index => "*"
        docinfo => true
      }
    }
    
    output {
      amazon_es {
        hosts => ["https://new-opensearch-endpoint"]
        region => "us-west-2"
        aws_access_key_id => "YOUR_ACCESS_KEY"
        aws_secret_access_key => "YOUR_SECRET_KEY"
        index => "%{[@metadata][_index]}"
      }
    }

     

    • Logstash 실행: bin/logstash -f logstash.conf

    4. 애플리케이션 수정

    4.1 OpenSearch 클라이언트 라이브러리 업데이트

    • 예: Java 애플리케이션의 경우 pom.xml 수정: 
    • xml

       
    <dependency>
        <groupId>org.opensearch.client</groupId>
        <artifactId>opensearch-rest-high-level-client</artifactId>
        <version>1.3.0</version>
    </dependency>

     

    4.2 연결 문자열 및 인증 방식 변경

    • 예: Java 코드 수정 
    • java

       
    RestHighLevelClient client = new RestHighLevelClient(
        RestClient.builder(
            new HttpHost("your-opensearch-endpoint", 443, "https"))
        .setHttpClientConfigCallback(httpAsyncClientBuilder -> {
            return httpAsyncClientBuilder.setDefaultCredentialsProvider(
                new BasicCredentialsProvider()
                    .setCredentials(AuthScope.ANY,
                        new UsernamePasswordCredentials("username", "password")));
        })
    );

    5. 테스트

    5.1 개발/스테이징 환경에서 마이그레이션 테스트

    • 전체 마이그레이션 프로세스 실행
    • 데이터 정합성 검증 쿼리 실행

    5.2 성능 테스트

    • Apache JMeter를 사용한 부하 테스트 실행

    5.3 데이터 무결성 검증

    • 샘플 데이터 비교 쿼리 실행

    6. 마이그레이션 실행

    6.1 다운타임 최소화 전략

    • 읽기 전용 모드 전환: PUT /_settings { "index": { "blocks.write": true } }
    • 최종 데이터 동기화
    • 트래픽 전환

    6.2 롤백 계획

    • 이전 Elasticsearch 클러스터 유지
    • 빠른 DNS 전환 준비

    6.3 단계별 마이그레이션 실행

    • 체크리스트 기반 단계별 실행

    7. 모니터링 및 최적화

    7.1 CloudWatch 모니터링 설정

    • CloudWatch 대시보드 생성

    알람 설정:

     
    aws cloudwatch put-metric-alarm --alarm-name OpenSearch-CPU-Utilization --alarm-description "Alarm when CPU exceeds 75%" --metric-name CPUUtilization --namespace AWS/ES --statistic Average --period 300 --threshold 75 --comparison-operator GreaterThanThreshold --dimensions Name=DomainName,Value=my-domain Name=ClientId,Value=YOUR-ACCOUNT-ID --evaluation-periods 1 --alarm-actions arn:aws:sns:REGION:ACCOUNT-ID:TOPIC-NAME

    7.2 성능 최적화

    • 인덱스 설정 조정:
       
    •  
    PUT /my-index/_settings
    {
      "index" : {
        "number_of_replicas" : 2,
        "refresh_interval" : "30s"
      }
    }

     


    8. 문서화 및 교육

    8.1 새로운 환경 문서 작성

    • 아키텍처 다이어그램 생성
    • 운영 가이드 작성

    8.2 운영팀 교육

    • 핸즈온 세션 계획
    • Q&A 세션 준비
Designed by Tistory.