본문 바로가기

리눅스

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

728x90

도커 컨테이너로 elasticsearch, kibana 올리기

elasticsearch 설치

elasticsearch 컨테이너 올리기

docker run -d --name elasticsearch --net esnet -p 9200:9200 -p 9300:9300 -e ES_JAVA_OPTS="-Xms1g -Xmx1g" docker.elastic.co/elasticsearch/elasticsearch:8.2.1; docker logs -f elasticsearch

elasticsearch 컨테이너 진입

docker exec -it elasticsearch bash

elastic 패스워드 변경

bin/elasticsearch-reset-password -u elastic
elasticsearch@80e1f1b11d73:~$ bin/elasticsearch-reset-password -u elastic
WARNING: Owner of file [/usr/share/elasticsearch/config/users] used to be [root], but now is [elasticsearch]
WARNING: Owner of file [/usr/share/elasticsearch/config/users_roles] used to be [root], but now is [elasticsearch]
This tool will reset the password of the [elastic] user to an autogenerated value.
The password will be printed in the console.
Please confirm that you would like to continue [y/N]y
Password for the [elastic] user successfully reset.
New value: YKZ8+3xdcrXmYtniNa8C

elasticsearch 정보 확인

curl -Ss --insecure -u elastic:YKZ8+3xdcrXmYtniNa8C https://localhost:9200 | jq .
$ curl -Ss --insecure -u elastic:YKZ8+3xdcrXmYtniNa8C https://localhost:9200 | jq .
{
  "name": "80e1f1b11d73",
  "cluster_name": "docker-cluster",
  "cluster_uuid": "KCKYA0XuSmyQUqlIAWtbww",
  "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 인증서 복사(elasticsearch 컨테이너에서 로컬 호스트로 복사)

docker cp elasticsearch:/usr/share/elasticsearch/config/certs/http_ca.crt .
$ ls -l http_ca.crt
-rw-rw---- 1 root root 1915 May 26 20:13 http_ca.crt

인증서를 이용하여 elasticsearch 정보 확인

curl -Ss -XGET --cacert ./http_ca.crt -u elastic:YKZ8+3xdcrXmYtniNa8C https://localhost:9200 | jq .
$ curl -Ss -XGET --cacert ./http_ca.crt -u elastic:YKZ8+3xdcrXmYtniNa8C https://localhost:9200 | jq .
{
  "name": "80e1f1b11d73",
  "cluster_name": "docker-cluster",
  "cluster_uuid": "KCKYA0XuSmyQUqlIAWtbww",
  "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:YKZ8+3xdcrXmYtniNa8C https://localhost:9200/_cat/nodes
$ curl --insecure --user elastic:YKZ8+3xdcrXmYtniNa8C https://localhost:9200/_cat/nodes
192.168.160.2 55 69 2 0.01 0.26 0.26 cdfhilmrstw * 80e1f1b11d73

kibana 설치

kibana 컨테이너 올리기

docker run -d --add-host="kibana.sangchul.kr:11.11.11.22" -e SERVER_PUBLICBASE_URL="http://kibana.sangchul.kr:5601" --name kibana --net esnet -p 5601:5601 docker.elastic.co/kibana/kibana:8.2.1

kibana 컨테이너 로그 확인

docker logs -f kibana
$ docker logs -f kibana
[2022-05-26T11:19:41.339+00:00][INFO ][plugins-service] Plugin "cloudSecurityPosture" is disabled.
[2022-05-26T11:19:41.370+00:00][INFO ][plugins-service] Plugin "metricsEntities" is disabled.
[2022-05-26T11:19:41.487+00:00][INFO ][http.server.Preboot] http server running at http://0.0.0.0:5601
[2022-05-26T11:19:41.550+00:00][INFO ][plugins-system.preboot] Setting up [1] plugins: [interactiveSetup]
[2022-05-26T11:19:41.553+00:00][INFO ][preboot] "interactiveSetup" plugin is holding setup: Validating Elasticsearch connection configuration…
[2022-05-26T11:19:41.597+00:00][INFO ][root] Holding setup until preboot stage is completed.


i Kibana has not been configured.

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

웹 브라우저 접속

http://kibana.sangchul.kr:5601/?code=965875 

elasticsearch 컨테이너 진입

docker exec -it elasticsearch bash

토큰 확인

bin/elasticsearch-create-enrollment-token -s kibana --url "https://localhost:9200"
elasticsearch@80e1f1b11d73:~$ bin/elasticsearch-create-enrollment-token -s kibana --url "https://localhost:9200"
eyJ2ZXIiOiI4LjIuMSIsImFkciI6WyIxOTIuMTY4LjE2MC4yOjkyMDAiXSwiZmdyIjoiNGYyZDVmM2Q2YWJiMzgwMzc4NWQ2MzI2YmFjOTZjYmRmNzc3MGRhYTkwYzg1MzNmOWI3Y2IxYmI1NzE2NzMxYiIsImtleSI6InZnNGJBSUVCbkNYLXZyMWMxbWJFOmIwNjA1TkM2UjlHYXhzUzFlWFltM3cifQ==

웹 브라우저 접속

kibana 컨테이너 로그 확인

$ docker logs -f kibana
[2022-05-26T11:19:41.339+00:00][INFO ][plugins-service] Plugin "cloudSecurityPosture" is disabled.
[2022-05-26T11:19:41.370+00:00][INFO ][plugins-service] Plugin "metricsEntities" is disabled.
[2022-05-26T11:19:41.487+00:00][INFO ][http.server.Preboot] http server running at http://0.0.0.0:5601
[2022-05-26T11:19:41.550+00:00][INFO ][plugins-system.preboot] Setting up [1] plugins: [interactiveSetup]
[2022-05-26T11:19:41.553+00:00][INFO ][preboot] "interactiveSetup" plugin is holding setup: Validating Elasticsearch connection configuration…
[2022-05-26T11:19:41.597+00:00][INFO ][root] Holding setup until preboot stage is completed.


i Kibana has not been configured.

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

Your verification code is:  965 875

kibana 컨테이너 진입

docker exec -it kibana bash

코드 확인

bin/kibana-verification-code
kibana@4b76a98c53b7:~$ bin/kibana-verification-code
Your verification code is:  965 875

웹 브라우저 접속

728x90