이번에는 ElasticSearch를 운영하면서 한번씩 고민해보는 색인, 검색 노드를 나누는 방법에 대해 알아 보도록 한다.
패스트 캠퍼스의 강의를 참고하여 만들어본다.
색인, 검색 노드를 나누는 이유는?
색인과 검색 노드를 따로 나누는 이유는 아마 대부분 검색 서비스에 영향을 주지 않기 위한 안전장치라고 보면 될 것 같다.
색인 노드에서 정상적으로 색인 된 인덱스를 검색 노드로 옮겨주기만하면 되기 때문에 검색 노드로 넘어온 샤드들은 전부다 정상이라고 볼 수 있다. (그렇다고 색인, 검색 노드를 따로 구분하지 않고 사용해도 아직까지는 큰 이슈는 보지 못하였다.)
구성
- 마스터 노드 1
- 색인 노드 2
- 검색 노드 2
위와 같이 구성하여 로컬에서 테스트를 해볼 예정이다.
1. 마스터 노드
cluster.name: elastic-cluster
node.name: node-1
node.roles: ["master"]
discovery.seed_hosts: [ "localhost:9300", "localhost:9301", "localhost:9302", "localhost:9303", "localhost:9304" ]
cluster.initial_master_nodes: [ "node-1", "node-2", "node-3" ]
cluster.routing.allocation.awareness.attributes: machine
xpack.security.enabled: false
2. 색인 노드(데이터 노드)
아래와 같이 노드 2개의 elasticsearch.yml에 node.attr.machine 값으로 indexing, indexing2로 셋팅한다.
cluster.name: elastic-cluster
node.name: node-2
node.roles: ["master", "data"]
node.attr.machine: indexing
discovery.seed_hosts: [ "localhost:9300", "localhost:9301", "localhost:9302", "localhost:9303", "localhost:9304" ]
cluster.initial_master_nodes: [ "node-1", "node-2", "node-3" ]
cluster.routing.allocation.awareness.attributes: machine
xpack.security.enabled: false
cluster.name: elastic-cluster
node.name: node-5
node.roles: ["master", "data"]
node.attr.machine: indexing2
discovery.seed_hosts: [ "localhost:9300", "localhost:9301", "localhost:9302", "localhost:9303", "localhost:9304" ]
cluster.initial_master_nodes: [ "node-1", "node-2", "node-3" ]
cluster.routing.allocation.awareness.attributes: machine
xpack.security.enabled: false
3. 검색 노드(데이터 노드)
아래와 같이 노드 2개의 elasticsearch.yml에 node.attr.machine 값으로 serving, serving2로 셋팅한다.
cluster.name: elastic-cluster
node.name: node-3
node.roles: ["master", "data"]
node.attr.machine: serving
discovery.seed_hosts: [ "localhost:9300", "localhost:9301", "localhost:9302", "localhost:9303", "localhost:9304" ]
cluster.initial_master_nodes: [ "node-1", "node-2", "node-3" ]
cluster.routing.allocation.awareness.attributes: machine
xpack.security.enabled: false
cluster.name: elastic-cluster
node.name: node-4
node.roles: ["master", "data"]
node.attr.machine: serving2
discovery.seed_hosts: [ "localhost:9300", "localhost:9301", "localhost:9302", "localhost:9303", "localhost:9304" ]
cluster.initial_master_nodes: [ "node-1", "node-2", "node-3" ]
cluster.routing.allocation.awareness.attributes: machine
xpack.security.enabled: false
위와 같이 셋팅을 해주고 노드 5대를 다 띄운다.
그럼 아래와 같이 노드 5대가 정상적으로 뜨는것을 확인한다. 그림(1) 참고
노드 상태를 확인해보면 아래 그림과 같이 설정이 잘 된 것을 확인 할 수 있다. (indexing-(1),(2) serving-(3),(4))
여기까지가 기본 셋팅이고 다음으로는 색인을 위한 Index template을 만든다.
[newstemplate] 을 간단하게 아래 설정값으로 하나 만들어주었다.
아래 셋팅값을 설명하면 primary shard는 2개로 생성하고 replica shard는 0개로 생성하며 machine이 indexing or indexing2라는 노드로 샤드가 할당되게 해주는 설정이다.
replica shard를 0개로 해준 이유는 색인할 때 replica shard까지 만들게 되면 그만큼 색인 시간이 길어지기 때문이다.
{
"index": {
"number_of_shards": "2",
"number_of_replicas": "0",
"routing": {
"allocation": {
"include": {
"machine": "indexing,indexing2"
}
}
}
}
}
다음으로는 색인을 해볼 차례다.
이미 스프링 배치를 이용해 어플리케이션을 만들어 두었다.
강의 마지막 웨비나에서 들었던 내용처럼 Fetcher와 Indexer를 따로 만들어 보았다.
Jenkins pipeline stage는 아래와 같이 3개 stage로 되어 있으며 각 stage에서 하는 역할은 아래 표를 참고
Stage | 설명 | Run |
Fetcher(아래 그림 (1)번) | Mysql에서 news 데이터 읽어와 json파일로 write | Spring Batch |
Indexer(아래 그림 (2)번) | Fetcher에서 write한 파일 읽어서 ES로 bulk Indexing | Spring Batch |
Move2ServingNode(아래 그림 (3)번) | Indexing node -> Serving node로 옮기기 | Shell script |
젠킨스를 실행하면
(2)번 stage에 들어갈때 쯤 아래와 같이 indexing(node-2),indexing2(node-5) 노드에 primary shard가 각각 1개씩 생긴것을 볼 수 있다.
그 다음 (3)번 stage에 들어가면 아래와 같이 primary shard들이 옮겨지는 것을 볼 수 있다.
그리고 (3)번 stage에서 추가로 replica shard도 생성되게 해주었다.
[move2ServingNode]
today=$(date "+%Y%m%d")
index=news"_"$today
curl -XPUT "http://localhost:9200/$index/_settings" -H 'Content-Type:application/json' -d '{
"index.routing.allocation.include.machine": "serving,serving2",
"index.routing.allocation.exclude.machine": "indexing",
"index.number_of_replicas": 1
}'
시간이 좀 지나면 아래와 같이 정상적으로 serving,serving2 노드에 각각 P/S, R/S 가 1개씩 생긴것을 볼 수 있다.(아래 그림 (1)참고)
이상으로 색인 노드와 검색 노드를 나누어 보는 테스트를 진행해보았다.
이후에는 alias작업이라던지 health체크라던지 등등 추가로 각자 더 진행을 하면 될 것 같다.
'검색엔진 > ElasticSearch' 카테고리의 다른 글
ElasticSearch vs Solr (0) | 2022.04.29 |
---|---|
인덱싱 성능 최적화 (0) | 2022.04.05 |
ElasticSearch - Rolling Restart (0) | 2022.03.22 |
ElasticSearch - Full-cluster Restart (0) | 2022.03.21 |
ElasticSearch에서 삭제가 발생하면 어떻게 동작할까? (0) | 2022.03.03 |