본문 바로가기
elastic-stack

VM을 활용한 Elastic Stack 실습 환경 구축 2 - elasticsearch 기본 설정

by jiseok.woo 2020. 1. 16.
반응형

 

 

 

 

 

 

지난 포스팅까지 진행했다면 아래와 같이 VM들이 생성되어 있을 것이다.

 

VM명 Hostname IP
kibana-7.5.1 kibana 192.168.100.10
elasticsearch-7.5.1_1 elastic1 192.168.100.11
elasticsearch-7.5.1_2 elastic2 192.168.100.12
elasticsearch-7.5.1_3 elastic3 192.168.100.13

 

cluster를 구성하기 이전에 elastic1에 접속해서 기본적인 elasticsearch 설정을 진행해보자.

 

 

 


 

 

 

1. elasticsearch 아카이브의 압축 해제

미리 받아 두었던 elasticsearch의 아카이브를 압축해제 하자.

 

[elastic@elastic1 ~]$ tar xvf elasticsearch-7.5.1-linux-x86_64.tar.gz 

 

 

2. elasticsearch 폴더 구성 확인

압축 풀린 elasticsearch 폴더의 구성을 확인해보자.

 

[elastic@elastic1 ~]$ cd elasticsearch-7.5.1/
[elastic@elastic1 elasticsearch-7.5.1]$ ls -al
total 556
drwxr-xr-x.  9 elastic elastic    154 Dec 16 18:01 .
drwx------. 16 elastic elastic   4096 Jan 13 18:31 ..
-rw-r--r--.  1 elastic elastic  13675 Dec 16 17:54 LICENSE.txt
-rw-r--r--.  1 elastic elastic 523209 Dec 16 18:01 NOTICE.txt
-rw-r--r--.  1 elastic elastic   8499 Dec 16 17:54 README.textile
drwxr-xr-x.  2 elastic elastic   4096 Dec 16 18:01 bin
drwxr-xr-x.  2 elastic elastic    148 Dec 16 18:01 config
drwxr-xr-x.  9 elastic elastic    107 Dec 16 18:01 jdk
drwxr-xr-x.  3 elastic elastic   4096 Dec 16 18:01 lib
drwxr-xr-x.  2 elastic elastic      6 Dec 16 18:01 logs
drwxr-xr-x. 38 elastic elastic   4096 Dec 16 18:01 modules
drwxr-xr-x.  2 elastic elastic      6 Dec 16 18:01 plugins
[elastic@elastic1 elasticsearch-7.5.1]$ 

 

  • bin/ : elasticsearch의 실행 파일들이 모여 있는 폴더
  • config/ : 각종 환경설정 파일들이 모여 있는 폴더
  • jdk/ : Open JDK 폴더. 기존 버전에서는 jdk를 직접 설치해야 했지만 7점대 버전부터였나? 이렇게 내장되어 있다.
  • lib/ : elasticsearch 구동에 필요한 라이브러리들이 모여 있는 폴더
  • logs/ : 로그 폴더
  • modules/ : elastcisearch의 모듈들이 설치되어 있는 폴더
  • plugins/ : elasticsearch 플러그인들이 설치되는 폴더

 

3. config 파일 구성 확인

컨피그 파일들의 구성을 확인해보자.

 

[elastic@elastic1 elasticsearch-7.5.1]$ cd config/
[elastic@elastic1 config]$ ls -al
total 36
drwxr-xr-x. 2 elastic elastic   148 Dec 16 18:01 .
drwxr-xr-x. 9 elastic elastic   154 Dec 16 18:01 ..
-rw-rw----. 1 elastic elastic  2831 Dec 16 17:54 elasticsearch.yml
-rw-rw----. 1 elastic elastic  2204 Dec 16 17:54 jvm.options
-rw-rw----. 1 elastic elastic 17545 Dec 16 18:01 log4j2.properties
-rw-rw----. 1 elastic elastic   473 Dec 16 18:01 role_mapping.yml
-rw-rw----. 1 elastic elastic   197 Dec 16 18:01 roles.yml
-rw-rw----. 1 elastic elastic     0 Dec 16 18:01 users
-rw-rw----. 1 elastic elastic     0 Dec 16 18:01 users_roles
[elastic@elastic1 config]$ 

 

  • elasticsearch.yml : 제일 중요한 컨피그 파일. elasticsearch의 기본 설정 파일이다.
  • jvm.options : elasticsearch를 구동시키기 위한 jvm에 대한 설정 파일. jvm의 heap 메모리 설정이 메인이다.
  • log4j2.properties : elasticsearch가 로거로 사용하는 log4j의 설정 파일이다. 로깅에 대한 디테일을 설정할 수 있다.
  • role_mapping.yml, roles.yml, users, users_roles : elasticsearch의 사용자 및 권한에 관한 설정 파일들이다.

 

 

4. jvm.options 파일 설정 (jvm heap 메모리 설정)

elasticsearch는 jvm 위에서 동작하며 많은 메모리를 사용하게 된다. jvm의 힙 메모리 영역을 미리 선점해 다른 프로세스가 사용하지 못하도록 하는데 이때 선점해둘 메모리의 용량을 설정하는 내용이다. (다른 설정은 안건드릴 거다.)

 

[elastic@elastic1 config]$ vi jvm.options 
# Xms represents the initial size of total heap space
# Xmx represents the maximum size of total heap space

-Xms1g
-Xmx1g

################################################################

 

  • Xms1g : 힙 메모리의 최소 용량을 1GB로 설정
  • Xmx1g : 힙 메모리의 최대 용량을 1GB로 설정 (보통 최소/최대 용량을 같게 설정한다)

 

 

5. elasticsearch.yml 설정

제일 중요한 elasticsearch의 기본 설정 파일이다. node 이름, IP 정도만 설정해도 기본 동작이 가능하다.

[elastic@elastic1 config]$ vi elasticsearch.yml 
node.name: node-1
network.host: 192.168.100.11
cluster.initial_master_nodes: ["node-1"]

 

  • node.name : elasticsearch의 노드 이름
  • network.host : 현재 노드의 IP 주소
  • cluster.initial_master_nodes : 현재 cluster의 master node 후보군들이다. 현재는 node가 한개 뿐이니 node-1만 적어주자.

 

6. elasticsearch 실행

기본적이 설정을 했으니 elasticsearch를 구동해보자.

 

[elastic@elastic1 config]$ cd ../bin/
[elastic@elastic1 bin]$ ./elasticsearch

 

[elastic@elastic1 bin]$ ./elasticsearch
OpenJDK 64-Bit Server VM warning: Option UseConcMarkSweepGC was deprecated in version 9.0 and will likely be removed in a future release.
[2020-01-13T18:52:35,862][INFO ][o.e.e.NodeEnvironment    ] [node-1] using [1] data paths, mounts [[/ (/dev/mapper/cl-root)]], net usable_space [12.1gb], net total_space [16.9gb], types [xfs]
[2020-01-13T18:52:35,869][INFO ][o.e.e.NodeEnvironment    ] [node-1] heap size [1015.6mb], compressed ordinary object pointers [true]
[2020-01-13T18:52:35,871][INFO ][o.e.n.Node               ] [node-1] node name [node-1], node ID [C0K4nzwKTDKbmko40Ko4-Q], cluster name [elasticsearch]
[2020-01-13T18:52:35,871][INFO ][o.e.n.Node               ] [node-1] version[7.5.1], pid[2507], build[default/tar/3ae9ac9a93c95bd0cdc054951cf95d88e1e18d96/2019-12-16T22:57:37.835892Z], OS[Linux/4.18.0-80.el8.x86_64/amd64], JVM[AdoptOpenJDK/OpenJDK 64-Bit Server VM/13.0.1/13.0.1+9]
[2020-01-13T18:52:35,872][INFO ][o.e.n.Node               ] [node-1] JVM home [/home/elastic/elasticsearch-7.5.1/jdk]
[2020-01-13T18:52:35,872][INFO ][o.e.n.Node               ] [node-1] JVM arguments [-Des.networkaddress.cache.ttl=60, -Des.networkaddress.cache.negative.ttl=10, -XX:+AlwaysPreTouch, -Xss1m, -Djava.awt.headless=true, -Dfile.encoding=UTF-8, -Djna.nosys=true, -XX:-OmitStackTraceInFastThrow, -Dio.netty.noUnsafe=true, -Dio.netty.noKeySetOptimization=true, -Dio.netty.recycler.maxCapacityPerThread=0, -Dio.netty.allocator.numDirectArenas=0, -Dlog4j.shutdownHookEnabled=false, -Dlog4j2.disable.jmx=true, -Djava.locale.providers=COMPAT, -Xms1g, -Xmx1g, -XX:+UseConcMarkSweepGC, -XX:CMSInitiatingOccupancyFraction=75, -XX:+UseCMSInitiatingOccupancyOnly, -Djava.io.tmpdir=/tmp/elasticsearch-4614584306940951439, -XX:+HeapDumpOnOutOfMemoryError, -XX:HeapDumpPath=data, -XX:ErrorFile=logs/hs_err_pid%p.log, -Xlog:gc*,gc+age=trace,safepoint:file=logs/gc.log:utctime,pid,tags:filecount=32,filesize=64m, -XX:MaxDirectMemorySize=536870912, -Des.path.home=/home/elastic/elasticsearch-7.5.1, -Des.path.conf=/home/elastic/elasticsearch-7.5.1/config, -Des.distribution.flavor=default, -Des.distribution.type=tar, -Des.bundled_jdk=true]
[2020-01-13T18:52:41,330][INFO ][o.e.p.PluginsService     ] [node-1] loaded module [aggs-matrix-stats]
[2020-01-13T18:52:41,331][INFO ][o.e.p.PluginsService     ] [node-1] loaded module [analysis-common]
[2020-01-13T18:52:41,331][INFO ][o.e.p.PluginsService     ] [node-1] loaded module [flattened]
[2020-01-13T18:52:41,331][INFO ][o.e.p.PluginsService     ] [node-1] loaded module [frozen-indices]
[2020-01-13T18:52:41,331][INFO ][o.e.p.PluginsService     ] [node-1] loaded module [ingest-common]
[2020-01-13T18:52:41,332][INFO ][o.e.p.PluginsService     ] [node-1] loaded module [ingest-geoip]
[2020-01-13T18:52:41,332][INFO ][o.e.p.PluginsService     ] [node-1] loaded module [ingest-user-agent]
[2020-01-13T18:52:41,332][INFO ][o.e.p.PluginsService     ] [node-1] loaded module [lang-expression]
[2020-01-13T18:52:41,332][INFO ][o.e.p.PluginsService     ] [node-1] loaded module [lang-mustache]
[2020-01-13T18:52:41,333][INFO ][o.e.p.PluginsService     ] [node-1] loaded module [lang-painless]
[2020-01-13T18:52:41,333][INFO ][o.e.p.PluginsService     ] [node-1] loaded module [mapper-extras]
[2020-01-13T18:52:41,333][INFO ][o.e.p.PluginsService     ] [node-1] loaded module [parent-join]
[2020-01-13T18:52:41,333][INFO ][o.e.p.PluginsService     ] [node-1] loaded module [percolator]
[2020-01-13T18:52:41,333][INFO ][o.e.p.PluginsService     ] [node-1] loaded module [rank-eval]
[2020-01-13T18:52:41,334][INFO ][o.e.p.PluginsService     ] [node-1] loaded module [reindex]
[2020-01-13T18:52:41,334][INFO ][o.e.p.PluginsService     ] [node-1] loaded module [repository-url]
[2020-01-13T18:52:41,334][INFO ][o.e.p.PluginsService     ] [node-1] loaded module [search-business-rules]
[2020-01-13T18:52:41,334][INFO ][o.e.p.PluginsService     ] [node-1] loaded module [spatial]
[2020-01-13T18:52:41,335][INFO ][o.e.p.PluginsService     ] [node-1] loaded module [transform]
[2020-01-13T18:52:41,335][INFO ][o.e.p.PluginsService     ] [node-1] loaded module [transport-netty4]
[2020-01-13T18:52:41,335][INFO ][o.e.p.PluginsService     ] [node-1] loaded module [vectors]
[2020-01-13T18:52:41,336][INFO ][o.e.p.PluginsService     ] [node-1] loaded module [x-pack-analytics]
[2020-01-13T18:52:41,336][INFO ][o.e.p.PluginsService     ] [node-1] loaded module [x-pack-ccr]
[2020-01-13T18:52:41,336][INFO ][o.e.p.PluginsService     ] [node-1] loaded module [x-pack-core]
[2020-01-13T18:52:41,336][INFO ][o.e.p.PluginsService     ] [node-1] loaded module [x-pack-deprecation]
[2020-01-13T18:52:41,337][INFO ][o.e.p.PluginsService     ] [node-1] loaded module [x-pack-enrich]
[2020-01-13T18:52:41,337][INFO ][o.e.p.PluginsService     ] [node-1] loaded module [x-pack-graph]
[2020-01-13T18:52:41,337][INFO ][o.e.p.PluginsService     ] [node-1] loaded module [x-pack-ilm]
[2020-01-13T18:52:41,337][INFO ][o.e.p.PluginsService     ] [node-1] loaded module [x-pack-logstash]
[2020-01-13T18:52:41,338][INFO ][o.e.p.PluginsService     ] [node-1] loaded module [x-pack-ml]
[2020-01-13T18:52:41,338][INFO ][o.e.p.PluginsService     ] [node-1] loaded module [x-pack-monitoring]
[2020-01-13T18:52:41,338][INFO ][o.e.p.PluginsService     ] [node-1] loaded module [x-pack-rollup]
[2020-01-13T18:52:41,338][INFO ][o.e.p.PluginsService     ] [node-1] loaded module [x-pack-security]
[2020-01-13T18:52:41,338][INFO ][o.e.p.PluginsService     ] [node-1] loaded module [x-pack-sql]
[2020-01-13T18:52:41,339][INFO ][o.e.p.PluginsService     ] [node-1] loaded module [x-pack-voting-only-node]
[2020-01-13T18:52:41,339][INFO ][o.e.p.PluginsService     ] [node-1] loaded module [x-pack-watcher]
[2020-01-13T18:52:41,339][INFO ][o.e.p.PluginsService     ] [node-1] no plugins loaded
[2020-01-13T18:52:49,517][INFO ][o.e.x.s.a.s.FileRolesStore] [node-1] parsed [0] roles from file [/home/elastic/elasticsearch-7.5.1/config/roles.yml]
[2020-01-13T18:52:51,488][INFO ][o.e.x.m.p.l.CppLogMessageHandler] [node-1] [controller/2585] [Main.cc@110] controller (64 bit): Version 7.5.1 (Build ae3c3c51b849be) Copyright (c) 2019 Elasticsearch BV
[2020-01-13T18:52:52,772][DEBUG][o.e.a.ActionModule       ] [node-1] Using REST wrapper from plugin org.elasticsearch.xpack.security.Security
[2020-01-13T18:52:53,328][INFO ][o.e.d.DiscoveryModule    ] [node-1] using discovery type [zen] and seed hosts providers [settings]
[2020-01-13T18:52:55,027][INFO ][o.e.n.Node               ] [node-1] initialized
[2020-01-13T18:52:55,027][INFO ][o.e.n.Node               ] [node-1] starting ...
[2020-01-13T18:52:55,348][INFO ][o.e.t.TransportService   ] [node-1] publish_address {192.168.100.11:9300}, bound_addresses {192.168.100.11:9300}
[2020-01-13T18:52:55,548][INFO ][o.e.b.BootstrapChecks    ] [node-1] bound or publishing to a non-loopback address, enforcing bootstrap checks
ERROR: [2] bootstrap checks failed
[1]: max file descriptors [4096] for elasticsearch process is too low, increase to at least [65535]
[2]: max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
[2020-01-13T18:52:55,566][INFO ][o.e.n.Node               ] [node-1] stopping ...
[2020-01-13T18:52:55,600][INFO ][o.e.n.Node               ] [node-1] stopped
[2020-01-13T18:52:55,600][INFO ][o.e.n.Node               ] [node-1] closing ...
[2020-01-13T18:52:55,625][INFO ][o.e.n.Node               ] [node-1] closed
[2020-01-13T18:52:55,630][INFO ][o.e.x.m.p.NativeController] [node-1] Native controller process has stopped - no new native processes can be started
[elastic@elastic1 bin]$ 

 

에러가 나면서 종료 되었다. 위 로그의 마지막 부분을 잘 보면 에러 내용을 알 수 있다.

 

ERROR: [2] bootstrap checks failed
[1]: max file descriptors [4096] for elasticsearch process is too low, increase to at least [65535]
[2]: max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]

 

2개의 에러가 확인되는데 첫번째는 max file descriptor 값이 너무 낮다, 두번째는 vm.max_map_count 값이 너무 낮다는 내용이다.

max file descriptors 값은 하나의 프로세스가 열어볼 수 있는 최대 파일 개수를 제한하는 값이고 vm.max_map_count는 하나의 프로세스가 가질 수 있는 메모리 맵의 최대 개수이다. elasticsearch는 파일 읽기도 잦고 메모리맵도 많이 사용하니 충분히 늘려주자.

 

 

먼저 max file descriptors 값을 수정해보자.

root 권한으로 limits.conf 파일에 아래와 같이 추가해주자.

[elastic@elastic1 bin]$ su -
Password: 
[root@elastic1 ~]# vi /etc/security/limits.conf 
elastic  -  nofile  65535

맨 앞의 elastic은 일반계정 이름이다. 즉, elasticsearch를 구동할 계정 이름을 써주면 된다.

 

 

vm.max_map_count 값은 /etc/sysctl.conf 파일에 아래와 같이 추가해주면 된다.

[elastic@elastic1 bin]$ su -
Password: 
[root@elastic1 ~]# vi /etc/sysctl.conf 
vm.max_map_count=262144

 

 

자, 이제 VM을 재부팅한 뒤에 다시 elasticsearch를 구동 해보자

[elastic@elastic1 bin]$ ./elasticsearch

 

쭈욱 로그들이 지나갈거고 마지막 부분에 아래와 같이 node-1 started가 보일 것이다. 성공적으로 elasticsearch가 구동된 듯 하다.

[2020-01-16T06:51:34,295][INFO ][o.e.h.AbstractHttpServerTransport] [node-1] publish_address {192.168.100.11:9200}, bound_addresses {192.168.100.11:9200}
[2020-01-16T06:51:34,295][INFO ][o.e.n.Node               ] [node-1] started

 

 

이제 맥북에서 elastic1의 elasticsearch로 접근해볼까? 터미널을 열고 아래와 같이 입력해보자.

(curl은 http 등의 프로토콜을 이용해 데이터를 전송하고 응답을 받는 툴이며, 9200번 포트는 elasticsearch에서 사용하는 default port 이다.)

Jiseokui-MacBookPro:~ jiseokwoo$ curl http://192.168.100.11:9200
curl: (7) Failed to connect to 192.168.100.11 port 9200: Connection refused
Jiseokui-MacBookPro:~ jiseokwoo$ 

 

응?? 접속이 안된다..

깜빡한게 있다... ubuntu, centos 등 리눅스는 설치하면 기본적으로 방화벽이 켜져있다. (윈도우도 그렇구나.)

 

방화벽이 켜져있는지 아래와 같이 확인해보자. (ubuntu는 방화벽 서비스명이 아마 ufw이었던 것 같으니 참고하자.)

[elastic@elastic1 ~]$ service firewalld status
Redirecting to /bin/systemctl status firewalld.service
● firewalld.service - firewalld - dynamic firewall daemon
   Loaded: loaded (/usr/lib/systemd/system/firewalld.service; enabled; vendor preset: enabled)
   Active: active (running) since Thu 2020-01-16 06:47:37 EST; 22min ago
     Docs: man:firewalld(1)
 Main PID: 895 (firewalld)
    Tasks: 2 (limit: 11362)
   Memory: 2.1M
   CGroup: /system.slice/firewalld.service
           └─895 /usr/libexec/platform-python -s /usr/sbin/firewalld --nofork --nopid
[elastic@elastic1 ~]$ 

 

켜져있으니 방화벽을 끄도록 하자.

[elastic@elastic1 ~]$ service firewalld stop
Redirecting to /bin/systemctl stop firewalld.service
==== AUTHENTICATING FOR org.freedesktop.systemd1.manage-units ====
Authentication is required to stop 'firewalld.service'.
Authenticating as: root
Password: 
==== AUTHENTICATION COMPLETE ====
[elastic@elastic1 ~]$ 

 

 

다시 맥북으로 돌아와서 elasticsearch에 접근해보자.

Jiseokui-MacBookPro:~ jiseokwoo$ curl http://192.168.100.11:9200
{
  "name" : "node-1",
  "cluster_name" : "elasticsearch",
  "cluster_uuid" : "NGCsgcl2QKeMwrliilTM_A",
  "version" : {
    "number" : "7.5.1",
    "build_flavor" : "default",
    "build_type" : "tar",
    "build_hash" : "3ae9ac9a93c95bd0cdc054951cf95d88e1e18d96",
    "build_date" : "2019-12-16T22:57:37.835892Z",
    "build_snapshot" : false,
    "lucene_version" : "8.3.0",
    "minimum_wire_compatibility_version" : "6.8.0",
    "minimum_index_compatibility_version" : "6.0.0-beta1"
  },
  "tagline" : "You Know, for Search"
}
Jiseokui-MacBookPro:~ jiseokwoo$ 

 

뭐라뭐라 메세지가 뜬다.

node 이름, cluster 이름, elasticsearch 버전 등의 정보가 표시된다.

 

아래와 같이 웹브라우져에서도 확인이 가능하다.

 

 

 

자, 여기까지 1개 node에 elasticsearch를 구성해보았다. 다음 포스팅에서는 3개 node로 cluster를 구성해보자.

 

 

 

끝.

 

 

 

2020/01/11 - [elastic-stack] - VM을 활용한 Elastic Stack 실습 환경 구축 1 - VM 생성하기

2020/01/16 - [elastic-stack] - VM을 활용한 Elastic Stack 실습 환경 구축 2 - elasticsearch 기본 설정

2020/01/16 - [elastic-stack] - VM을 활용한 Elastic Stack 실습 환경 구축 3 - cluster 기본 설정

2020/01/24 - [elastic-stack] - VM을 활용한 Elastic Stack 실습 환경 구축 4 - kibana 기본 설정

 

 

 

반응형

댓글