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)
13400정성태8/10/20233376오류 유형: 874. 파이썬 - pymssql을 윈도우 환경에서 설치 불가
13399정성태8/9/20233393닷넷: 2135. C# - 지역 변수로 이해하는 메서드 매개변수의 값/참조 전달
13398정성태8/3/20234164스크립트: 55. 파이썬 - pyodbc를 이용한 SQL Server 연결 사용법
13397정성태7/23/20233685닷넷: 2134. C# - 문자열 연결 시 string.Create를 이용한 GC 할당 최소화
13396정성태7/22/20233377스크립트: 54. 파이썬 pystack 소개 - 메모리 덤프로부터 콜 스택 열거
13395정성태7/20/20233332개발 환경 구성: 685. 로컬에서 개발 중인 ASP.NET Core/5+ 웹 사이트에 대해 localhost 이외의 호스트 이름으로 접근하는 방법
13394정성태7/16/20233283오류 유형: 873. Oracle.ManagedDataAccess.Client - 쿼리 수행 시 System.InvalidOperationException
13393정성태7/16/20233437닷넷: 2133. C# - Oracle 데이터베이스의 Sleep 쿼리 실행하는 방법
13392정성태7/16/20233316오류 유형: 872. Oracle - ORA-01031: insufficient privileges
13391정성태7/14/20233380닷넷: 2132. C# - sealed 클래스의 메서드를 callback 호출했을 때 인라인 처리가 될까요?
13390정성태7/12/20233368스크립트: 53. 파이썬 - localhost 호출 시의 hang 현상
13389정성태7/5/20233400개발 환경 구성: 684. IIS Express로 호스팅하는 웹을 WSL 환경에서 접근하는 방법
13388정성태7/3/20233532오류 유형: 871. 윈도우 탐색기에서 열리지 않는 zip 파일 - The Compressed (zipped) Folder '[...].zip' is invalid. [1]파일 다운로드1
13387정성태6/28/20233545오류 유형: 870. _mysql - Commands out of sync; you can't run this command now
13386정성태6/27/20233616Linux: 61. docker - 원격 제어를 위한 TCP 바인딩 추가
13385정성태6/27/20233829Linux: 60. Linux - 외부에서의 접속을 허용하기 위한 TCP 포트 여는 방법
13384정성태6/26/20233577.NET Framework: 2131. C# - Source Generator로 해결하는 enum 박싱 문제파일 다운로드1
13383정성태6/26/20233321개발 환경 구성: 683. GPU 런타임을 사용하는 Colab 노트북 설정
13382정성태6/25/20233367.NET Framework: 2130. C# - Win32 API를 이용한 윈도우 계정 정보 (예: 마지막 로그온 시간)파일 다운로드1
13381정성태6/25/20233751오류 유형: 869. Fatal Python error: init_fs_encoding: failed to get the Python codec of the filesystem encoding
13380정성태6/24/20233200스크립트: 52. 파이썬 3.x에서의 동적 함수 추가
13379정성태6/23/20233214스크립트: 51. 파이썬 2.x에서의 동적 함수 추가
13378정성태6/22/20233122오류 유형: 868. docker - build 시 "CANCELED ..." 뜨는 문제
13377정성태6/22/20236907오류 유형: 867. 파이썬 mysqlclient 2.2.x 설치 시 "Specify MYSQLCLIENT_CFLAGS and MYSQLCLIENT_LDFLAGS env vars manually" 오류
13376정성태6/21/20233294.NET Framework: 2129. C# - Polly를 이용한 클라이언트 측의 요청 재시도파일 다운로드1
13375정성태6/20/20232990스크립트: 50. Transformers (신경망 언어모델 라이브러리) 강좌 - 2장 코드 실행 결과
1  2  3  4  5  6  7  8  [9]  10  11  12  13  14  15  ...