ES常用维护操作
如果你还搞不清ES是个啥,请参阅ES基本名词解释
目录
[显示]如何启停ES
如何安全的停止es
切记:任何情况下不要轻易使用kill -9关闭某个进程,-9参数会使操作系统强行关闭制定进程,其效果相当于直接拔掉正在运行的服务器的电源。
如何获取ES的版本信息
使用浏览器获取ES版本信息
通过浏览器获取ES的版本信息,确保浏览器可以访问ES所在服务器的9200端口。
http://172.16.1.163:9200/?pretty
将在浏览器中显示如下信息,下列实例第6行内容为版本号信息, "number" : "1.7.0"。
1 { 2 "status" : 200, 3 "name" : "Yellow Claw", 4 "cluster_name" : "fusionskye", 5 "version" : { 6 "number" : "1.7.0", 7 "build_hash" : "929b9739cae115e73c346cb5f9a6f24ba735a743", 8 "build_timestamp" : "2015-07-16T14:31:07Z", 9 "build_snapshot" : false, 10 "lucene_version" : "4.10.4" 11 }, 12 "tagline" : "You Know, for Search" 13 }
使用命令行获取ES版本信息
通过ES服务器的命令行终端,获取ES的版本信息。
[root@EzsDemo ~]# curl 'http://127.0.0.1:9200'
1 { 2 "status" : 200, 3 "name" : "Yellow Claw", 4 "cluster_name" : "fusionskye", 5 "version" : { 6 "number" : "1.7.0", 7 "build_hash" : "929b9739cae115e73c346cb5f9a6f24ba735a743", 8 "build_timestamp" : "2015-07-16T14:31:07Z", 9 "build_snapshot" : false, 10 "lucene_version" : "4.10.4" 11 }, 12 "tagline" : "You Know, for Search" 13 }
如何删除ES的索引
使用head插件删除ES的索引
- 启动ES(如果进程已经正常运行,则不需要该步骤);
- 进入ES的head,确认当前ES有哪些索引文件;
- 确认【需要删除的索引】当前并无写入操作,如果需要删除当天的索引,请务必先关闭Collector;
- 使用head删除历史数据;
通过命令行删除ES的索引
如果你所处的环境恰巧没有部署head插件,还可以通过命令行清除ES的索引。
- 启动ES;
- 进入ES的索引目录,确认当前ES有哪些索引文件;
- 确认【需要删除的索引】当前并无写入操作,如果需要删除当天的索引,请务必先关闭Collector;
- 使用命令行删除历史数据;
[root@EZsonar-manager indices]# curl 'localhost:9200/_cat/indices?v'
1 health status index pri rep docs.count docs.deleted store.size pri.store.size 2 green open .marvel-kibana 3 0 2 0 17.5kb 17.5kb 3 green open ezsonar_2016-08-22 3 0 19245738 0 8.6gb 8.6gb 4 green open ezsonarnpm_2016-08-22 3 0 0 0 432b 432b 5 green open ezsonarnpm_2016-08-21 3 0 28079698 0 12.4gb 12.4gb 6 green open ezsonar_2016-08-21 3 0 28079698 0 12.4gb 12.4gb 7 green open heatmap_summary_2016-08 3 0 5035666 0 655.3mb 655.3mb 8 green open heatmap_summary_2016-06 3 0 625815 0 81.6mb 81.6mb 9 green open analyzier_2016-08 3 0 4385286 0 1.6gb 1.6gb
[root@EZsonar-manager indices]# curl -XDELETE "http://localhost:9200/ezsonarnpm_2016-08-21"
{"acknowledged":true}
为何删除正在写入的索引需要先关闭Collector
如果在Collector进程尚未关闭的情况下删除索引,Collector收到的后续数据仍然会往ES里写,但是这个时候索引文件和MAPPING已经不存在了。ES会按照自身的配置生成索引和MAPPING,此时Shard和Replicas的配置都会按照ES的配置生成,MAPPING也会按照ES的默认配置生成,这会导致当天索引及Mapping出现错误。
如何重启ES集群中的某个节点
如果ES集群中已经存放了大量的数据,直接重启ES集群中的某个节点可能会将会涉及到很多shard的relocation,重启的过程会很慢,而且会给系统带来很大的压力,直接的影响是导致交易无法及时写入ES,导致数据积压,界面数据展示出现延迟。
解决办法,先把cluster.routing.allocation.disable_allocation设置为true,再重启对应节点,再把先把cluster.routing.allocation.disable_allocation设置为false。
- 确认当前ES集群的cluster.routing.allocation.disable_allocation状态,浏览器中输入:http://192.168.1.176:9200/_cluster/settings ,IP为ES节点;
- 关闭allocation功能,在ES所在的服务器输入命令,将cluster.routing.allocation.disable_allocation设置为true;
#临时将cluster.routing.allocation.disable_allocation设置为true,重启整个Cluster以后失效; curl -XPUT "http://192.168.1.176:9200/_cluster/settings" -d '{ "transient" : { "cluster.routing.allocation.disable_allocation" : true } }' #永久将cluster.routing.allocation.disable_allocation设置为true,重启整个Cluster以后仍然有效; curl -XPUT "http://192.168.1.176:9200/_cluster/settings" -d '{ "persistent" : { "cluster.routing.allocation.disable_allocation" : true } }'
- 重启ES节点;
- 在ES所在的服务器输入命令,将cluster.routing.allocation.disable_allocation设置为false;
#临时将cluster.routing.allocation.disable_allocation设置为false,重启整个Cluster以后失效; curl -XPUT "http://192.168.1.176:9200/_cluster/settings" -d '{ "transient" : { "cluster.routing.allocation.disable_allocation" : false} }' #永久将cluster.routing.allocation.disable_allocation设置为false,重启整个Cluster以后仍然有效; curl -XPUT "http://192.168.1.176:9200/_cluster/settings" -d '{ "persistent" : { "cluster.routing.allocation.disable_allocation" : false} }'
重启ES节点后,分片一直处于灰色unassigned状态怎么办?
需要注意的是,如果disable_allocation设为True,某个ES节点重启之后,该节点上的所有分片会一直处于灰色unassigned状态,另外新建索引的时候,replica不会分配到node上,处于灰色unassigned状态。需要手工进行分配,或者将cluster.routing.allocation.disable_allocation暂时设置为false。