今天的分享是关于如何使用Shell 脚本轻松搞定ES 的信息查询,通过不同的参数传入来获取相应的信息反馈。 相应的代码如下: #!/bin/bash username="admin" password="test123" ip=$2 if [[ $1 == "" ]] #判断参数是否为空 then echo "需要输入参数" echo "$0 [ health | node | nodeprocess | disk | index | shards | status | task | fielddata | setting | backup ] hostip" exit 0 fi case $1 in #匹配输出的参数 health) echo "查看es集群状态" curl -XGET -u${username}:${password} "http://${ip}:9200/_cluster/health?pretty" ;; node) echo "查看节点信息" curl -XGET -u${username}:${password} "http://${ip}:9200/_cat/nodes?v" ;; nodeprocess) echo "查看节点进程信息" curl -XGET -u${username}:${password} "http://${ip}:9200/_cat/nodes/process?pretty" ;; disk) echo "查看各节点磁盘使用情况" curl -XGET -u${username}:${password} "http://${ip}:9200/_cat/allocation?v" ;; index) echo "查看索引信息" curl -XGET -u${username}:${password} "http://${ip}:9200/_cat/indices?v" ;; shards) echo "查看分片信息" curl -XGET -u${username}:${password} "http://${ip}:9200/_cat/shards?v" ;; status) echo "查看状态信息" curl -XGET -u${username}:${password} "http://${ip}:9200/_cluster/health?pretty" ;; task) echo "查看执行队列" curl -XGET -u${username}:${password} "http://${ip}:9200/_cat/pending_tasks?v" ;; fielddata) echo "查看数据结构" curl -XGET -u${username}:${password} "http://${ip}:9200/_cat/fielddata?v" ;; setting) echo "查看配置信息" curl -XGET -u${username}:${password} "http://${ip}:9200/_cluster/settings?pretty" ;; backup) echo "查看备份信息" curl -XGET -u${username}:${password} "http://${ip}:9200/_snapshot?pretty" ;; *) echo "参数匹配不对,请参照如下输出:" echo "$0 [ node | disk | index | shard | status | task | fielddata | setting | backup ] hostip" exit 0 ;; esac exit 0 以上代码内容需耐心每一行一行的去分析理解才能对今天分享的内容有更深入的理解,如果对Shell 操作不熟悉的童鞋,可以参考之前分享的《Shell编程核心技术》系列文章。 Shell编程系列:核心技术《一》 Shell编程系列:核心技术《二》 Shell编程系列:核心技术《三》 Shell编程系列:核心技术《四》