아키텍처 구성
master node 1대
data node 1대
data node 1대
설치 과정
ssh [IP]
sudo su - root
apt update
apt install openjdk-11-jdk (echo $JAVA_HOME)
// 처음에 proxy 설정(/etc/yum.conf 에 프록시 설정 추가를 해야하는지 몰라서,
ES 설치파일을 로컬 서버에서 다운받고, scp로 생성한 가상머신에 보내줘서 그 파일로 설치함
dpkg -i elasticsearch-6.8.23.deb
systemctl restart elasticsearch
설치 확인)
apt install net-tools
netstat -anlp | grep 9200
curl -X GET http://localhost:9200/classes
클러스터 구성
tip: apt install net-tools 먼저 해주면 좋다 (netstat 때문에)
master 노드 설정 파일
vi elasticsearch.yml
|
# ======================== Elasticsearch Configuration ========================= # # NOTE: Elasticsearch comes with reasonable defaults for most settings. # Before you set out to tweak and tune the configuration, make sure you # understand what are you trying to accomplish and the consequences. # # The primary way of configuring a node is via this file. This template lists # the most important settings you may want to configure for a production cluster. # # Please consult the documentation for further information on configuration options: # # ---------------------------------- Cluster ----------------------------------- # # Use a descriptive name for your cluster: # cluster.name: es-cluster # # ------------------------------------ Node ------------------------------------ # # Use a descriptive name for the node: # node.name: test03-minji # # Add custom attributes to the node: # #node.attr.rack: r1 # node.master: true node.data: false # ----------------------------------- Paths ------------------------------------ # # Path to directory where to store the data (separate multiple locations by comma): # path.data: /var/lib/elasticsearch # # Path to log files: # path.logs: /var/log/elasticsearch # # ----------------------------------- Memory ----------------------------------- # # Lock the memory on startup: # bootstrap.memory_lock: true # # Make sure that the heap size is set to about half the memory available # on the system and that the owner of the process is allowed to use this # limit. # # Elasticsearch performs poorly when the system is swapping the memory. # # ---------------------------------- Network ----------------------------------- # # Set the bind address to a specific IP (IPv4 or IPv6): # network.host: [본인 아이피] # # Set a custom port for HTTP: # http.port: 9200 # # For more information, consult the network module documentation. # # --------------------------------- Discovery ---------------------------------- # # Pass an initial list of hosts to perform discovery when new node is started: # The default list of hosts is ["127.0.0.1", "[::1]"] # discovery.zen.ping.unicast.hosts: ["test03-minji:9300","test02-minji:9300","test01-minji:9300"] # # Prevent the "split brain" by configuring the majority of nodes (total number of master-eligible nodes / 2 + 1): # discovery.zen.minimum_master_nodes: 3 # # For more information, consult the zen discovery module documentation. # # ---------------------------------- Gateway ----------------------------------- # # Block initial recovery after a full cluster restart until N nodes are started: # #gateway.recover_after_nodes: 3 # # For more information, consult the gateway module documentation. # # ---------------------------------- Various ----------------------------------- # # Require explicit names when deleting indices: # #action.destructive_requires_name: true |
data 노드
vi elasticsearch.yml
|
# ======================== Elasticsearch Configuration ========================= # # NOTE: Elasticsearch comes with reasonable defaults for most settings. # Before you set out to tweak and tune the configuration, make sure you # understand what are you trying to accomplish and the consequences. # # The primary way of configuring a node is via this file. This template lists # the most important settings you may want to configure for a production cluster. # # Please consult the documentation for further information on configuration options: # # ---------------------------------- Cluster ----------------------------------- # # Use a descriptive name for your cluster: # cluster.name: es-cluster # # ------------------------------------ Node ------------------------------------ # # Use a descriptive name for the node: # node.name: test01-minji # # Add custom attributes to the node: # #node.attr.rack: r1 # node.master: true node.data: false # ----------------------------------- Paths ------------------------------------ # # Path to directory where to store the data (separate multiple locations by comma): # path.data: /var/lib/elasticsearch # # Path to log files: # path.logs: /var/log/elasticsearch # # ----------------------------------- Memory ----------------------------------- # # Lock the memory on startup: # bootstrap.memory_lock: true # # Make sure that the heap size is set to about half the memory available # on the system and that the owner of the process is allowed to use this # limit. # # Elasticsearch performs poorly when the system is swapping the memory. # # ---------------------------------- Network ----------------------------------- # # Set the bind address to a specific IP (IPv4 or IPv6): # network.host: [본인 아이피] # # Set a custom port for HTTP: # http.port: 9200 # # For more information, consult the network module documentation. # # --------------------------------- Discovery ---------------------------------- # # Pass an initial list of hosts to perform discovery when new node is started: # The default list of hosts is ["127.0.0.1", "[::1]"] # discovery.zen.ping.unicast.hosts: ["test03-minji:9300","test02-minji:9300","test01-minji:9300"] # # Prevent the "split brain" by configuring the majority of nodes (total number of master-eligible nodes / 2 + 1): # discovery.zen.minimum_master_nodes: 3 # # For more information, consult the zen discovery module documentation. # # ---------------------------------- Gateway ----------------------------------- # # Block initial recovery after a full cluster restart until N nodes are started: # #gateway.recover_after_nodes: 3 # # For more information, consult the gateway module documentation. # # ---------------------------------- Various ----------------------------------- # # Require explicit names when deleting indices: # #action.destructive_requires_name: true |
/usr/lib/systemd/system/elasticsearch.service 설정 파일 수정
[Service]
LimitMEMLOCK=infinity ← 이 부분 추가
ES 실행하기
systemctl daemon-reload
systemctl restart elasticsearch
실행 확인
systemctl status elasticsearch
curl -X GET "http://localhost:9200/_cluster/health?pretty"
* 여기서 localhost 는 본인이 위 설정파일에 설정한 값을 고려해서..
localhost 인지 아이피인지 생각하고 테스트해야합니다.
netstat -anlp | grep 9300
설정 파일에 대한 간단한 설명
[ cluster ]
클러스터 전체에 적용되는 설정. 클러스터 구성시 각 노드에 같은 클러스터 이름을 사용. 클러스터 이름 변경시, 클러스터 내 모든 노드를 재시작 cluster.name 클러스터 이름 (기본값 : elasticsearch)
[ node ]
해당 노드에만 적용되는 설정.
- node.name:
노드 이름. 클러스터내 유일해야함. → ${HOSTNAME} = 호스트명 으로 설정시 중복을 피할 수 있다.
운영중 변경 불가. 변경시 노드 재시작.
주석처리시 랜덤한 문자열으로 자동 설정됨.
- node.attr.rack
사용자 정의된 rack값으로 HA구성과 같이 샤드를 분배.
[ path ]
데이터, 로그 저장 위치 설정. 반드시 설정되어야 하는 값. 주석X. (설정 하지 않으면 애플리케이션 실행이 되지 않음.)
path.data: 노드의 문서들을 저장할 경로. = 색인된 문서들이 세그먼트 파일로 저장될 위치.
멀티 path 설정 가능. (경로1, 경로2) 여러개의 디스크존재시, 분산저장할 수 있다는 장점.
단점은 하나의 디스크에 문제 발생시 어느 문서들이 영향을 받는지 알 수 없다.
path.logs: 로그를 저장할 경로
[ memory ]
Elasticsearch 프로세스에서 할당되는 메모리 영역 관리 설정
bootstrap.memory_lock:
스왑 메모리 영역 사용 여부 설정. 스왑 메모리 사용하지 않는것을 권고 이는 성능을 보장 하나, Out Of Memory 에러로 노드 장애 발생 가능성이 있다. 대게의 경우 문제가 없지만 JVM 힙 메모리 용량이 시스템 메모리 용량의 절반이상이 되면 Out Of Memory 발생 가능성이 있다. 이를 사용하기 위해선 OS의 /etc/security/limits.conf 파일도 수정해야 한다. systemd로 프로세스 시작시 추가 설정
sudo vi etc/security/limits.conf elasticsearch soft memlock unlimited elasticsearch hard memlock unlimited # {계정명} -> yum or rpm 설치시 디폴트계정명(=elasticsearch)
sudo mkdir /etc/systemd/system/elasticsearch.service.d sudo vi /etc/systemd/system/elasticsearch.service.d/override.conf [service] LimitMEMLOCK=infinity sudo systemctl deamon-reload
(위 추가설정 없이 bootstrap.memory_lock: true 설정시 프로세스가 시작되지 않음.)
[ Network ]
외부와 통신하기 위한 IP & 노드간 통신 설정
network.host : IP주소 설정. 아래 두가지 설정을 한번에 설정하기 위한 필드. 두가지로 나누어 각각 설정 할 수 있다.
대게 분리해서 설정하는 이유는 bind_host 를 특정 IP로 지정하면, 노드 내부에서도 localhost(127.0.0.1)으로 접근 할 수 없어서, 스크립트나 자동화를 통해 ElasticSearch관리시 localhost 사용이 효율적이다.
그래서 0.0.0.0 설정 권장. 그러면 노드IP + localhost 모두 사용 가능하다.
하지만, 두개 이상의 노드의 경우 같은 IP로 설정하면 통신 불가능.
즉, 클라이언트 요청 = 노드 IP + localhost & 노드간 통신 = 노드IP (5.3에서 해결방안)
network.bind_host - 노드간 통신
network.publish_host - 외부통신
http.port : 포트 설정
[ discovery ]
노드간 클러스터링 설정.
discovery.zen.ping.unicast.hosts
클러스터링을 위한 다른 노드들의 정보. 배열 형태. 1개 이상의 노드 나열.
discovery.zen.minimum_master_nodes:
최소한의 마스터 노드 개수 설정. (기본값 : 1)
split brain 현상을 방지하는데 반드시 필요한 설정.
7.x부터 사라짐.
node.master: true 인 노드가 추가되면 클러스터가 스스로minimum_master_nodes 노드 값을 변경하도록 됨.
사용자는 최초 마스터 후보로 선출할 cluster.initial_master_nodes: 값만 설정
즉, hosts에 설정된 IP에 ElasticSearch 떠있는지 확인 →
해당 클러스터의 정보를 받아서, 마스터 노드 개수를 확인. 최소 개수 이상이면, 성공적으로 클러스터에 합류.
[ Gateway ]
클러스터 복구 관련 설정.
gateway.recover_after_nodes: 클러스터내 노드 모두 재시작시, 최소 몇개 노드가 정상적인 상태일때 복구를 시작할 것인지 설정.
버전 업그레이드 or 전체 노드 장애 → 전체 노드 재시작 (Full Cluster Restart)
재시작 노드들을 순차적으로 클러스터링 진행
클러스러링 시작시, 클러스터내 인덱스 데이터를 복구
노드 role에 따라 최소 개수 설정 가능
gateway.recover_after_master_nodes gateway.recover_after_data_nodes gateway.recover_after_data_nodes
bootstrap 설정= 스왑 메모리 영역 사용 여부 설정.
스왑 메모리 사용하지 않는것을 권고하고 있는데, 이는 성능을 보장 하나, Out Of Memory 에러로 노드 장애 발생 가능성이 있다. (대게의 경우 문제가 없다고 하지만 JVM 힙 메모리 용량이 시스템 메모리 용량의 절반이상이 되면 Out Of Memory 발생 가능성이 있다.) 이를 사용하기 위해 /etc/security/limits.conf 파일도 수정해야 한다. systemd로 프로세스 시작시 추가 설정..
[ 트러블슈팅 ]
#1 클러스터 구성 시
[1]: memory locking requested for elasticsearch process but memory is not locked
엘라스틱 메모리 설정 관련 문제가 있었다.
vi /usr/lib/systemd/system/elasticsearch.service 파일에 다음을 추가하여 해결.
[Service]
LimitMEMLOCK=infinity ← 이 부분 추가
#2
에러 로그를 잘못보고 있었다.
cd /var/log/elasticsearch/ 여기서
tail -f /var/log/elasticsearch/elasticsearch.log 이거라고 생각해서 계속 보는데 반응이 없길래
date 확인해보고, 이건 제대로 되어 있어서 다른 로그 파일들을 봤다.
cd /var/log/elasticsearch/
cat syslog
cat syslog | grep elastic
tail -f syslog
찾던 도중 tail -f es-cluster.log 이것 발견..
내가 /etc/elasticsearch/elasticsearch.yml 여기 cluster 에 es-cluster 라고 해놔서 생긴 문제였다..
참고 사이트:
https://kangmyounghun.blogspot.com/2021/01/bootstrapmemorylock.html
https://asecurity.dev/entry/PART-1-INSTALL-ELASTICSEARCH-6-CLUSTER-FOR-CENTRALIZED-SYSLOG
https://stophyun.tistory.com/242
https://ldh-6019.tistory.com/m/39 (이 분 글이 가장 깔끔)