본문 바로가기

리눅스

[리눅스] 도커 컨테이너로 elasticsearch, kibana 올리기(multi-node cluster)

반응형

도커 컨테이너로 elasticsearch, kibana 올리기(multi-node cluster)

elasticsearch 설치

docker network 생성

docker network create esnet

elasticsearch node-1 생성 및 로그 확인

docker run -it --name node-1 --net esnet -p 9200:9200 -p 9300:9300 -e ES_JAVA_OPTS="-Xms1g -Xmx1g" docker.elastic.co/elasticsearch/elasticsearch:8.2.1
---------------------------------------------------------------------------------------------------------------------------------------------------------------------
-> Elasticsearch security features have been automatically configured!
-> Authentication is enabled and cluster connections are encrypted.

->  Password for the elastic user (reset with `bin/elasticsearch-reset-password -u elastic`):
  qZPJKJmczwVYO65nn3bS

->  HTTP CA certificate SHA-256 fingerprint:
  b66b85d14985b710514652839d9905355da94a554e27677cac0ec2801dc4a597

->  Configure Kibana to use this cluster:
* Run Kibana and click the configuration link in the terminal when Kibana starts.
* Copy the following enrollment token and paste it into Kibana in your browser (valid for the next 30 minutes):
  eyJ2ZXIiOiI4LjIuMSIsImFkciI6WyIxOTIuMTY4LjE2MC4yOjkyMDAiXSwiZmdyIjoiYjY2Yjg1ZDE0OTg1YjcxMDUxNDY1MjgzOWQ5OTA1MzU1ZGE5NGE1NTRlMjc2NzdjYWMwZWMyODAxZGM0YTU5NyIsImtleSI6Il9vNjJfb0FCV0MxOGgyeUtaWkQyOklJeXRSS3J0UzJpNUlTUWRBbmR5WlEifQ==

-> Configure other nodes to join this cluster:
* Copy the following enrollment token and start new Elasticsearch nodes with `bin/elasticsearch --enrollment-token <token>` (valid for the next 30 minutes):
  eyJ2ZXIiOiI4LjIuMSIsImFkciI6WyIxOTIuMTY4LjE2MC4yOjkyMDAiXSwiZmdyIjoiYjY2Yjg1ZDE0OTg1YjcxMDUxNDY1MjgzOWQ5OTA1MzU1ZGE5NGE1NTRlMjc2NzdjYWMwZWMyODAxZGM0YTU5NyIsImtleSI6Il9JNjJfb0FCV0MxOGgyeUtaWkR3OkUzOW1NSkZTUVNHUFRNdUU4OGtsMmcifQ==

  If you're running in Docker, copy the enrollment token and run:
  `docker run -e "ENROLLMENT_TOKEN=<token>" docker.elastic.co/elasticsearch/elasticsearch:8.2.1`
---------------------------------------------------------------------------------------------------------------------------------------------------------------------

elasticsearch 정보 확인

curl -Ss --insecure -u elastic:qZPJKJmczwVYO65nn3bS https://localhost:9200 | jq .
$ curl --insecure -u elastic:qZPJKJmczwVYO65nn3bS https://localhost:9200 | jq .
{
  "name" : "35f9c6abd412",
  "cluster_name" : "docker-cluster",
  "cluster_uuid" : "XIJxDPgNQFOWKZNjDW0FjQ",
  "version" : {
    "number" : "8.2.1",
    "build_flavor" : "default",
    "build_type" : "docker",
    "build_hash" : "db223507a0bd08f8e84a93e329764cc39b0043b9",
    "build_date" : "2022-05-19T16:34:08.043347449Z",
    "build_snapshot" : false,
    "lucene_version" : "9.1.0",
    "minimum_wire_compatibility_version" : "7.17.0",
    "minimum_index_compatibility_version" : "7.0.0"
  },
  "tagline" : "You Know, for Search"
}

CA(http_ca.crt) 인증서 복사

docker cp node-1:/usr/share/elasticsearch/config/certs/http_ca.crt .

CA 인증서를 사용하여 elasticsearch 정보 확인

curl -Ss -XGET --cacert ./http_ca.crt -u elastic:qZPJKJmczwVYO65nn3bS https://localhost:9200 | jq .
$ curl -Ss -XGET --cacert ./http_ca.crt -u elastic:qZPJKJmczwVYO65nn3bS https://localhost:9200 | jq .
{
  "name": "35f9c6abd412",
  "cluster_name": "docker-cluster",
  "cluster_uuid": "XIJxDPgNQFOWKZNjDW0FjQ",
  "version": {
    "number": "8.2.1",
    "build_flavor": "default",
    "build_type": "docker",
    "build_hash": "db223507a0bd08f8e84a93e329764cc39b0043b9",
    "build_date": "2022-05-19T16:34:08.043347449Z",
    "build_snapshot": false,
    "lucene_version": "9.1.0",
    "minimum_wire_compatibility_version": "7.17.0",
    "minimum_index_compatibility_version": "7.0.0"
  },
  "tagline": "You Know, for Search"
}

elasticsearch node 확인

curl --insecure --user elastic:qZPJKJmczwVYO65nn3bS https://localhost:9200/_cat/nodes
$ curl --insecure --user elastic:qZPJKJmczwVYO65nn3bS https://localhost:9200/_cat/nodes
192.168.160.2 12 94 0 0.00 0.10 0.11 cdfhilmrstw * 35f9c6abd412

elasticsearch node-2 생성

docker run -it --name node-2 --net esnet -e ES_JAVA_OPTS="-Xms1g -Xmx1g" -e ENROLLMENT_TOKEN="eyJ2ZXIiOiI4LjIuMSIsImFkciI6WyIxOTIuMTY4LjE2MC4yOjkyMDAiXSwiZmdyIjoiYjY2Yjg1ZDE0OTg1YjcxMDUxNDY1MjgzOWQ5OTA1MzU1ZGE5NGE1NTRlMjc2NzdjYWMwZWMyODAxZGM0YTU5NyIsImtleSI6Il9JNjJfb0FCV0MxOGgyeUtaWkR3OkUzOW1NSkZTUVNHUFRNdUU4OGtsMmcifQ==" docker.elastic.co/elasticsearch/elasticsearch:8.2.1

elasticsearch node-3 생성

docker run -it --name node-3 --net esnet -e ES_JAVA_OPTS="-Xms1g -Xmx1g" -e ENROLLMENT_TOKEN="eyJ2ZXIiOiI4LjIuMSIsImFkciI6WyIxOTIuMTY4LjE2MC4yOjkyMDAiXSwiZmdyIjoiYjY2Yjg1ZDE0OTg1YjcxMDUxNDY1MjgzOWQ5OTA1MzU1ZGE5NGE1NTRlMjc2NzdjYWMwZWMyODAxZGM0YTU5NyIsImtleSI6Il9JNjJfb0FCV0MxOGgyeUtaWkR3OkUzOW1NSkZTUVNHUFRNdUU4OGtsMmcifQ==" docker.elastic.co/elasticsearch/elasticsearch:8.2.1

elasticsearch node 확인

curl --insecure --user elastic:qZPJKJmczwVYO65nn3bS https://localhost:9200/_cat/nodes
$ curl --insecure --user elastic:qZPJKJmczwVYO65nn3bS https://localhost:9200/_cat/nodes
192.168.160.3 59 96 19 2.67 0.84 0.36 cdfhilmrstw - 40971a2ef791
192.168.160.4 39 96 46 2.67 0.84 0.36 cdfhilmrstw - 0ba0e3f0e4c4
192.168.160.2 41 96 19 2.67 0.84 0.36 cdfhilmrstw * 35f9c6abd412

kibana 설치

kibana 컨테이너 실행 및 로그 확인

docker run -it --add-host="kibana:1.1.1.221" -e SERVER_PUBLICBASE_URL="http://kibana:5601" --name kibana --net esnet -p 5601:5601 docker.elastic.co/kibana/kibana:8.2.1
i Kibana has not been configured.

Go to http://0.0.0.0:5601/?code=113170 to get started.

웹 브라우저

http://kibana:5601/?code=953621

 

elasticsearch node-1 컨테이너에 접근하여 토큰 생성

dokcer exec -it node-1 bash
bin/elasticsearch-create-enrollment-token -s kibana --url "https://localhost:9200"
$ bin/elasticsearch-create-enrollment-token -s kibana --url "https://localhost:9200"
eyJ2ZXIiOiI4LjIuMSIsImFkciI6WyIxOTIuMTY4LjE2MC4yOjkyMDAiXSwiZmdyIjoiYjY2Yjg1ZDE0OTg1YjcxMDUxNDY1MjgzOWQ5OTA1MzU1ZGE5NGE1NTRlMjc2NzdjYWMwZWMyODAxZGM0YTU5NyIsImtleSI6IkE0N1Vfb0FCV0MxOGgyeUtyWkV2OmQxUFhzODZzUUVpT0dkV3NOd21QZVEifQ==
728x90
반응형