내용으로 건너뛰기

OpenSearch Service 클러스터에서 인덱스 패턴을 만들려면 어떻게 해야 합니까?

5분 분량
0

Amazon OpenSearch Service 클러스터에서 인덱스 패턴을 만들려고 합니다.

해결 방법

사전 요구 사항:

  • 인덱스 패턴을 만들려면 AWS Identity and Access Management(IAM) 사용자에게 PUT 및 POST 권한이 있어야 합니다. 액세스 정책 예시:
    {  "Version": "2012-10-17",
      "Statement": [
        {
          "Sid": "VisualEditor0",
          "Effect": "Allow",
          "Action": [
            "es:ESHttpHead",
            "es:ESHttpPost",
            "es:ESHttpGet",
            "es:ESHttpDelete",
            "es:ESHttpPut"
          ],
          "Resource": "arn:aws:es:region:account-id:domain/domain-name/*"
        }
      ]
    }
    참고: region을 AWS 리전으로, account-id를 AWS 계정으로, domain-name을 도메인 이름으로 바꾸십시오.
  • 클러스터 버전은 인덱스 패턴을 허용해야 합니다.

인덱스 패턴 만들기

OpenSearch 대시보드 사용

다음 지침에 따라 세분화된 액세스 제어 사용 여부에 관계없이 OpenSearch Service 또는 Elasticsearch 클러스터의 인덱스 패턴을 만들 수 있습니다. 자세한 내용은 OpenSearch 웹 사이트에서 인덱스 패턴 만들기를 참조하십시오.

curl 명령 사용

세분화된 액세스 제어 없이 클러스터의 인덱스 패턴을 만들려면 클러스터 유형에 따라 다음 명령을 실행합니다.

Elasticsearch 클러스터:

curl -X POST  https://elasticsearch-end-point/_plugin/kibana/api/saved_objects/index-pattern/ \
-H "kbn-xsrf: true" \

-H "content-type: application/json" \

-d '{ "attributes": { "title": "sample-index*" } }'

참고: sample-index를 인덱스 이름 또는 패턴으로 바꾸십시오.

OpenSearch Service 클러스터:

curl -X POST  https://opensearch-end-point/_dashboards/api/saved_objects/index-pattern/ \
-H "kbn-xsrf: true" \

-H "content-type: application/json" \

-d '{ "attributes": { "title": "sample-index*" } }'

참고: sample-index를 인덱스 이름 또는 패턴으로 바꾸십시오.

세분화된 액세스 제어가 있는 클러스터의 경우 다음 단계를 완료하십시오.

  1. auth.txt 파일에서 권한 부여 쿠키를 생성하려면 클러스터 유형에 따라 다음 명령을 실행합니다.
    Elasticsearch 클러스터:
    curl -X POST  https://elasticsearch-end-point/_plugin/kibana/auth/login  \
    -H "kbn-xsrf: true" \
    -H "content-type: application/json" \
    -d '{"username":"usernameexample", "password":"passwordexample"}' \
    -c auth.txt
    참고: usernameexample을 사용자 이름으로 바꾸고 passwordexample을 암호로 바꾸십시오.
    OpenSearch Service 클러스터:
    curl -X POST  https://opensearch-end-point/_dashboards/auth/login  \
    -H "kbn-xsrf: true" \
    -H "content-type: application/json" \
    -d '{"username":"usernameexample", "password":"passwordexample"}' \
    -c auth.txt
    참고: usernameexample을 사용자 이름으로 바꾸고 passwordexample을 암호로 바꾸십시오.
  2. 인덱스 패턴 만들기 요청을 제출하려면 클러스터 유형에 따라 다음 명령을 실행합니다.
    Elasticsearch 클러스터:
    curl -X POST  https://elasticsearch-end-point/_plugin/kibana/api/saved_objects/index-pattern/test  \
    -H "kbn-xsrf: true" \
    -H "content-type: application/json" \
    -d '{ "attributes": { "title": "sample-index*" } }' \
    -b auth.txt
    참고: sample-index를 인덱스 이름 또는 패턴으로 바꾸십시오.
    OpenSearch Service 클러스터:
    curl -X POST  https://opensearch-end-point/_dashboards/api/saved_objects/index-pattern/  \
    -H "kbn-xsrf: true" \
    -H "content-type: application/json" \
    -d '{ "attributes": { "title": "sample-index*" } }' \
    -b auth.txt
    참고: sample-index를 인덱스 이름 또는 패턴으로 바꾸십시오.

Python 사용

사전 요구 사항:

다음 Python 명령을 실행하여 OpenSearch Service 클러스터의 인덱스 패턴을 만듭니다.

import boto3
import requests
from requests_aws4auth import AWS4Auth

host = 'https://domain-endpoint/' # include trailing /
region = 'aos-region' # example us-west-1
service = 'es'
credentials = boto3.Session().get_credentials()
awsauth = AWS4Auth(credentials.access_key, credentials.secret_key, region, service, session_token=credentials.token)


path = '_dashboards/api/saved_objects/index-pattern' # _plugin/kibana/api/saved_objects/index-pattern for es versions
url = host + path
payload = {"attributes":{"title":"multi-logs-*","fields":"[]"}}
headers = {"Content-Type": "application/json", "osd-xsrf": "true", "security_tenant": "global" }
r = requests.post (url, auth=awsauth, json=payload, headers=headers)
print(r.status_code)
print(r.text)

참고: domain-endpoint를 도메인 엔드포인트로, aos-region을 리전으로 바꾸십시오. Elasticsearch 클러스터의 경우 _dashboards/api/saved_objects/index-pattern_plugin/kibana/api/saved_objects/index-pattern으로 바꾸십시오.

인덱스 패턴 만들기 문제 해결

SAML 2.0 또는 Amazon Cognito 인증을 통해 세분화된 액세스 제어 사용

클러스터의 도메인이 인증에 SAML 2.0 또는 Amazon Cognito를 사용하는 경우 인덱스 패턴을 관리할 내부 사용자를 만듭니다.

참고: 세분화된 액세스 제어를 활성화한 클러스터의 경우 사용자에게 ESHttpPutESHttpPost 권한이 있어야 인덱스 패턴을 만들 수 있습니다.

글로벌 테넌트에서는 인덱스 패턴을 만들 수 없음

기본적으로 OpenSearch 대시보드는 글로벌 테넌트 아래에 인덱스 패턴을 만듭니다. 글로벌 테넌트 외부에서 인덱스 패턴을 만들려면 다음 명령을 실행합니다.

curl -s -X POST https://opensearch-end-point/_dashboards/api/saved_objects/index-pattern/sample-index -d '{"attributes": {"title": "sample-index*"}}' \
-H "osd-xsrf:true" \
-H "securitytenant: private" \
-H "content-type:application/json" \
-b auth.txt

참고: sample-index를 인덱스 이름 또는 패턴으로 바꾸십시오.

클러스터에 .kibana 별칭을 포함하지 않았음

이 문제를 해결하려면 다음 단계를 완료하십시오.

  1. .kibana 별칭이 클러스터에 있는지 확인하려면 다음 명령을 실행합니다.
    curl -XGET https://opensearch-end-point/_cat/aliases
    참고: 세분화된 액세스 제어가 있는 클러스터의 경우 사용자 이름 및 암호에 -u 플래그를 포함하십시오. 명령 예시:
    curl -XPOST -u 'master-user:master-user-password' 'domain-endpoint/_cat/indices
    .kibana 인덱스가 없는 경우 4번 단계로 진행하십시오.
  2. .kibana 인덱스 백업을 만들려면 다음 명령을 실행합니다.
    curl -XPOST "https://domain-endpoint/_reindex" -H 'Content-Type: application/json' -d'{
      "source": {
        "index": ".kibana"
      },
      "dest": {
     "index": ".kibana_backup"
      }
    }'
    참고: domain-endpoint를 도메인 엔드포인트로 바꾸십시오. 세분화된 액세스 제어가 있는 클러스터의 경우 사용자 이름 및 암호에 -u 플래그를 포함하십시오.
  3. .kibana 인덱스를 삭제하려면 다음 명령을 실행합니다.
    curl -XDELETE "https://domain-endpoint/.kibana"
    참고: domain-endpoint를 도메인 엔드포인트로 바꾸십시오. 세분화된 액세스 제어가 있는 클러스터의 경우 사용자 이름 및 암호에 -u 플래그를 포함하십시오.
  4. .kibana 별칭을 만들고 .kibana_backup 인덱스를 가리키려면 다음 명령을 실행합니다.
    curl -XPOST "https://domain-endpoint/_aliases" -H 'Content-Type: application/json' -d'{
      "actions": [
        {
          "add": {
            "index": ".kibana_backup",
            "alias": ".kibana"
          }
        }
      ]
    }'
    참고: domain-endpoint를 도메인 엔드포인트로 바꾸십시오. 세분화된 액세스 제어가 있는 클러스터의 경우 사용자 이름 및 암호에 -u 플래그를 포함하십시오.

관련 정보

OpenSearch Service를 사용하여 Kibana 대시보드 내보내기 및 가져오기

ISM 정책의 롤오버 인덱스 작업이 OpenSearch Service에서 계속 실패하는 이유는 무엇입니까?