美文网首页ELK文集手把手教你搭建ELK日志分析系统
搭建ELK日志分析系统(二)-elasticsearch-hea

搭建ELK日志分析系统(二)-elasticsearch-hea

作者: IM魂影 | 来源:发表于2017-09-04 20:53 被阅读72次

    前言

    elasticsearch-head是一个界面化的集群管理工具,数据可视化、增删改查工具。它是完全由HTML5编写的独立网页程序,你可以通过插件把它集成到es。

    安装elasticsearch-head

    elasticsearch5.0之后,head插件换成了采用grunt服务方式启动,需要用npm方式打包安装,所以需先安装nodejs

    直接下载Linux Binaries格式的NodeJs安装包(安装方便)

    wget https://nodejs.org/dist/v6.11.2/node-v6.11.2-linux-x64.tar.gz
    

    解压到指定文件夹

    tar -xzvf node-v6.11.2-linux-x64.tar.gz -C /usr/local/
    

    重命名

    mv /usr/local/node-v6.11.2-linux-x64 /usr/local/node-v6.11.2
    

    配置环境变量

    vi /etc/profile
    export NODE_HOME=/usr/local/node-v6.11.2
    export PATH=$NODE_HOME/bin:$PATH
    export NODE_PATH=$NODE_HOME/lib/node_modules
    

    使环境变量生效

    source /etc/profile
    

    查看nodejs是否生效

    node -v
    npm -v
    

    安装elasticsearch-head使用到git工具

    yum install git 
    

    安装grunt

    npm install -g grunt-cli
    ln -s /usr/local/node-v6.11.2/lib/node_modules/grunt-cli/bin/grunt /usr/bin/grunt
    

    下载获取elasticsearch-head插件

    cd /usr/local/elasticsearch-5.5.2/
    git clone git://github.com/mobz/elasticsearch-head.git
    #结果git下载生成这个文件夹
    /usr/local/elasticsearch-5.5.2/elasticsearch-head
    

    安装插件,建议使用cnpm安装,使用npm安装过程中下载依赖时出现失败(因为墙的问题)
    所以我们先安装国内镜像cnpm

    npm install -g cnpm --registry=https://registry.npm.taobao.org
    

    从此用cnpm代替npm

    安装elasticsearch-head

    #进入刚才下载目录
    cd /usr/local/elasticsearch-5.5.2/elasticsearch-head
    #执行cnpm安装
    cnpm install
    

    安装成功后,修改配置

    vi Gruntfile.js
    connect: {
         server: {
             options: {
             hostname: "0.0.0.0",
             port: 9100,
             base: '.',
             keepalive: true
             }
         }
    }
    

    修改_site/app.js配置

    vi _site/app.js
    #搜索http://localhost:9200
    #修改为
    
    this.base_uri = this.config.base_uri || this.prefs.get("app-base_uri") || "http://192.168.1.138:9200";
    

    启动服务

    grunt server
    #如果启动成功,则可以直接使用后台运行,命令行可继续输入(但是如果想退出,则需要自己kill进程)
    grunt server &
    

    启动elasticsearch

    #切换用户
    su elk
    ./bin/elasticsearch
    #elasticsearch也有后台运行模式,只需后面添加-d参数
    ./bin/elasticsearch -d
    

    启动前确保elasticsearch配置已修改为外部可访问(参考上一节)

    vi ./config/elasticsearch.yml
    
    network.host: 192.168.1.138 
    http.port: 9200
    
    # 增加新的参数,这样head插件可以访问es
    http.cors.enabled: true
    http.cors.allow-origin: "*"
    

    最终运行效果,注意集群健康状态,如果链接不成功,请检查上一节相关设置

    安全问题

    因为该插件可以对数据进行,增删改查,故生产环境尽量不要使用。

    相关文章

      网友评论

        本文标题:搭建ELK日志分析系统(二)-elasticsearch-hea

        本文链接:https://www.haomeiwen.com/subject/roqyjxtx.html