1.创建elasticsearch-cluster文件夹,在内部复制三个elasticsearch服务
2.修改集群文件目录中第一个节点的config/elasticsearch.yml配置文件
参数 | 值 | 说明 | |
---|---|---|---|
1 | cluster.name | my-application | 集群名称,节点之间保持一致 |
2 | node.name | node-1001 | 节点名称,集群内要唯一 |
3 | node.master | true | |
4 | node.data | true | |
5 | network.host | localhost | IP |
6 | http:port | 9201 | http:端口 |
7 | transport.tcp.port | 9301 | Tcp监听端口 |
8 | discovery.zen.fd.ping_timeout | ||
9 | discovery.zen.fd.ping_retries | ||
10 | discovery.seed_hosts | ||
11 | http.cors.enabled | true | 跨域配置 |
12 | 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 | node.master | true | |
4 | node.data | true | |
5 | network.host | localhost | IP |
6 | http:port | 9202 | http:端口 |
7 | transport.tcp.port | 9302 | Tcp监听端口 |
8 | discovery.zen.fd.ping_timeout | ||
9 | discovery.zen.fd.ping_retries | ||
10 | discovery.seed_hosts | ["localhost:9301"] | |
11 | http.cors.enabled | true | 跨域配置 |
12 | http.cors.allow-origin | “*” |
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 | node.master | true | |
4 | node.data | true | |
5 | network.host | localhost | IP |
6 | http:port | 9203 | http:端口 |
7 | transport.tcp.port | 9303 | Tcp监听端口 |
8 | discovery.zen.fd.ping_timeout | 这个节点时间太短容易找不到Master | |
9 | discovery.zen.fd.ping_retries | ||
10 | discovery.seed_hosts | ["localhost:9301","localhost:9302"] | |
11 | http.cors.enabled | true | 跨域配置 |
12 | 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
}