로컬 개발, 테스트, CI/CD 환경에서 단일 노드 Elasticsearch를 구성할 때 필요한 설정을 정리합니다.
왜 단일 노드를 사용하는가
- 로컬 개발 환경의 90%는 단일 노드로 충분합니다.
- 리소스 제약이 있는 테스트/CI 환경에 적합합니다.
- 운영 환경에서는 권장하지 않습니다. (장애 시 데이터 유실, 수평 확장 불가)
기본 설정
elasticsearch.yml 또는 환경 변수로 다음을 설정합니다.
discovery.type: single-node이 설정이 없으면 클러스터 형성을 시도하다가 bootstrap check에서 실패할 수 있습니다.
Replica Shard 문제
기본적으로 인덱스는 Primary Shard 1개, Replica 1개로 생성됩니다. Replica는 Primary와 다른 노드에 할당되어야 하므로, 단일 노드에서는 할당이 불가능합니다. 이 경우 클러스터 상태가 yellow가 됩니다.
기존 인덱스 수정
curl -X PUT "localhost:9200/<index_name>/_settings" \
-H 'Content-Type: application/json' \
-d '{ "index": { "number_of_replicas": 0 } }'모든 인덱스 일괄 수정
for index in $(curl -s "localhost:9200/_cat/indices?h=index"); do
curl -X PUT "localhost:9200/$index/_settings" \
-H 'Content-Type: application/json' \
-d '{ "index": { "number_of_replicas": 0 } }'
doneIndex Template으로 기본값 변경
새로 생성되는 인덱스에 자동 적용됩니다.
curl -X PUT "localhost:9200/_template/single_node_default" \
-H 'Content-Type: application/json' \
-d '{
"index_patterns": ["*"],
"settings": {
"number_of_replicas": 0
}
}'