1.确认主节点
[root@oracle1 ~]# curl http://192.168.1.7:9201/_cat/nodes
192.168.1.7 59 84 2 0.13 0.27 0.37 dilmt - esdb-node-1
192.168.1.7 43 84 2 0.13 0.27 0.37 dilmt * esdb-node-2
192.168.1.7 38 84 2 0.13 0.27 0.37 dilmt - esdb-node-3
--esdb-node-2 是主节点。对应目录是:/esdb/esapp/esapp9202/
2.关闭主节点
ps -ef |grep
esadmin 3009 2959 6 11:04 pts/0 00:01:04 /esdb/jdk-17.0.11/bin/java -Xshare:auto -Des.networkaddress.cache.ttl=60 -Des.networkaddress.cache.negative.ttl=10
-XX:+AlwaysPreTouch -Xss1m -Djava.awt.headless=true -Dfile.encoding=UTF-8
-Djna.nosys=true -XX:-OmitStackTraceInFastThrow -XX:+ShowCodeDetailsInExceptionMessages
-Dio.netty.noUnsafe=true -Dio.netty.noKeySetOptimization=true
-Dio.netty.recycler.maxCapacityPerThread=0 -Dio.netty.allocator.numDirectArenas=0
-Dlog4j.shutdownHookEnabled=false -Dlog4j2.disable.jmx=true
-Djava.locale.providers=SPI,COMPAT -server -Xmx256m -Xms256m -Xmn100m -Xss228K
-XX:+DisableExplicitGC -XX:HeapDumpPath=/esdb/eslog/eslog9202
-XX:ErrorFile=/esdb/eslog/eslog9202/hs_err_pid%p.log -Xlog:gc*,gc+age=trace,safepoint:file=/esdb/eslog/eslog9202/gc.log:utctime,pid,tags:filecount=32,filesize=64m -XX:+UseG1GC -XX:G1ReservePercent=25 -XX:InitiatingHeapOccupancyPercent=30 -Djava.io.tmpdir=/tmp/elasticsearch-17860247193418553795 -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=data -XX:ErrorFile=logs/hs_err_pid%p.log -XX:MaxDirectMemorySize=134217728 -Des.path.home=/esdb/esapp/esapp9202 -Des.path.conf=/esdb/esapp/esapp9202/config -Des.distribution.flavor=default -Des.distribution.type=tar -Des.bundled_jdk=true -cp /esdb/esapp/esapp9202/lib/* org.elasticsearch.bootstrap.Elasticsearch
*/
kill -9 3009
3.重新检查主节点
[root@oracle1 ~]# curl http://192.168.1.7:9201/_cat/nodes
192.168.1.7 45 77 3 0.05 0.23 0.35 dilmt * esdb-node-1
192.168.1.7 58 77 3 0.05 0.23 0.35 dilmt - esdb-node-3
--当前主节点已经转变为esdb-node-1
4.两个节点的情况下插入数据测试
curl -XPOST http://192.168.1.7:9201/mydb1/_doc/?pretty -H 'Content-Type: application/json' -d '
{
"id" : "2",
"name" : "xsq002",
"city" : "北京",
"course" : "mysql",
"teacher" : "da哥",
"pxdate": "20240627"
}'
[root@oracle1 ~]# curl -XPOST http://192.168.1.7:9201/mydb1/_doc/?pretty -H 'Content-Type: application/json' -d '
> {
> "id" : "2",
> "name" : "xsq002",
> "city" : "北京",
> "course" : "mysql",
> "teacher" : "da哥",
> "pxdate": "20240627"
> }'
{
"_index" : "mydb1",
"_type" : "_doc",
"_id" : "68u5V5ABQJTCooTXTrt_",
"_version" : 1,
"result" : "created",
"_shards" : {
"total" : 2,
"successful" : 2,
"failed" : 0
},
"_seq_no" : 1,
"_primary_term" : 1
}
--查看数据
[esadmin@oracle1 ~]$ curl -XPOST 'http://192.168.1.7:9203/mydb1/_search?pretty' -H 'Content-Type: application/json'
{
"took" : 761,
"timed_out" : false,
"_shards" : {
"total" : 1,
"successful" : 1,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : {
"value" : 2,
"relation" : "eq"
},
"max_score" : 1.0,
"hits" : [
{
"_index" : "mydb1",
"_type" : "_doc",
"_id" : "6suxV5ABQJTCooTXY7tl",
"_score" : 1.0,
"_source" : {
"id" : "1",
"name" : "xsq001",
"city" : "深圳",
"course" : "oracle",
"teacher" : "da哥",
"pxdate" : "20200829"
}
},
{
"_index" : "mydb1",
"_type" : "_doc",
"_id" : "68u5V5ABQJTCooTXTrt_",
"_score" : 1.0,
"_source" : {
"id" : "2",
"name" : "xsq002",
"city" : "北京",
"course" : "mysql",
"teacher" : "da哥",
"pxdate" : "20240627"
}
}
]
}
}
5.启动失败的节点
原来的主库关闭后,又加入了新的数据。当前主库还没有新新增的数据,
现在启动后我们观察是否同步了最新的数据。
(1)检查节点状态
[esadmin@oracle1 ~]$ curl http://192.168.1.7:9201/_cat/nodes
192.168.1.7 65 83 65 1.63 0.54 0.41 dilmt * esdb-node-1
192.168.1.7 32 83 87 1.63 0.54 0.41 dilmt - esdb-node-2
192.168.1.7 37 83 65 1.63 0.54 0.41 dilmt - esdb-node-3
(2)检查集群健康状态
[esadmin@oracle1 ~]$ curl http://192.168.1.7:9203/_cat/health?pretty -H 'Content-Type: application/json'
1719458917 03:28:37 escluster1 green 3 3 2 1 0 0 0 0 - 100.0%
(3)原来的主节点:9202上查询数据。
curl -XPOST 'http://192.168.1.7:9202/mydb1/_search?pretty' -H 'Content-Type: application/json'
[esadmin@oracle1 ~]$ curl -XPOST 'http://192.168.1.7:9202/mydb1/_search?pretty' -H 'Content-Type: application/json'
{
"took" : 1096,
"timed_out" : false,
"_shards" : {
"total" : 1,
"successful" : 1,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : {
"value" : 2,
"relation" : "eq"
},
"max_score" : 1.0,
"hits" : [
{
"_index" : "mydb1",
"_type" : "_doc",
"_id" : "6suxV5ABQJTCooTXY7tl",
"_score" : 1.0,
"_source" : {
"id" : "1",
"name" : "xsq001",
"city" : "深圳",
"course" : "oracle",
"teacher" : "da哥",
"pxdate" : "20200829"
}
},
{
"_index" : "mydb1",
"_type" : "_doc",
"_id" : "68u5V5ABQJTCooTXTrt_",
"_score" : 1.0,
"_source" : {
"id" : "2",
"name" : "xsq002",
"city" : "北京",
"course" : "mysql",
"teacher" : "da哥",
"pxdate" : "20240627"
}
}
]
}
}
6.总结
由此可见,三个节点以上的集群,单个节点宕机,不影响集群。可以照常提供
对外服务。老的节点启动后,会重新自动加入集群,并同步丢失的数据。