zoukankan      html  css  js  c++  java
  • 安装elasticsearch插件之head

        可以实现对elasticsearch集群的状态监控与管理配置等功能。

        git地址:https://github.com/mobz/elasticsearch-head

    二 安装elasticsearch-head

    1.1.1 安装

    yum install -y npm
    git clone git://github.com/mobz/elasticsearch-head.git
    cd elasticsearch-head
    npm install
    npm install grunt -save
    ll node_modules/grunt 
    npm run start &

    1.1.2 浏览器访问测试

    1.1.3 elasticsearch开启跨域访问支持

      追加在文件尾部(所有节点都要追加)

    [root@Centos-node5 elasticsearch-head]# vim /etc/elasticsearch/elasticsearch.yml
    http.cors.enabled: true
    http.cors.allow-origin: "*"

    1.1.4 elasticsearch-head连接Elasticsearch测试

    1.1.5 模拟查询查看分片

    1.1.6 查看分片信息状态 绿色为正常 

    三 脚本监控集群状态

    1.1.1 通过shell命令获取集群状态

      获取到的是一个json格式的返回值,那就可以通过python对其中的信息进行分析,例如对status进行分析,如果等于green(绿色)就是运行在正常,等于yellow(黄色)表示副本分片丢失,red(红色)表示主分片丢失

    [root@Centos-node5 elasticsearch-head]# curl –sXGET  http://192.168.10.141:9200/_cluster/health?pretty=true
    {
      "cluster_name" : "my_elk",
      "status" : "green",
      "timed_out" : false,
      "number_of_nodes" : 2,
      "number_of_data_nodes" : 2,
      "active_primary_shards" : 5,
      "active_shards" : 10,
      "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
    }

    1.1.2Python监控

        50为正常100为非正常

    [root@Centos-node5 ~]# cat els-cluster-monitor.py 
    #!/usr/bin/env python
    #coding:utf-8
    import smtplib
    from email.mime.text import MIMEText
    from email.utils import formataddr
    import subprocess
    body = ""
    false="false"
    obj = subprocess.Popen(("curl -sXGET http://192.168.10.141:9200/_cluster/health?pretty=true"),shell=True, stdout=subprocess.PIPE)
    data =  obj.stdout.read()
    data1 = eval(data)
    status = data1.get("status")
    if status == "green":
        print "50"
    else:
        print "100"
    
    [root@Centos-node5 ~]# python els-cluster-monitor.py 
    50

    作者:闫世成

    出处:http://cnblogs.com/yanshicheng

    联系:yans121@sina.com

    本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接。如有问题或建议,请联系上述邮箱,非常感谢。
  • 相关阅读:
    为什么图层1剪切蒙版到图层2,图层1不见了?
    制作放射状背景
    如何制作底纹(2)
    如何制作底纹?
    web网页按钮如何制作
    取得表中数据的insert语句
    Solr查询详解
    .NET开发过程中的全文索引使用技巧之Solr
    工作中常用的数据库操作脚本整理
    如何在Linux上编译c++文件
  • 原文地址:https://www.cnblogs.com/yanshicheng/p/9416807.html
Copyright © 2011-2022 走看看