windows集群
# 部署集群
创建 elasticsearch-cluster 文件夹,在内部复制三个 elasticsearch 服务
修改集群文件目录中每个节点的 config/elasticsearch.yml 配置文件
# node-1001
#节点 1 的配置信息:
#集群名称,节点之间要保持一致
cluster.name: my-elasticsearch
#节点名称,集群内要唯一
node.name: node-1001
node.master: true
node.data: true
#ip 地址
network.host: localhost
#http 端口
http.port: 1001
#tcp 监听端口
transport.tcp.port: 9301
#discovery.seed_hosts: ["localhost:9301", "localhost:9302","localhost:9303"]
#discovery.zen.fd.ping_timeout: 1m
#discovery.zen.fd.ping_retries: 5
#集群内的可以被选为主节点的节点列表
#cluster.initial_master_nodes: ["node-1", "node-2","node-3"]
#跨域配置
#action.destructive_requires_name: true
http.cors.enabled: true
http.cors.allow-origin: "*"
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# node-1002
#节点 2 的配置信息:
#集群名称,节点之间要保持一致
cluster.name: my-elasticsearch
#节点名称,集群内要唯一
node.name: node-1002
node.master: true
node.data: true
#ip 地址
network.host: localhost
#http 端口
http.port: 1002
#tcp 监听端口
transport.tcp.port: 9302
discovery.seed_hosts: ["localhost:9301"]
discovery.zen.fd.ping_timeout: 1m
discovery.zen.fd.ping_retries: 5
#集群内的可以被选为主节点的节点列表
#cluster.initial_master_nodes: ["node-1", "node-2","node-3"]
#跨域配置
#action.destructive_requires_name: true
http.cors.enabled: true
http.cors.allow-origin: "*"
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# node-1003
#节点 3 的配置信息:
#集群名称,节点之间要保持一致
cluster.name: my-elasticsearch
#节点名称,集群内要唯一
node.name: node-1003
node.master: true
node.data: true
#ip 地址
network.host: localhost
#http 端口
http.port: 1003
#tcp 监听端口
transport.tcp.port: 9303
#候选主节点的地址,在开启服务后可以被选为主节点
discovery.seed_hosts: ["localhost:9301", "localhost:9302"]
discovery.zen.fd.ping_timeout: 1m
discovery.zen.fd.ping_retries: 5
#集群内的可以被选为主节点的节点列表
#cluster.initial_master_nodes: ["node-1", "node-2","node-3"]
#跨域配置
#action.destructive_requires_name: true
http.cors.enabled: true
http.cors.allow-origin: "*"
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# 启动集群
启动前先删除每个节点中的 data 目录中所有内容(如果存在)
分别双击执行 bin/elasticsearch.bat, 启动节点服务器,启动后,会自动加入指定名称的集群
node-1001 启动信息如下
...
[2022-01-29T20:56:19,426][INFO ][o.e.c.m.MetadataIndexTemplateService] [node-1001] adding template [.monitoring-alerts-7] for index patterns [.monitoring-alerts-7]
[2022-01-29T20:56:19,483][INFO ][o.e.c.m.MetadataIndexTemplateService] [node-1001] adding template [.monitoring-kibana] for index patterns [.monitoring-kibana-7-*]
[2022-01-29T20:56:19,523][INFO ][o.e.x.i.a.TransportPutLifecycleAction] [node-1001] adding index lifecycle policy [watch-history-ilm-policy]
[2022-01-29T20:56:19,565][INFO ][o.e.x.i.a.TransportPutLifecycleAction] [node-1001] adding index lifecycle policy [ml-size-based-ilm-policy]
[2022-01-29T20:56:19,609][INFO ][o.e.x.i.a.TransportPutLifecycleAction] [node-1001] adding index lifecycle policy [ilm-history-ilm-policy]
[2022-01-29T20:56:19,642][INFO ][o.e.x.i.a.TransportPutLifecycleAction] [node-1001] adding index lifecycle policy [slm-history-ilm-policy]
[2022-01-29T20:56:19,767][INFO ][o.e.l.LicenseService ] [node-1001] license [09189eef-c989-4cb2-89c6-d49b1087cf82] mode [basic] - valid
[2022-01-29T20:56:19,768][INFO ][o.e.x.s.s.SecurityStatusChangeListener] [node-1001] Active license is now [BASIC]; Security is disabled
1
2
3
4
5
6
7
8
9
2
3
4
5
6
7
8
9
node-1002 启动信息如下
...
[2022-01-29T20:57:21,703][INFO ][o.e.p.PluginsService ] [node-1002] loaded module [x-pack-watcher]
[2022-01-29T20:57:21,703][INFO ][o.e.p.PluginsService ] [node-1002] no plugins loaded
[2022-01-29T20:57:22,998][INFO ][o.e.e.NodeEnvironment ] [node-1002] using [1] data paths, mounts [[Data (D:)]], net usable_space [265.4gb], net total_space [343.3gb], types [NTFS]
[2022-01-29T20:57:22,999][INFO ][o.e.e.NodeEnvironment ] [node-1002] heap size [989.8mb], compressed ordinary object pointers [true]
[2022-01-29T20:57:24,191][INFO ][o.e.n.Node ] [node-1002] node name [node-1002], node ID [C4Po74pXRmGe7uw5iJhv5Q], cluster name [my-elasticsearch]
[2022-01-29T20:57:27,497][INFO ][o.e.x.s.a.s.FileRolesStore] [node-1002] parsed [0] roles from file [D:\tool\elasticsearch-cluster\node-1002\config\roles.yml]
[2022-01-29T20:57:28,165][INFO ][o.e.x.m.p.l.CppLogMessageHandler] [node-1002] [controller/286008] [Main.cc@110] controller (64 bit): Version 7.8.0 (Build 58ff6912e20047) Copyright (c) 2020 Elasticsearch BV
[2022-01-29T20:57:28,995][INFO ][o.e.d.DiscoveryModule ] [node-1002] using discovery type [zen] and seed hosts providers [settings]
[2022-01-29T20:57:29,862][INFO ][o.e.n.Node ] [node-1002] initialized
[2022-01-29T20:57:29,863][INFO ][o.e.n.Node ] [node-1002] starting ...
[2022-01-29T20:57:31,143][INFO ][o.e.t.TransportService ] [node-1002] publish_address {localhost/127.0.0.1:9302}, bound_addresses {127.0.0.1:9302}, {[::1]:9302}
[2022-01-29T20:57:31,634][INFO ][o.e.c.s.ClusterApplierService] [node-1002] master node changed {previous [], current [{node-1001}{d8i8fwkzS-akQN6gIJKpCA}{yR6d2VsgQPKb9BfnuURh0Q}{localhost}{127.0.0.1:9301}{dilmrt}{ml.machine_memory=16505966592, ml.max_open_jobs=20, xpack.installed=true, transform.node=true}]}, added {{node-1001}{d8i8fwkzS-akQN6gIJKpCA}{yR6d2VsgQPKb9BfnuURh0Q}{localhost}{127.0.0.1:9301}{dilmrt}{ml.machine_memory=16505966592, ml.max_open_jobs=20, xpack.installed=true, transform.node=true}}, term: 1, version: 28, reason: ApplyCommitRequest{term=1, version=28, sourceNode={node-1001}{d8i8fwkzS-akQN6gIJKpCA}{yR6d2VsgQPKb9BfnuURh0Q}{localhost}{127.0.0.1:9301}{dilmrt}{ml.machine_memory=16505966592, ml.max_open_jobs=20, xpack.installed=true, transform.node=true}}
[2022-01-29T20:57:31,770][INFO ][o.e.x.s.a.TokenService ] [node-1002] refresh keys
[2022-01-29T20:57:31,932][INFO ][o.e.x.s.a.TokenService ] [node-1002] refreshed keys
[2022-01-29T20:57:31,960][INFO ][o.e.l.LicenseService ] [node-1002] license [09189eef-c989-4cb2-89c6-d49b1087cf82] mode [basic] - valid
[2022-01-29T20:57:31,962][INFO ][o.e.x.s.s.SecurityStatusChangeListener] [node-1002] Active license is now [BASIC]; Security is disabled
[2022-01-29T20:57:32,027][INFO ][o.e.h.AbstractHttpServerTransport] [node-1002] publish_address {localhost/127.0.0.1:1002}, bound_addresses {127.0.0.1:1002}, {[::1]:1002}
[2022-01-29T20:57:32,028][INFO ][o.e.n.Node ] [node-1002] started
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
node-1003启动信息如下
...
[2022-01-29T20:58:50,004][INFO ][o.e.p.PluginsService ] [node-1003] no plugins loaded
[2022-01-29T20:58:51,256][INFO ][o.e.e.NodeEnvironment ] [node-1003] using [1] data paths, mounts [[Data (D:)]], net usable_space [265.4gb], net total_space [343.3gb], types [NTFS]
[2022-01-29T20:58:51,257][INFO ][o.e.e.NodeEnvironment ] [node-1003] heap size [989.8mb], compressed ordinary object pointers [true]
[2022-01-29T20:58:52,414][INFO ][o.e.n.Node ] [node-1003] node name [node-1003], node ID [CxUbAYfZRyWCd7p_SKdOQw], cluster name [my-elasticsearch]
[2022-01-29T20:58:55,516][INFO ][o.e.x.s.a.s.FileRolesStore] [node-1003] parsed [0] roles from file [D:\tool\elasticsearch-cluster\node-1003\config\roles.yml]
[2022-01-29T20:58:56,210][INFO ][o.e.x.m.p.l.CppLogMessageHandler] [node-1003] [controller/285972] [Main.cc@110] controller (64 bit): Version 7.8.0 (Build 58ff6912e20047) Copyright (c) 2020 Elasticsearch BV
[2022-01-29T20:58:56,884][INFO ][o.e.d.DiscoveryModule ] [node-1003] using discovery type [zen] and seed hosts providers [settings]
[2022-01-29T20:58:57,652][INFO ][o.e.n.Node ] [node-1003] initialized
[2022-01-29T20:58:57,653][INFO ][o.e.n.Node ] [node-1003] starting ...
[2022-01-29T20:58:58,901][INFO ][o.e.t.TransportService ] [node-1003] publish_address {localhost/127.0.0.1:9303}, bound_addresses {127.0.0.1:9303}, {[::1]:9303}
[2022-01-29T20:58:59,390][INFO ][o.e.c.s.ClusterApplierService] [node-1003] master node changed {previous [], current [{node-1001}{d8i8fwkzS-akQN6gIJKpCA}{yR6d2VsgQPKb9BfnuURh0Q}{localhost}{127.0.0.1:9301}{dilmrt}{ml.machine_memory=16505966592, ml.max_open_jobs=20, xpack.installed=true, transform.node=true}]}, added {{node-1002}{C4Po74pXRmGe7uw5iJhv5Q}{IAgxwL-2S3edztKb5JfsTg}{localhost}{127.0.0.1:9302}{dilmrt}{ml.machine_memory=16505966592, ml.max_open_jobs=20, xpack.installed=true, transform.node=true},{node-1001}{d8i8fwkzS-akQN6gIJKpCA}{yR6d2VsgQPKb9BfnuURh0Q}{localhost}{127.0.0.1:9301}{dilmrt}{ml.machine_memory=16505966592, ml.max_open_jobs=20, xpack.installed=true, transform.node=true}}, term: 1, version: 29, reason: ApplyCommitRequest{term=1, version=29, sourceNode={node-1001}{d8i8fwkzS-akQN6gIJKpCA}{yR6d2VsgQPKb9BfnuURh0Q}{localhost}{127.0.0.1:9301}{dilmrt}{ml.machine_memory=16505966592, ml.max_open_jobs=20, xpack.installed=true, transform.node=true}}
[2022-01-29T20:58:59,557][INFO ][o.e.x.s.a.TokenService ] [node-1003] refresh keys
[2022-01-29T20:58:59,723][INFO ][o.e.x.s.a.TokenService ] [node-1003] refreshed keys
[2022-01-29T20:58:59,754][INFO ][o.e.l.LicenseService ] [node-1003] license [09189eef-c989-4cb2-89c6-d49b1087cf82] mode [basic] - valid
[2022-01-29T20:58:59,755][INFO ][o.e.x.s.s.SecurityStatusChangeListener] [node-1003] Active license is now [BASIC]; Security is disabled
[2022-01-29T20:58:59,859][INFO ][o.e.h.AbstractHttpServerTransport] [node-1003] publish_address {localhost/127.0.0.1:1003}, bound_addresses {127.0.0.1:1003}, {[::1]:1003}
[2022-01-29T20:58:59,860][INFO ][o.e.n.Node ] [node-1003] started
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# 测试集群
# 健康检查
node-1001节点
GET http://localhost:1001/_cluster/health
1
response
- status
- green 所有的主分片和副本分片都正常运行
- yellow 所有的主分片都正常运行,但不是所有的副本分片都正常运行
- red 有主分片没有正常运行
- number_of_nodes表示nodes个数是3个
- number_of_data_nodes表示数据节点是3个
{
"cluster_name": "my-elasticsearch",
"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
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
node-1002节点
GET http://localhost:1002/_cluster/health
1
response
{
"cluster_name": "my-elasticsearch",
"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
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
node-1003节点
GET http://localhost:1003/_cluster/healthGET
1
response
{
"cluster_name": "my-elasticsearch",
"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
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# 增加索引
用Postman,在一节点增加索引,另一节点获取索引
创建user索引
GET http://localhost:1002/user
1
response
{
"acknowledged": true,
"shards_acknowledged": true,
"index": "user"
}
1
2
3
4
5
2
3
4
5
# 查看索引
GET http://localhost:1001/user
1
response
{
"user": {
"aliases": {},
"mappings": {},
"settings": {
"index": {
"creation_date": "1643461652685",
"number_of_shards": "1",
"number_of_replicas": "1",
"uuid": "iywRYB0KSDO6RpXajLJj7g",
"version": {
"created": "7080099"
},
"provided_name": "user"
}
}
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
如果在1003创建索引,同样在1001也能获取索引信息
Last Updated: 2022/02/05, 15:58:51