zoukankan      html  css  js  c++  java
  • zabbix通过简单shell命令监控elasticsearch集群状态

    简单命令监控elasticsearch集群状态

    原理:
    使用curl命令模拟访问任意一个es节点可以反馈的集群状态,集群的状态需要为green
    curl -sXGET http://serverip:9200/_cluster/health/?pretty

    {
      "cluster_name" : "yunva-es",
      "status" : "green",
      "timed_out" : false,
      "number_of_nodes" : 7,
      "number_of_data_nodes" : 6,
      "active_primary_shards" : 66,
      "active_shards" : 132,
      "relocating_shards" : 0,
      "initializing_shards" : 0,
      "unassigned_shards" : 0,
      "delayed_unassigned_shards" : 0,
      "number_of_pending_tasks" : 0,
      "number_of_in_flight_fetch" : 0,
      "task_max_waiting_in_queue_millis" : 0,
      "active_shards_percent_as_number" : 100.0
    }

    前端使用了nginx验证,需要模拟登陆
    curl模拟用户登录命令格式:
    curl -u username:password -sXGET http://serverip:9200/_cluster/health/?pretty | grep "status"|awk -F '[ "]+' '{print $4}'

    1.修改客户端zabbix配置:
    vim /etc/zabbix/zabbix_agentd.conf

    UserParameter=es_status,curl -u elkadmin:elkpass -sXGET http://serverip/_cluster/health/?pretty | grep "status"|awk -F '[ "]+' '{print $4}'|grep -c 'green'

    重启zabbix-agent使配置生效
    service zabbix-agent restart

    在zabbix-server端测试
    zabbix_get -s ip -p 10050 -k es_status

    2.在zabbix的web页面添加对应的监控:

    添加监控项item

    Confuguration --> Hosts --> 找到对应的主机,点开 Items --> Create item



    创建触发器:
    Name
    es_status_check
    es_cluster_status is not green

    3.针对es集群中的每个节点做进程监控,如果进程挂了自动重启

    配置监控进程item


    配置触发器


    配置action,看参考 

    zabbix系列(九)zabbix3.0实现自动触发zabbix-agent端shell脚本任务

    http://blog.csdn.net/reblue520/article/details/52315154


    触发脚本:

    /usr/local/zabbix-agent/scripts/start_es.sh
    
    #!/bin/bash
    # if elasticsearch exists kill it
    source /etc/profile
    count_es=`ps -ef|grep elasticsearch|grep -v grep|wc -l`
    if [ $count_es -gt 1 ];then
        ps -ef|grep elasticsearch|grep -v grep|/bin/kill `awk '{print $2}'`
    fi
    # start it
    
    su yunva -c "cd /data/elasticsearch-5.0.1/bin && /bin/bash elasticsearch &"


    执行:
    sudo /bin/bash /usr/local/zabbix-agent/scripts/start_es.sh
    报错:
    which: no java in (/sbin:/bin:/usr/sbin:/usr/bin)
    Could not find any executable java binary. Please install java in your PATH or set JAVA_HOME

    解决办法:
    在脚本中添加
    source /etc/profile

    以root用户运行elasticsearch

    报错:
    can not run elasticsearch as root

    网上的方法,针对elasticsearch5.1不起作用
    解决方法1:
    在执行elasticSearch时加上参数-Des.insecure.allow.root=true,完整命令如下

    ./elasticsearch -Des.insecure.allow.root=true  
    解决办法2:
    用vi打开elasicsearch执行文件,在变量ES_JAVA_OPTS使用前添加以下命令

    ES_JAVA_OPTS="-Des.insecure.allow.root=true"  

    解决办法:
    su yunva -c "cd /data/elasticsearch-5.0.1/bin && /bin/bash elasticsearch &"

    自动拉起kibana服务的脚本:
    cat /usr/local/zabbix/scripts/restart_kibana.sh
    #!/bin/bash
    # if kibana exists kill it

    count_kibana=`ps -ef|grep kibana|grep -v grep|wc -l`
    if [ $count_kibana -eq 1 ];then
        ps -ef|grep kibana|grep -v grep|/bin/kill `awk '{print $2}'`
    fi

    # start it


    排错思路:

    针对每台es的节点进行检查,发现有无法访问的,问题就出在这里了

    # curl http://10.27.1.10:9200/
    curl: (56) Recv failure: Connection reset by peer



  • 相关阅读:
    python测试开发django-1.开始hello world!
    python基础--杂项
    Python基础----函数
    python介绍
    公共Webservice
    divmod(a,b)函数
    模块知识
    第三周作业 修改配置文件
    rsync在windows和linux同步数据的配置过程
    docker学习笔记
  • 原文地址:https://www.cnblogs.com/reblue520/p/6784503.html
Copyright © 2011-2022 走看看