ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • Elasticsearch 클러스터 구성하기
    Log 2021. 10. 1. 22:58
    반응형

    개요

    운영 환경은 다음과 같다.

    • 모든 노드는 동일 private network로 묶여 있다.
    • OS: CentOS 8 3대 (VM)
      • master 노드 1대 (192.168.101.10)
      • data 노드 2대 (192.168.101.11, 192.168.101.12)
    • Java 11
    • Elasticsearch 7.15

    이미 JavaElasticsearch는 설치되어있다고 가정한다. 설치가 되어 있지 않다면 다음 문서를 참고하라

    Elasticsearch는 다음과 같이 실핼할 수 있다.

    $ sudo systemctl start elasticsearch

     

    클러스터 구성 전이라면 curl 명령어를 실행했을 때 다음과 같이 응답해 줄 것이다.

    $ curl localhost:9200
    {
      "name" : "es-master",
      "cluster_name" : "elasticsearch",
      "cluster_uuid" : "TOevKIVwShq7f8y192NuxQ",
      "version" : {
        "number" : "7.15.0",
        "build_flavor" : "default",
        "build_type" : "rpm",
        "build_hash" : "79d65f6e357953a5b3cbcc5e2c7c21073d89aa29",
        "build_date" : "2021-09-16T03:05:29.143308416Z",
        "build_snapshot" : false,
        "lucene_version" : "8.9.0",
        "minimum_wire_compatibility_version" : "6.8.0",
        "minimum_index_compatibility_version" : "6.0.0-beta1"
      },
      "tagline" : "You Know, for Search"
    }

    Elasticsearch 설정 (마스터)

    마스터 노드의 구성 파일 /etc/elasticsearch/elasticsearch.yml을 다음과 같이 수정한다.

     

    /etc/elasticsearch/elasticsearch.yml

    cluster.name: es-cluster-example
    
    node.name: ${HOSTNAME}
    node.master: true
    node.data: false
    
    path.data: /var/lib/elasticsearch
    path.logs: /var/log/elasticsearch
    
    network.host: 192.168.101.10
    http.port: 9200
    
    discovery.seed_hosts: ["192.168.101.10"]
    cluster.initial_master_nodes: [] # 7.x 이상 부터는 여기를 비워줘야 하는 듯 하다.

     

    그 후, Elasticsearch를 재시작한다.

    $ sudo systemctl restart elasticsearch

    Elasticsearch 설정 (데이터)

    데이터 노드 2개의 설정 파일을 다음과 같이 수정한다. 마스터 노드와 다른 것은 discovery.seed_hosts에서 자신을 포함한 모든 데이터 노드와 마스터 노드의 IP를 지정해주어여 한다.

     

    /etc/elasticsearch/elasticsearch.yml (data01)

    cluster.name: es-cluster-example
    
    node.name: ${HOSTNAME}
    node.master: false
    node.data: true
    
    path.data: /var/lib/elasticsearch
    path.logs: /var/log/elasticsearch
    
    network.host: 192.168.101.11
    http.port: 9200
    
    discovery.seed_hosts: ["192.168.101.10", "192.168.101.11", "192.168.101.12"]
    cluster.initial_master_nodes: []

     

    /etc/elasticsearch/elasticsearch.yml (data02)

    cluster.name: es-cluster-example
    
    node.name: ${HOSTNAME}
    node.master: false
    node.data: true
    
    path.data: /var/lib/elasticsearch
    path.logs: /var/log/elasticsearch
    
    network.host: 192.168.101.12
    http.port: 9200
    
    discovery.seed_hosts: ["192.168.101.10", "192.168.101.11", "192.168.101.12"]
    cluster.initial_master_nodes: []

     

    그 후, Elasticsearch를 재시작한다.

    $ sudo systemctl restart elasticsearch

    클러스터 구성 확인

    클러스터 구성 확인은 쉽다. 특정 Elasticsearch 노드에서 /_nodes/process API를 호출하면 된다. 파라미터로 pretty=true로 주면 JSON이 이쁘게 출력된다.

    $ curl 192.168.101.10:9200/_nodes/process?pretty=true
    {
      "_nodes" : {
        "total" : 3,
        "successful" : 3,
        "failed" : 0
      },
      "cluster_name" : "es-cluster-example",
      "nodes" : {
        "CiScDRbZS968AbQ_Pv5nZQ" : {
          "name" : "es-data02",
          "transport_address" : "192.168.101.12:9300",
          "host" : "192.168.101.12",
          "ip" : "192.168.101.12",
          "version" : "7.15.0",
          "build_flavor" : "default",
          "build_type" : "rpm",
          "build_hash" : "79d65f6e357953a5b3cbcc5e2c7c21073d89aa29",
          "roles" : [
            "data",
            "data_cold",
            "data_content",
            "data_frozen",
            "data_hot",
            "data_warm",
            "ingest",
            "ml",
            "remote_cluster_client",
            "transform"
          ],
          "attributes" : {
            "ml.machine_memory" : "488480768",
            "ml.max_open_jobs" : "512",
            "xpack.installed" : "true",
            "ml.max_jvm_size" : "1073741824",
            "transform.node" : "true"
          },
          "process" : {
            "refresh_interval_in_millis" : 1000,
            "id" : 4298,
            "mlockall" : false
          }
        },
        "jgMGu9p0QBKhwKNBj-vNQw" : {
          "name" : "es-data01",
          "transport_address" : "192.168.101.11:9300",
          "host" : "192.168.101.11",
          "ip" : "192.168.101.11",
          "version" : "7.15.0",
          "build_flavor" : "default",
          "build_type" : "rpm",
          "build_hash" : "79d65f6e357953a5b3cbcc5e2c7c21073d89aa29",
          "roles" : [
            "data",
            "data_cold",
            "data_content",
            "data_frozen",
            "data_hot",
            "data_warm",
            "ingest",
            "ml",
            "remote_cluster_client",
            "transform"
          ],
          "attributes" : {
            "ml.machine_memory" : "488480768",
            "ml.max_open_jobs" : "512",
            "xpack.installed" : "true",
            "ml.max_jvm_size" : "1073741824",
            "transform.node" : "true"
          },
          "process" : {
            "refresh_interval_in_millis" : 1000,
            "id" : 4300,
            "mlockall" : false
          }
        },
        "SnuqiReLQDe1Mxo9YmjzYA" : {
          "name" : "es-master",
          "transport_address" : "192.168.101.10:9300",
          "host" : "192.168.101.10",
          "ip" : "192.168.101.10",
          "version" : "7.15.0",
          "build_flavor" : "default",
          "build_type" : "rpm",
          "build_hash" : "79d65f6e357953a5b3cbcc5e2c7c21073d89aa29",
          "roles" : [
            "ingest",
            "master",
            "ml",
            "remote_cluster_client"
          ],
          "attributes" : {
            "ml.machine_memory" : "488480768",
            "xpack.installed" : "true",
            "transform.node" : "false",
            "ml.max_open_jobs" : "512",
            "ml.max_jvm_size" : "1073741824"
          },
          "process" : {
            "refresh_interval_in_millis" : 1000,
            "id" : 5389,
            "mlockall" : false
          }
        }
      }
    }

    끝이다.

    참고

    'Log' 카테고리의 다른 글

    Elasticsearch 설치하기 (RPM)  (0) 2021.09.29
    Elasticsearch 설치하기 (Binary)  (0) 2021.09.21
Designed by Tistory.