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)
13548정성태2/1/20242302개발 환경 구성: 705. "Docker Desktop for Windows" - ASP.NET Core 응용 프로그램의 소켓 주소 바인딩(IPv4/IPv6 loopback, Any)
13547정성태1/31/20242052개발 환경 구성: 704. Visual Studio - .NET 8 프로젝트부터 dockerfile에 추가된 "USER app" 설정
13546정성태1/30/20241894Windows: 255. (디버거의 영향 등으로) 대상 프로세스가 멈추면 Socket KeepAlive로 연결이 끊길까요?
13545정성태1/30/20241823닷넷: 2212. ASP.NET Core - 우선순위에 따른 HTTP/HTTPS 호스트:포트 바인딩 방법
13544정성태1/30/20241846오류 유형: 894. Microsoft.Data.SqlClient - Could not load file or assembly 'System.Security.Permissions, ...'
13543정성태1/30/20241822Windows: 254. Windows - 기본 사용 중인 5357 포트 비활성화는 방법
13542정성태1/30/20241875오류 유형: 893. Visual Studio - Web Application을 실행하지 못하는 IISExpress - 두 번째 이야기
13541정성태1/29/20241919VS.NET IDE: 188. launchSettings.json의 useSSL 옵션
13540정성태1/29/20242049Linux: 69. 리눅스 - "Docker Desktop for Windows" Container 환경에서 IPv6 Loopback Address 바인딩 오류
13539정성태1/26/20242141개발 환경 구성: 703. Visual Studio - launchSettings.json을 이용한 HTTP/HTTPS 포트 바인딩
13538정성태1/25/20242210닷넷: 2211. C# - NonGC(FOH) 영역에 .NET 개체를 생성파일 다운로드1
13537정성태1/24/20242257닷넷: 2210. C# - Native 메모리에 .NET 개체를 생성파일 다운로드1
13536정성태1/23/20242368닷넷: 2209. .NET 8 - NonGC Heap / FOH (Frozen Object Heap) [1]
13535정성태1/22/20242200닷넷: 2208. C# - GCHandle 구조체의 메모리 분석
13534정성태1/21/20242030닷넷: 2207. C# - SQL Server DB를 bacpac으로 Export/Import파일 다운로드1
13533정성태1/18/20242223닷넷: 2206. C# - TCP KeepAlive의 서버 측 구현파일 다운로드1
13532정성태1/17/20242134닷넷: 2205. C# - SuperSimpleTcp 사용 시 주의할 점파일 다운로드1
13531정성태1/16/20242019닷넷: 2204. C# - TCP KeepAlive에 새로 추가된 Retry 옵션파일 다운로드1
13530정성태1/15/20242008닷넷: 2203. C# - Python과의 AES 암호화 연동파일 다운로드1
13529정성태1/15/20241893닷넷: 2202. C# - PublishAot의 glibc에 대한 정적 링킹하는 방법
13528정성태1/14/20242029Linux: 68. busybox 컨테이너에서 실행 가능한 C++, Go 프로그램 빌드
13527정성태1/14/20241957오류 유형: 892. Visual Studio - Failed to launch debug adapter. Additional information may be available in the output window.
13526정성태1/14/20242043닷넷: 2201. C# - Facebook 연동 / 사용자 탈퇴 처리 방법
13525정성태1/13/20242010오류 유형: 891. Visual Studio - Web Application을 실행하지 못하는 IISExpress
13524정성태1/12/20242063오류 유형: 890. 한국투자증권 KIS Developers OpenAPI - GW라우팅 중 오류가 발생했습니다.
13523정성태1/12/20241886오류 유형: 889. Visual Studio - error : A project with that name is already opened in the solution.
1  2  [3]  4  5  6  7  8  9  10  11  12  13  14  15  ...