Microsoft MVP성태의 닷넷 이야기
글쓴 사람
정성태 (techsharer at outlook.com)
홈페이지
첨부 파일
 
(연관된 글이 2개 있습니다.)

Windows - 단일 머신에서 단일 바이너리로 여러 개의 ElasticSearch 노드를 실행하는 방법

실제 운영 시에는 머신 하나 당 노드 한 개를 유지하겠지만, 테스트 환경을 구축할 때는 그게 좀 번거롭긴 합니다. 따라서 한 대의 머신에서 해결하는 것이 좋은데, 이를 위해 가장 쉬운 방법은, elasticsearch.yml 파일에 node.max_local_storage_nodes 설정을 포함하는 것입니다. (물론, docker를 이용해도 됩니다.)

node.max_local_storage_nodes: 3

그럼, 동일한 경로에 설치된 elasticsearch.bat 파일을 서로 다른 명령행 창에서 3번 실행할 수 있고, 이렇게 확인할 수 있습니다.

C:\temp> curl -XGET "localhost:9200/_cat/health?v&pretty"
epoch      timestamp cluster    status node.total node.data shards pri relo init unassign pending_tasks max_task_wait_time active_shards_percent
1598856739 06:52:19  my_cluster green           3         3      0   0    0    0        0             0                  -                100.0%

그런데, 아무리 테스트 환경이라고 해도 기본 설정 상태에서는 "localhost"로만 접근이 되는 제약이 있으므로, 다른 머신에서 접근하기 위해 HTTP 바인딩을 바꾸는 경우,

network.host: _site_

아쉽게도 실행 오류가 발생하며 종료합니다.

...[생략]...
[2020-08-31T11:51:13,039][INFO ][o.e.n.Node               ] [TESTPC] initialized
[2020-08-31T11:51:13,039][INFO ][o.e.n.Node               ] [TESTPC] starting ...
[2020-08-31T11:51:13,844][INFO ][o.e.t.TransportService   ] [TESTPC] publish_address {172.26.48.6:9300}, bound_addresses {172.26.48.6:9300}, {192.168.0.167:9300}
[2020-08-31T11:51:14,489][INFO ][o.e.b.BootstrapChecks    ] [TESTPC] bound or publishing to a non-loopback address, enforcing bootstrap checks
ERROR: [1] bootstrap checks failed
[1]: the default discovery settings are unsuitable for production use; at least one of [discovery.seed_hosts, discovery.seed_providers, cluster.initial_master_nodes] must be configured
ERROR: Elasticsearch did not exit normally - check the logs at D:\elk\elasticsearch\logs\my_cluster.log
[2020-08-31T11:51:14,513][INFO ][o.e.n.Node               ] [TESTPC] stopping ...
[2020-08-31T11:51:14,536][INFO ][o.e.n.Node               ] [TESTPC] stopped
[2020-08-31T11:51:14,537][INFO ][o.e.n.Node               ] [TESTPC] closing ...
[2020-08-31T11:51:14,576][INFO ][o.e.n.Node               ] [TESTPC] closed
[2020-08-31T11:51:14,579][INFO ][o.e.x.m.p.NativeController] [TESTPC] Native controller process has stopped - no new native processes can be started

이 오류를 수정하려면, discovery.seed_hosts 옵션으로,

Problems with access to Elasticsearch form outside machine
; https://discuss.elastic.co/t/problems-with-access-to-elasticsearch-form-outside-machine/172450/3

빈 값을 넣어도 된다고 하는데,

discovery.seed_hosts: []

실제로 이렇게 설정하고 Elasticsearch 인스턴스를 실행하면 이번엔 종료는 안 되지만 다음과 같은 메시지가 반복되며 출력될 뿐,

[2020-08-31T16:23:44,260][WARN ][o.e.c.c.ClusterFormationFailureHelper] [TESTPC] master not discovered yet, this node has not previously joined a bootstrapped (v7+) cluster, and [cluster.initial_master_nodes] is empty on this node: have discovered [{TESTPC}{g1hWq0_bT7WurIZn9hWLOg}{GcqjG1_AQTyoyiKG32Yaag}{172.26.48.6}{172.26.48.6:9300}{dilmrt}{ml.machine_memory=8588800000, xpack.installed=true, transform.node=true, ml.max_open_jobs=20}]; discovery will continue using [] from hosts providers and [{TESTPC}{g1hWq0_bT7WurIZn9hWLOg}{GcqjG1_AQTyoyiKG32Yaag}{172.26.48.6}{172.26.48.6:9300}{dilmrt}{ml.machine_memory=8588800000, xpack.installed=true, transform.node=true, ml.max_open_jobs=20}] from last-known cluster state; node term 0, last-accepted version 0 in term 0


정상적인 동작은 하지 않습니다. 대신 discovery.seed_hosts에 (127.0.0.1이 아닌) "bound_addresses"로 출력된,

...[생략]...
[2020-08-31T11:51:13,844][INFO ][o.e.t.TransportService   ] [TESTPC] publish_address {172.26.48.6:9300}, bound_addresses {172.26.48.6:9300}, {192.168.0.167:9300}
...[생략]...

IP 주솟값을 줘야 합니다. 위의 출력에서는 "172.26.48.6", "192.168.0.167"이 있으므로 둘 중의 하나를 설정하고,

discovery.seed_hosts: [ "172.26.48.6" ]

이후, 2개 더 Elasticsearch.bat을 실행하는 경우 3개의 노드가 1개의 클러스터에 활성화한 것을 볼 수 있습니다.

c:\temp> curl -XGET "172.26.48.6:9200/_cat/health?v&pretty"
epoch      timestamp cluster    status node.total node.data shards pri relo init unassign pending_tasks max_task_wait_time active_shards_percent
1598859586 07:39:46  my_cluster green           3         3      0   0    0    0        0             0                  -                100.0%




향후 실행했을 때, 1개의 노드만 실행하는 경우 다음과 같이 예외가 발생할 수 있습니다.

[2020-08-31T16:58:51,417][WARN ][o.e.c.c.ClusterFormationFailureHelper] [TESTPC] master not discovered or elected yet, an election requires at least 2 nodes with ids from [Y0nYZsd2Q-izMTZQRF49vA, xU_vDh9uS7WDxJqlVqNmQw, abSNuGzETB-ah8M2LjfKKw], have discovered [{TESTPC}{Y0nYZsd2Q-izMTZQRF49vA}{ELdxViPRT8Gb0SmwUpeUEA}{172.26.48.6}{172.26.48.6:9300}{dilmrt}{ml.machine_memory=8588800000, xpack.installed=true, transform.node=true, ml.max_open_jobs=20}] which is not a quorum; discovery will continue using [] from hosts providers and [{TESTPC}{Y0nYZsd2Q-izMTZQRF49vA}{ELdxViPRT8Gb0SmwUpeUEA}{172.26.48.6}{172.26.48.6:9300}{dilmrt}{ml.machine_memory=8588800000, xpack.installed=true, transform.node=true, ml.max_open_jobs=20}] from last-known cluster state; node term 6, last-accepted version 52 in term 6


메시지에도 나오지만, 최소 2개 이상의 노드가 실행되어 있어야 하므로 하나 더 노드를 실행하면 정상적으로 서비스 하게 됩니다.




참고로, Elasticsearch의 바이너리를 설치하자마자 처음부터 yml 설정을 저런 식으로 바꿔서 실행하면 안 됩니다. 그런 경우, 메타 데이터를 생성하지 않은 상태로 서로 마스터로 승격된 것으로부터 동기화를 하려고 시도하므로 모든 노드가 메타 데이터가 없어 정상 동작을 하지 않게 됩니다.

따라서, 처음에는 기본 상태에서 Elasticsearch.bat을 실행해 기본 실행을 위한 Metadata 생성을 한 후 다음의 설정을 추가/구성하는 식으로 진행해야 합니다.

node.max_local_storage_nodes: 3
network.host: _site_
discovery.seed_hosts: [ "172.26.48.6" ]




"network.host"의 경우 공식 문서를 보면,

Elasticsearch Reference [7.9] - Modules - Network Settings
; https://www.elastic.co/guide/en/elasticsearch/reference/7.9/modules-network.html#network-interface-values

"127.0.0.1"을 나타내는 "_local_", 네트워크 어댑터마다 할당된 주소 중 사설 IP 대역을 선택하는 "_site_"와 공용 IP 대역을 선택하는 "_global_"이 있는데, 어떤 것을 선택하든 IPAddress.Any의 의미를 갖진 않습니다. 즉, "_site_"나 "_global_"로 선택한 경우 로컬 PC에서는 간편하게 127.0.0.1로도 접속하고 싶은데 그게 안 됩니다.

그래도 ^^ 괜찮습니다. 그냥 IPAddress.Any의 의미로 "0.0.0.0"을 지정해도 무방합니다.

network.host: 0.0.0.0

그런 경우 discovery.seed_hosts의 값도 IP 주소를 하드코딩하지 않고 127.0.0.1로 지정할 수 있습니다.

discovery.seed_hosts: [ "127.0.0.1" ]




같은 바이너리/yml 설정을 바탕으로 실행되었으므로 node 이름이 다소 멋있지 않은데요, 이 문제는 명령행을 다음과 같이 나눠서 실행하는 것으로 보완할 수 있습니다.

elasticsearch -Enode.name=node-1
elasticsearch -Enode.name=node-2
elasticsearch -Enode.name=node-3

그래서 head 크롬 확장으로 보면 다음과 같은 상태를 확인할 수 있습니다.

es_cluster_1.png




마지막으로 유의해야 할 것은, 공식 문서에도 나오지만,

Node - node.max_local_storage_nodes
; https://www.elastic.co/guide/en/elasticsearch/reference/current/modules-node.html#max-local-storage-nodes

This setting is deprecated in 7.x and will be removed in version 8.0.

이런 식의 테스트는 7.x까지만 가능하고 향후의 8.0부터는 없어진다는 점! 시간이 되시면 아래의 문서도 한 번쯤 읽어보시고. ^^

3.1 클러스터 구성
; https://esbook.kimjmin.net/03-cluster/3.1-cluster-settings




[이 글에 대해서 여러분들과 의견을 공유하고 싶습니다. 틀리거나 미흡한 부분 또는 의문 사항이 있으시면 언제든 댓글 남겨주십시오.]

[연관 글]






[최초 등록일: ]
[최종 수정일: 9/2/2020]

Creative Commons License
이 저작물은 크리에이티브 커먼즈 코리아 저작자표시-비영리-변경금지 2.0 대한민국 라이센스에 따라 이용하실 수 있습니다.
by SeongTae Jeong, mailto:techsharer at outlook.com

비밀번호

댓글 작성자
 




1  2  3  4  5  6  7  8  9  10  11  12  13  [14]  15  ...
NoWriterDateCnt.TitleFile(s)
13277정성태3/6/20234723개발 환경 구성: 668. 코드 사인용 인증서 신청 및 적용 방법(예: Digicert)
13276정성태3/5/20234405.NET Framework: 2102. C# 11 - ref struct/ref field를 위해 새롭게 도입된 scoped 예약어
13275정성태3/3/20234729.NET Framework: 2101. C# 11의 ref 필드 설명
13274정성태3/2/20234300.NET Framework: 2100. C# - ref 필드로 ref struct 타입을 허용하지 않는 이유
13273정성태2/28/20234015.NET Framework: 2099. C# - 관리 포인터로서의 ref 예약어 의미
13272정성태2/27/20234289오류 유형: 850. SSMS - mdf 파일을 Attach 시킬 때 Operating system error 5: "5(Access is denied.)" 에러
13271정성태2/25/20234203오류 유형: 849. Sql Server Configuration Manager가 시작 메뉴에 없는 경우
13270정성태2/24/20233827.NET Framework: 2098. dotnet build에 /p 옵션을 적용 시 유의점
13269정성태2/23/20234368스크립트: 46. 파이썬 - uvicorn의 콘솔 출력을 UDP로 전송
13268정성태2/22/20234919개발 환경 구성: 667. WSL 2 내부에서 열고 있는 UDP 서버를 호스트 측에서 접속하는 방법
13267정성태2/21/20234838.NET Framework: 2097. C# - 비동기 소켓 사용 시 메모리 해제가 finalizer 단계에서 발생하는 사례파일 다운로드1
13266정성태2/20/20234448오류 유형: 848. .NET Core/5+ - Process terminated. Couldn't find a valid ICU package installed on the system
13265정성태2/18/20234367.NET Framework: 2096. .NET Core/5+ - PublishSingleFile 유형에 대한 runtimeconfig.json 설정
13264정성태2/17/20235851스크립트: 45. 파이썬 - uvicorn 사용자 정의 Logger 작성
13263정성태2/16/20234011개발 환경 구성: 666. 최신 버전의 ilasm.exe/ildasm.exe 사용하는 방법
13262정성태2/15/20235075디버깅 기술: 191. dnSpy를 이용한 (소스 코드가 없는) 닷넷 응용 프로그램 디버깅 방법 [1]
13261정성태2/15/20234364Windows: 224. Visual Studio - 영문 폰트가 Fullwidth Latin Character로 바뀌는 문제
13260정성태2/14/20234154오류 유형: 847. ilasm.exe 컴파일 오류 - error : syntax error at token '-' in ... -inf
13259정성태2/14/20234293.NET Framework: 2095. C# - .NET5부터 도입된 CollectionsMarshal
13258정성태2/13/20234175오류 유형: 846. .NET Framework 4.8 Developer Pack 설치 실패 - 0x81f40001
13257정성태2/13/20234269.NET Framework: 2094. C# - Job에 Process 포함하는 방법 [1]파일 다운로드1
13256정성태2/10/20235102개발 환경 구성: 665. WSL 2의 네트워크 통신 방법 - 두 번째 이야기
13255정성태2/10/20234428오류 유형: 845. gihub - windows2022 이미지에서 .NET Framework 4.5.2 미만의 프로젝트에 대한 빌드 오류
13254정성태2/10/20234330Windows: 223. (WMI 쿼리를 위한) PowerShell 문자열 escape 처리
13253정성태2/9/20235113Windows: 222. C# - 다른 윈도우 프로그램이 실행되었음을 인식하는 방법파일 다운로드1
13252정성태2/9/20233938오류 유형: 844. ssh로 명령어 수행 시 멈춤 현상
1  2  3  4  5  6  7  8  9  10  11  12  13  [14]  15  ...