1.创建elasticsearch-cluster文件夹,在内部复制三个elasticsearch服务

2.修改集群文件目录中第一个节点的config/elasticsearch.yml配置文件
| 参数 | 值 | 说明 | |
|---|---|---|---|
| 1 | cluster.name | my-application | 集群名称,节点之间保持一致 |
| 2 | node.name | node-1001 | 节点名称,集群内要唯一 |
| 3 | discovery.seed_hosts | ["192.168.2.3:9301","192.168.2.3:9302","192.168.2.3:9303"] | |
| 4 | cluster.initial_master_nodes | ["192.168.2.3:9301"] | maste节点必须有 |
| 5 | network.host | 0.0.0.0 | IP |
| 6 | http:port | 9201 | http:端口 |
| 7 | transport.tcp.port | 9301 | Tcp监听端口 |
| 8 | bootstrap.memory_lock | true | |
| 9 | bootstrap.system_call_filter | false | |
| 10 | http.cors.enabled | true | 跨域配置 |
| 11 | http.cors.allow-origin | “*” | |
3.执行 bin/elasticsearch.bat, 启动节点服务器,启动后,会自动加入指定名称的集群
4.启动node-1001后,查看集群状态
在Postman中向ES服务器发,GET: http://localhost:9201/_cluster/health
{
"cluster_name": "my-application",
"status": "green",
"timed_out": false,
"number_of_nodes": 1,
"number_of_data_nodes": 1,
"active_primary_shards": 0,
"active_shards": 0,
"relocating_shards": 0,
"initializing_shards": 0,
"unassigned_shards": 0,
"delayed_unassigned_shards": 0,
"number_of_pending_tasks": 0,
"number_of_in_flight_fetch": 0,
"task_max_waiting_in_queue_millis": 0,
"active_shards_percent_as_number": 100.0
}
5.修改集群文件目录中第二个节点的config/elasticsearch.yml配置文件
| 参数 | 值 | 说明 | |
|---|---|---|---|
| 1 | cluster.name | my-application | 集群名称,节点之间保持一致 |
| 2 | node.name | node-1002 | 节点名称,集群内要唯一 |
| 3 | discovery.seed_hosts | ["192.168.2.3:9301","192.168.2.3:9302","192.168.2.3:9303"] | |
| 4 | cluster.initial_master_nodes | ["192.168.2.3:9301"] | maste节点必须有 |
| 5 | network.host | 0.0.0.0 | IP |
| 6 | http:port | 9202 | http:端口 |
| 7 | transport.tcp.port | 9302 | Tcp监听端口 |
| 8 | bootstrap.memory_lock | true | |
| 9 | bootstrap.system_call_filter | false | |
| 10 | http.cors.enabled | true | 跨域配置 |
| 11 | http.cors.allow-origin | “*” | |
| 12 | |||
6.启动node-1002后,查看集群状态
在Postman中向ES服务器发,GET: http://localhost:9201/_cluster/health
{
"cluster_name": "my-application",
"status": "green",
"timed_out": false,
"number_of_nodes": 2,
"number_of_data_nodes": 2,
"active_primary_shards": 0,
"active_shards": 0,
"relocating_shards": 0,
"initializing_shards": 0,
"unassigned_shards": 0,
"delayed_unassigned_shards": 0,
"number_of_pending_tasks": 0,
"number_of_in_flight_fetch": 0,
"task_max_waiting_in_queue_millis": 0,
"active_shards_percent_as_number": 100.0
}
7.修改集群文件目录中第三个节点的config/elasticsearch.yml配置文件
| 参数 | 值 | 说明 | |
|---|---|---|---|
| 1 | cluster.name | my-application | 集群名称,节点之间保持一致 |
| 2 | node.name | node-1003 | 节点名称,集群内要唯一 |
| 3 | discovery.seed_hosts | ["192.168.2.3:9301","192.168.2.3:9302","192.168.2.3:9303"] | |
| 4 | cluster.initial_master_nodes | ["192.168.2.3:9301"] | maste节点必须有 |
| 5 | network.host | 0.0.0.0 | IP |
| 6 | http:port | 9203 | http:端口 |
| 7 | transport.tcp.port | 9303 | Tcp监听端口 |
| 8 | bootstrap.memory_lock | true | |
| 9 | bootstrap.system_call_filter | false | |
| 10 | http.cors.enabled | true | 跨域配置 |
| 11 | http.cors.allow-origin | “*” | |
8.启动node-1003后,查看集群状态
在Postman中向ES服务器发,GET: http://localhost:9201/_cluster/health
{
"cluster_name": "my-application",
"status": "green",
"timed_out": false,
"number_of_nodes": 3,
"number_of_data_nodes": 3,
"active_primary_shards": 0,
"active_shards": 0,
"relocating_shards": 0,
"initializing_shards": 0,
"unassigned_shards": 0,
"delayed_unassigned_shards": 0,
"number_of_pending_tasks": 0,
"number_of_in_flight_fetch": 0,
"task_max_waiting_in_queue_millis": 0,
"active_shards_percent_as_number": 100.0
}
9. discovery.seed_hosts值最少是填写3个,少了运行不起来,如果每个节点都是一台服务器,可以把端口呈去掉按默认9300即可
10.如想添加第4个节点,配置如下:
| 参数 | 值 | 说明 | |
|---|---|---|---|
| 1 | cluster.name | my-application | 集群名称,节点之间保持一致 |
| 2 | node.name | node-1004 | 节点名称,集群内要唯一 |
| 3 | discovery.seed_hosts | ["192.168.2.3:9301","192.168.2.3:9302" ,"192.168.2.3:9303","192.168.2.3:9304"] | |
| 4 | cluster.initial_master_nodes | ["192.168.2.3:9301"] | maste节点必须有 |
| 5 | network.host | 0.0.0.0 | IP |
| 6 | http:port | 9204 | http:端口 |
| 7 | transport.tcp.port | 9304 | Tcp监听端口 |
| 8 | bootstrap.memory_lock | true | |
| 9 | bootstrap.system_call_filter | false | |
| 10 | http.cors.enabled | true | 跨域配置 |
| 11 | http.cors.allow-origin | “*” | |
本文详细指导如何在Windows上创建并配置三个Elasticsearch节点,设置集群名称、节点名和种子主机,确保节点间正确通信。通过Postman监控集群健康状态,逐步增加节点,展示跨域配置和发现服务的过程。
141

被折叠的 条评论
为什么被折叠?



