当想在linux的命令行中查看elasticsearch的状态时,可以用es2unix这个工具,插件地址: https://github.com/elasticsearch/es2unix。它是elasticsearch官方推出的,可以通过命令来查看es的各种状态,安装方法
curl -s download.elasticsearch.org/es2unix/es > /bin/es
chmod +x /bin/es
这个是作者编译的,如果你运行时报Unrecognized VM option 'TieredStopAtLevel=1',则是因为你使用的jdk是比较旧的1.6版本的,不支持TieredStopAtLevel=1这个jvm参数,解决办法有两个,一个是换最新的jdk,一个是下我编译好的工具,我重新编译时把这个参数去掉了。
用法
这个工具默认是使用http://localhost:9200这个elasticsearch的地址,你可以在命令中通过u参数指定其它地址,例如 %es version -u http://192.168.0.1:9200
查看es版本
% es version
es 1.0.0
elasticsearch 0.21.0.Beta1
查看健康状态
% es health -v
cluster status nodes data pri shards relo init unassign
kluster green 2 2 3 6 0 0 0
统计索引
% es count
2,319,799
% es count elasticsearch
3 "q=elasticsearch"
% es count "john deacon"
225,839 "q=john deacon"
% es count "\"saved by the bell\""
220 "q="saved by the bell""
搜索
% es search -v "george costanza" title
score index type id title
5.78647 wiki page 660183 George Costansa
5.78647 wiki page 273868 George Constanza
5.63803 wiki page 865781 Vandelay Industries
4.69835 wiki page 932333 Art Vandelay
4.69835 wiki page 2147975 Can't Stand Ya
4.67351 wiki page 2486208 Art vandelay
4.07630 wiki page 2147959 Costanza
3.23200 wiki page 2147971 The Costanza family
3.21007 wiki page 2147972 Costanza family
2.94863 wiki page 4946953 Santa costanza
Total: 118186
查询master
% es master
J-erllamTOiW5WoGVUd04A 127.0.0.1 Slade, Frederick
查询索引状态
% es indices -v
status name pri rep docs size
green _river 0 1 4 8068
green wiki 1 1 1104894 13805525784
% es indices | grep \^red
red bb 5 0
red test 4 1 218b 218 0
red enron 5 0
red uno 1 0
查看节点信息
% es nodes
Uv1Iy8FvR0y6_RzPXKBolg 127.0.0.1 9201 127.0.0.1 9300 d Cannonball I
J-erllamTOiW5WoGVUd04A 127.0.0.1 9200 127.0.0.1 9301 * d Slade, Frederick
j27iagsmQQaeIpl6yU6mCg 127.0.0.1 9203 127.0.0.1 9303 - c Georgianna Castleberry
T1aFDU2BSUm748gYxjEN9w 127.0.0.1 9202 127.0.0.1 9302 d Living Tribunal
查看节点的变化状态日志
% es lifecycle /tmp/es-*/logs/elasticsearch.log
2013-02-08 13:47:15,516 Lurking Unknown INIT 0.21.0.Beta1-SNAPSHOT
2013-02-08 13:47:20,413 Lurking Unknown MASTER Lurking Unknown
2013-02-08 13:47:20,467 Lurking Unknown START
2013-02-08 13:47:36,319 Cameron Hodge INIT 0.21.0.Beta1-SNAPSHOT
2013-02-08 13:47:41,211 Lurking Unknown ADD Cameron Hodge
2013-02-08 13:47:41,223 Cameron Hodge MASTER Lurking Unknown
2013-02-08 13:47:41,278 Cameron Hodge START
2013-02-08 13:47:59,426 Armageddon INIT 0.21.0.Beta1-SNAPSHOT
2013-02-08 13:48:04,279 Lurking Unknown ADD Armageddon
2013-02-08 13:48:04,280 Cameron Hodge ADD Armageddon
2013-02-08 13:48:04,287 Armageddon MASTER Lurking Unknown
2013-02-08 13:48:04,340 Armageddon START
2013-02-08 13:48:30,333 Lurking Unknown REMOVE Armageddon
2013-02-08 13:48:30,339 Cameron Hodge REMOVE Armageddon
2013-02-08 13:48:30,362 Armageddon STOP
查看jvm heap占用
% es heap | sort -rnk6
XO6c2A1D 23.9mb 25138608 123.7mb 129761280 19.4% 127.0.0.1 Junkpile
uVP8g9_l 94.6mb 99257976 990.7mb 1038876672 9.6% 127.0.0.1 Hammond, Jim
pjbeg_k8 76.9mb 80730208 990.7mb 1038876672 7.8% 127.0.0.1 Scarlet Centurion
可以通过下面脚本来实时监控
% while true; do es heap | sort -rnk6 | head -1; sleep 60; done
XO6c2A1D 57.3mb 60157200 123.7mb 129761280 46.4% 127.0.0.1 Junkpile
XO6c2A1D 54.7mb 57405904 123.7mb 129761280 44.2% 127.0.0.1 Junkpile
XO6c2A1D 62.7mb 65834752 123.7mb 129761280 50.7% 127.0.0.1 Junkpile
XO6c2A1D 56.9mb 59743504 123.7mb 129761280 46.0% 127.0.0.1 Junkpile
XO6c2A1D 52.1mb 54676216 123.7mb 129761280 42.1% 127.0.0.1 Junkpile
XO6c2A1D 37.1mb 38971744 123.7mb 129761280 30.0% 127.0.0.1 Junkpile
XO6c2A1D 52mb 54528424 123.7mb 129761280 42.0% 127.0.0.1 Junkpile
XO6c2A1D 46.5mb 48787064 123.7mb 129761280 37.6% 127.0.0.1 Junkpile
查看分片状态
% es shards
wiki 0 p STARTED 1160290 7.2gb 7776371641 127.0.0.1 Feline
wiki 0 r STARTED 1160290 7.2gb 7776371602 127.0.0.1 Jenkins, Abner
wiki 1 p RELOCATING 1159509 7.5gb 8116295811 127.0.0.1 Feline -> 127.0.0.1 Amphibius
wiki 1 r STARTED 1159509 7.5gb 8116295811 127.0.0.1 Jenkins, Abner
标签:127.0,mb,0.1,08,linux,elasticsearch,2013,es2unix,es
From: https://blog.51cto.com/u_6186189/6458437