操作系统:
https://s1.运维网.com/images/blog/201903/12/6eddf25876437dac131f021a0672359b.png
https://s1.运维网.com/images/blog/201903/12/56b03fe7f0fb5775c2b9733d06d585d6.png
es的安装:https://www.elastic.co/guide/en/elasticsearch/reference/current/deb.html
要紧的就这2步:
wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-6.6.0.deb
sudo dpkg -i elasticsearch-6.6.0.deb
sudo /bin/systemctl daemon-reload
sudo /bin/systemctl enable elasticsearch.service
sudo /bin/systemctl start elasticsearch.service
如果启动失败说找不到JAVA_HOME环境变量,但是在命令行里敲java又有,则
在 /etc/default/elasticsearch里添加如下行
`JAVA_HOME=/usr/local/jre1.8.0_191`
2个节点:
节点1的IP: 192.168.11.145
节点2的IP: 192.168.11.148
更改2个节点的配置文件 /etc/elasticsearch/elasticsearch.yml
参照这个链接配置 https://dzone.com/articles/elasticsearch-tutorial-creating-an-elasticsearch-c
我的2个配置
打开 192.168.11.145:5601查看
在DevTool里输入GET /_cluster/state?pretty查看,可以看到有2个节点了
https://s1.运维网.com/images/blog/201903/12/115ba3aaecfff8ad2306e680414463ac.png
在Monitoring也可以看到2个节点
https://s1.运维网.com/images/blog/201903/12/7b8598fb9191e0aa02ed3a27fe3f588c.png
创建一个index看看
PUT /index-sgd
{
"settings" : {
"index" : {
"number_of_shards" : 2,
"number_of_replicas" : 1
}
}
}
发现健康为yellow
https://s1.运维网.com/images/blog/201903/12/3a8ab7d8867756d71d376a5cb3b69492.png
查看index-sgd的stats,我是2个主分片,2个副本共4个分片,显示有2个分片successful
https://s1.运维网.com/images/blog/201903/12/b791364b7a481b27de6e5a05fb0c9d60.png
Monitoring的这里也可以看到index-sgd有2个分片Unassigned
https://s1.运维网.com/images/blog/201903/12/c0439ac74859413041079de5316a89c1.png
应该是因为192.168.11.148这个node的node.data设置为了false的原因,把这个节点的node.data设置为true
重启节点再通过kibana查看,健康状态就为green了
https://s1.运维网.com/images/blog/201903/12/996d5f55611ae2f15ec0d32f94a280da.png
PUT /index-sgd
{
"settings" : {
"index" : {
"number_of_shards" : 2,
"number_of_replicas" : 2
}
}
}
如果把number_of_shards和number_of_replicas改成2,2,健康状态怎么都是yellow了
{
"_shards": {
"total": 6,
"successful": 4,
"failed": 0
},
改成3,1 健康状态为green
{
"_shards": {
"total": 6,
"successful": 6,
"failed": 0
},
改成3,2 健康状态为yellow
{
"_shards": {
"total": 9,
"successful": 6,
"failed": 0
},
改成3,3, 健康状态为yellow
{
"_shards": {
"total": 12,
"successful": 6,
"failed": 0
},
改成4,1,green
{
"_shards": {
"total": 8,
"successful": 8,
"failed": 0
},
改成4,2,yellow
{
"_shards": {
"total": 12,
"successful": 8,
"failed": 0
},
改成100,1,green
{
"_shards": {
"total": 200,
"successful": 200,
"failed": 0
},
改成1,2,yellow
{
"_shards": {
"total": 3,
"successful": 2,
"failed": 0
},
健康状态取决于node和number_of_replicas
满足这个number_of_replicas |