查看集群状态
root@node-25:~# curl http://10.20x.6.4:9200/_cluster/health\?pretty
{
“cluster_name” : “lma”,
“status” : “red”,
“timed_out” : false,
“number_of_nodes” : 3,
“number_of_data_nodes” : 3,
“active_primary_shards” : 1900,
“active_shards” : 5700,
“relocating_shards” : 0,
“initializing_shards” : 0,
“unassigned_shards” : 15,
“delayed_unassigned_shards” : 0,
“number_of_pending_tasks” : 0,
“number_of_in_flight_fetch” : 0
}
查看集群分片
root@node-25:~# curl -s “http://10.20x.6.4:9200/_cat/shards“
notification-2018.08.30 2 r STARTED 4814 5.3mb 10.20x.6.14 node-25.domain.tld_es-01
notification-2018.08.30 2 r STARTED 4814 5.3mb 10.20x.6.7 node-26.domain.tld_es-01
notification-2018.08.30 2 p STARTED 4814 5.3mb 10.20x.6.20 node-35.domain.tld_es-01
notification-2018.08.30 0 p STARTED 4690 5.1mb 10.20x.6.14 node-25.domain.tld_es-01
notification-2018.08.30 0 r STARTED 4690 5.1mb 10.20x.6.7 node-26.domain.tld_es-01
notification-2018.08.30 0 r STARTED 4690 5.1mb 10.20x.6.20 node-35.domain.tld_es-01
notification-2018.08.30 3 p STARTED 4872 5.3mb 10.20x.6.14 node-25.domain.tld_es-01
notification-2018.08.30 3 r STARTED 4872 5.3mb 10.20x.6.7 node-26.domain.tld_es-01
notification-2018.08.30 3 r STARTED 4872 5.3mb 10.20x.6.20 node-35.domain.tld_es-01
notification-2018.08.30 1 p STARTED 4772 5.1mb 10.20x.6.14 node-25.domain.tld_es-01
notification-2018.08.30 1 r STARTED 4772 5.1mb 10.20x.6.7 node-26.domain.tld_es-01
notification-2018.08.30 1 r STARTED 4772 5.1mb 10.20x.6.20 node-35.domain.tld_es-01
notification-2018.08.30 4 p STARTED 4882 5.3mb 10.20x.6.14 node-25.domain.tld_es-01
notification-2018.08.30 4 r STARTED 4882 5.3mb 10.20x.6.7 node-26.domain.tld_es-01
notification-2018.08.30 4 r STARTED 4882 5.3mb 10.20x.6.20 node-35.domain.tld_es-01
notification-2018.08.31 4 r STARTED 4682 5.1mb 10.20x.6.14 node-25.domain.tld_es-01
notification-2018.08.31 4 r STARTED 4682 5.1mb 10.20x.6.7 node-26.domain.tld_es-01
notification-2018.08.31 4 p STARTED 4682 5.1mb 10.20x.6.20 node-35.domain.tld_es-01
notification-2018.08.31 0 p STARTED 4758 5.2mb 10.20x.6.14 node-25.domain.tld_es-01
notification-2018.08.31 0 r STARTED 4758 5.2mb 10.20x.6.7 node-26.domain.tld_es-01
notification-2018.08.31 0 r STARTED 4758 5.2mb 10.20x.6.20 node-35.domain.tld_es-01
notification-2018.08.31 3 r STARTED 4883 5.3mb 10.20x.6.14 node-25.domain.tld_es-01
notification-2018.08.31 3 r STARTED 4883 5.3mb 10.20x.6.7 node-26.domain.tld_es-01
notification-2018.08.31 3 p STARTED 4883 5.3mb 10.20x.6.20 node-35.domain.tld_es-01
notification-2018.08.31 1 r STARTED 4813 5.3mb 10.20x.6.14 node-25.domain.tld_es-01
notification-2018.08.31 1 r STARTED 4813 5.3mb 10.20x.6.7 node-26.domain.tld_es-01
notification-2018.08.31 1 p STARTED 4813 5.3mb 10.20x.6.20 node-35.domain.tld_es-01
notification-2018.08.31 2 r STARTED 4857 5.3mb 10.20x.6.14 node-25.domain.tld_es-01
notification-2018.08.31 2 r STARTED 4857 5.3mb 10.20x.6.7 node-26.domain.tld_es-01
notification-2018.08.31 2 p STARTED 4857 5.3mb 10.20x.6.20 node-35.domain.tld_es-01
log-2018.11.01 4 r STARTED 3340643 1gb 10.20x.6.14 node-25.domain.tld_es-01
log-2018.11.01 4 r STARTED 3340643 1gb 10.20x.6.7 node-26.domain.tld_es-01
log-2018.11.01 4 p STARTED 3340643 1gb 10.20x.6.20 node-35.domain.tld_es-01
log-2018.11.01 0 r STARTED 3339632 1gb 10.20x.6.14 node-25.domain.tld_es-01
log-2018.11.01 0 r STARTED 3339632 1gb 10.20x.6.7 node-26.domain.tld_es-01
log-2018.11.01 0 p STARTED 3339632 1gb 10.20x.6.20 node-35.domain.tld_es-01
log-2018.11.01 3 r STARTED 3339629 1gb 10.20x.6.14 node-25.domain.tld_es-01
log-2018.11.01 3 r STARTED 3339629 1gb 10.20x.6.7 node-26.domain.tld_es-01
log-2018.11.01 3 p STARTED 3339629 1gb 10.20x.6.20 node-35.domain.tld_es-01
log-2018.11.01 1 p STARTED 3338539 1gb 10.20x.6.14 node-25.domain.tld_es-01
log-2018.11.01 1 r STARTED 3338539 1gb 10.20x.6.7 node-26.domain.tld_es-01
log-2018.11.01 1 r STARTED 3338539 1gb 10.20x.6.20 node-35.domain.tld_es-01
log-2018.11.01 2 r STARTED 3339770 1gb 10.20x.6.14 node-25.domain.tld_es-01
log-2018.11.01 2 r STARTED 3339770 1gb 10.20x.6.7 node-26.domain.tld_es-01
log-2018.11.01 2 p STARTED 3339770 1gb 10.20x.6.20 node-35.domain.tld_es-01
notification-2018.10.29 4 p STARTED 4834 5.3mb 10.20x.6.14 node-25.domain.tld_es-01
notification-2018.10.29 4 r STARTED 4834 5.3mb 10.20x.6.7 node-26.domain.tld_es-01
notification-2018.10.29 4 r STARTED 4834 5.3mb 10.20x.6.20 node-35.domain.tld_es-01
notification-2018.10.29 0 p STARTED 4800 5.2mb 10.20x.6.14 node-25.domain.tld_es-01
notification-2018.10.29 0 r STARTED 4800 5.2mb 10.20x.6.7 node-26.domain.tld_es-01
notification-2018.10.29 0 r STARTED 4800 5.2mb 10.20x.6.20 node-35.domain.tld_es-01
notification-2018.10.29 3 p STARTED 4785 5.3mb 10.20x.6.14 node-25.domain.tld_es-01
notification-2018.10.29 3 r STARTED 4785 5.3mb 10.20x.6.7 node-26.domain.tld_es-01
notification-2018.10.29 3 r STARTED 4785 5.3mb 10.20x.6.20 node-35.domain.tld_es-01
notification-2018.10.29 1 p STARTED 4790 5.3mb 10.20x.6.14 node-25.domain.tld_es-01
notification-2018.10.29 1 r STARTED 4790 5.3mb 10.20x.6.7 node-26.domain.tld_es-01
notification-2018.10.29 1 r STARTED 4790 5.3mb 10.20x.6.20 node-35.domain.tld_es-01
notification-2018.10.29 2 r STARTED 4784 5.2mb 10.20x.6.14 node-25.domain.tld_es-01
notification-2018.10.29 2 r STARTED 4784 5.2mb 10.20x.6.7 node-26.domain.tld_es-01
notification-2018.10.29 2 p STARTED 4784 5.2mb 10.20x.6.20 node-35.domain.tld_es-01
notification-2018.10.28 4 r STARTED 4906 5.3mb 10.20x.6.14 node-25.domain.tld_es-01
notification-2018.10.28 4 r STARTED 4906 5.3mb 10.20x.6.7 node-26.domain.tld_es-01
notification-2018.10.28 4 p STARTED 4906 5.3mb 10.20x.6.20 node-35.domain.tld_es-01
notification-2018.10.28 0 p STARTED 4822 5.2mb 10.20x.6.14 node-25.domain.tld_es-01
notification-2018.10.28 0 r STARTED 4822 5.2mb 10.20x.6.7 node-26.domain.tld_es-01
notification-2018.10.28 0 r STARTED 4822 5.2mb 10.20x.6.20 node-35.domain.tld_es-01
notification-2018.10.28 3 r STARTED 4903 5.4mb 10.20x.6.14 node-25.domain.tld_es-01
notification-2018.10.28 3 r STARTED 4903 5.4mb 10.20x.6.7 node-26.domain.tld_es-01
notification-2018.10.28 3 p STARTED 4903 5.4mb 10.20x.6.20 node-35.domain.tld_es-01
notification-2018.10.28 1 r STARTED 4820 5.3mb 10.20x.6.14 node-25.domain.tld_es-01
notification-2018.10.28 1 r STARTED 4820 5.3mb 10.20x.6.7 node-26.domain.tld_es-01
notification-2018.10.28 1 p STARTED 4820 5.3mb 10.20x.6.20 node-35.domain.tld_es-01
notification-2018.10.28 2 r STARTED 4812 5.3mb 10.20x.6.14 node-25.domain.tld_es-01
notification-2018.10.28 2 r STARTED 4812 5.3mb 10.20x.6.7 node-26.domain.tld_es-01
notification-2018.10.28 2 p STARTED 4812 5.3mb 10.20x.6.20 node-35.domain.tld_es-01
notification-2018.10.27 2 p STARTED 4864 5.3mb 10.20x.6.14 node-25.domain.tld_es-01
notification-2018.10.27 2 r STARTED 4864 5.3mb 10.20x.6.7 node-26.domain.tld_es-01
notification-2018.10.27 2 r STARTED 4864 5.3mb 10.20x.6.20 node-35.domain.tld_es-01
notification-2018.10.27 0 r STARTED 4796 5.2mb 10.20x.6.14 node-25.domain.tld_es-01
notification-2018.10.27 0 r STARTED 4796 5.2mb 10.20x.6.7 node-26.domain.tld_es-01
notification-2018.10.27 0 p STARTED 4796 5.2mb 10.20x.6.20 node-35.domain.tld_es-01
notification-2018.10.27 3 r STARTED 4952 5.4mb 10.20x.6.14 node-25.domain.tld_es-01
notification-2018.10.27 3 r STARTED 4952 5.4mb 10.20x.6.7 node-26.domain.tld_es-01
notification-2018.10.27 3 p STARTED 4952 5.4mb 10.20x.6.20 node-35.domain.tld_es-01
notification-2018.10.27 1 p STARTED 4830 5.2mb 10.20x.6.14 node-25.domain.tld_es-01
notification-2018.10.27 1 r STARTED 4830 5.2mb 10.20x.6.7 node-26.domain.tld_es-01
notification-2018.10.27 1 r STARTED 4830 5.2mb 10.20x.6.20 node-35.domain.tld_es-01
notification-2018.10.27 4 r STARTED 4851 5.3mb 10.20x.6.14 node-25.domain.tld_es-01
notification-2018.10.27 4 r STARTED 4851 5.3mb 10.20x.6.7 node-26.domain.tld_es-01
notification-2018.10.27 4 p STARTED 4851 5.3mb 10.20x.6.20 node-35.domain.tld_es-01
log-2018.06.20 4 p STARTED 3214109 1gb 10.20x.6.14 node-25.domain.tld_es-01
log-2018.06.20 4 r STARTED 3214109 1gb 10.20x.6.7 node-26.domain.tld_es-01
log-2018.06.20 4 r STARTED 3214109 1gb 10.20x.6.20 node-35.domain.tld_es-01
log-2018.06.20 0 r STARTED 3214241 1016.5mb 10.20x.6.14 node-25.domain.tld_es-01
log-2018.06.20 0 r STARTED 3214241 1016.5mb 10.20x.6.7 node-26.domain.tld_es-01
log-2018.06.20 0 p STARTED 3214241 1016.5mb 10.20x.6.20 node-35.domain.tld_es-01
log-2018.06.20 3 p STARTED 3212684 1014.9mb 10.20x.6.14 node-25.domain.tld_es-01
log-2018.06.20 3 r STARTED 3212684 1014.9mb 10.20x.6.7 node-26.domain.tld_es-01
log-2018.06.20 3 r STARTED 3212684 1014.9mb 10.20x.6.20 node-35.domain.tld_es-01
log-2018.06.20 1 p STARTED 3215750 1gb 10.20x.6.14 node-25.domain.tld_es-01
log-2018.06.20 1 r STARTED 3215750 1gb 10.20x.6.7 node-26.domain.tld_es-01
log-2018.06.20 1 r STARTED 3215750 1gb 10.20x.6.20 node-35.domain.tld_es-01
log-2018.06.20 2 r STARTED 3212429 1014.2mb 10.20x.6.14 node-25.domain.tld_es-01
log-2018.06.20 2 r STARTED 3212429 1014.2mb 10.20x.6.7 node-26.domain.tld_es-01
log-2018.06.20 2 p STARTED 3212429 1014.2mb 10.20x.6.20 node-35.domain.tld_es-01
log-2018.06.21 2 p STARTED 3266398 1gb 10.20x.6.20 node-35.domain.tld_es-01
log-2018.06.21 2 r UNASSIGNED
log-2018.06.21 2 r UNASSIGNED
log-2018.06.21 0 p STARTED 3264364 1gb 10.20x.6.20 node-35.domain.tld_es-01
log-2018.06.21 0 r UNASSIGNED
log-2018.06.21 0 r UNASSIGNED
log-2018.06.21 3 p STARTED 3267448 1gb 10.20x.6.14 node-25.domain.tld_es-01
log-2018.06.21 3 r UNASSIGNED
log-2018.06.21 3 r UNASSIGNED
log-2018.06.21 1 p STARTED 3267192 1gb 10.20x.6.20 node-35.domain.tld_es-01
log-2018.06.21 1 r UNASSIGNED
log-2018.06.21 1 r UNASSIGNED
log-2018.06.21 4 p STARTED 3266666 1gb 10.20x.6.20 node-35.domain.tld_es-01
log-2018.06.21 4 r UNASSIGNED
log-2018.06.21 4 r UNASSIGNED
查看未分配的分片
root@node-25:~# curl -s “http://10.20x.6.4:9200/_cat/shards“ |grep UNASSIGNED
notification-2018.11.29 4 p UNASSIGNED
notification-2018.11.29 4 r UNASSIGNED
notification-2018.11.29 4 r UNASSIGNED
notification-2018.11.29 0 p UNASSIGNED
notification-2018.11.29 0 r UNASSIGNED
notification-2018.11.29 0 r UNASSIGNED
notification-2018.11.29 3 p UNASSIGNED
notification-2018.11.29 3 r UNASSIGNED
notification-2018.11.29 3 r UNASSIGNED
notification-2018.11.29 1 p UNASSIGNED
notification-2018.11.29 1 r UNASSIGNED
notification-2018.11.29 1 r UNASSIGNED
notification-2018.11.29 2 p UNASSIGNED
notification-2018.11.29 2 r UNASSIGNED
notification-2018.11.29 2 r UNASSIGNED
查看节点标识
root@node-25:~# curl “http://10.20x.6.4:9200/_nodes/process?pretty“
{
“clustername” : “lma”,
“nodes” : {
“YbLjwxGxRrempMdCT1W8tg” : {
“name” : “node-25.domain.tld_es-01”,
“transport_address” : “inet[/10.20x.6.14:9300]”,
“host” : “node-25.domain.tld”,
“ip” : “10.20x.6.14”,
“version” : “1.7.4”,
“build” : “0d3159b”,
“http_address” : “inet[/10.20x.2.17:9200]”,
“attributes” : {
“master” : “true”
},
“process” : {
“refresh_interval_in_millis” : 1000,
“id” : 54121,
“max_file_descriptors” : 65535,
“mlockall” : true
}
},
“uncgrQ08Q1iBzB8QBVOHuQ” : {
“name” : “node-26.domain.tld_es-01”,
“transport_address” : “inet[/10.20x.6.7:9300]”,
“host” : “node-26.domain.tld”,
“ip” : “10.20x.6.7”,
“version” : “1.7.4”,
“build” : “0d3159b”,
“http_address” : “inet[/10.20x.2.4:9200]”,
“attributes” : {
“master” : “true”
},
“process” : {
“refresh_interval_in_millis” : 1000,
“id” : 37302,
“max_file_descriptors” : 65535,
“mlockall” : true
}
},
“-sNRRzaTAapyZthb62Lsw” : {
“name” : “node-35.domain.tld_es-01”,
“transport_address” : “inet[/10.20x.6.20:9300]”,
“host” : “node-35.domain.tld”,
“ip” : “10.20x.6.20”,
“version” : “1.7.4”,
“build” : “0d3159b”,
“http_address” : “inet[/10.20x.2.5:9200]”,
“attributes” : {
“master” : “true”
},
“process” : {
“refresh_interval_in_millis” : 1000,
“id” : 194237,
“max_file_descriptors” : 65535,
“mlockall” : true
}
}
}
}
重新分配分片
curl -XPOST ‘http://10.20x.6.4:9200/_cluster/reroute‘ -d ‘{
“commands” : [ {
“allocate” : {
“index” : “notification-2018.11.29”,
“shard” : 4,
“node” : “YbLjwxGxRrempMdCT1W8tg”,
“allow_primary” : true
}
}
]
}’
查看集群状态
root@node-25:~# curl http://10.20x.6.4:9200/_cluster/health\?pretty
{
“cluster_name” : “lma”,
“status” : “green”,
“timed_out” : false,
“number_of_nodes” : 3,
“number_of_data_nodes” : 3,
“active_primary_shards” : 1905,
“active_shards” : 5715,
“relocating_shards” : 0,
“initializing_shards” : 0,
“unassigned_shards” : 0,
“delayed_unassigned_shards” : 0,
“number_of_pending_tasks” : 0,
“number_of_in_flight_fetch” : 0
}
脚本参考
!/bin/bash
for index in $(curl -s ‘http://localhost:9200/_cat/shards‘ | grep UNASSIGNED | awk ‘{print $1}’ | sort | uniq); do
for shard in $(curl -s ‘http://localhost:9200/_cat/shards‘ | grep UNASSIGNED | grep $index | awk ‘{print $2}’ | sort | uniq); do
echo $index $shard
curl -XPOST 'localhost:9200/_cluster/reroute' -d "{<br /> 'commands' : [ {<br /> 'allocate' : {<br /> 'index' : $index,<br /> 'shard' : $shard,<br /> 'node' : 'Master',<br /> 'allow_primary' : true<br /> }<br /> }<br /> ]<br /> }"
sleep 5<br /> done<br />done