zoukankan      html  css  js  c++  java
  • 通过xshell在linux上安装ELK6.6.1

    查看更多Linux开发环境配置,请点击《Linux开发环境配置大全》

    通过xshell在linux上安装ELK6.6.1

    Elasticsearch:是实时全文搜索和分析引擎,提供搜集、分析、存储数据三大功能;是一套开放REST和JAVA API

    等结构提供高效搜索功能,可扩展的分布式系统。它构建于Apache Lucene搜索引擎库之上。

    Logstash:是一个用来搜集、分析、过滤日志的工具。它支持几乎任何类型的日志,包括系统日志、错误日志和

    自定义应用程序日志。它可以从许多来源接收日志,这些来源包括 syslog、消息传递(例如 RabbitMQ)和JMX,

    它能够以多种方式输出数据,包括电子邮件、websockets和Elasticsearch。

    Kibana:是一个基于Web的图形界面,用于搜索、分析和可视化存储在 Elasticsearch指标中的日志数据。它利用

    Elasticsearch的REST接口来检索数据,不仅允许用户创建他们自己的数据的定制仪表板视图,还允许他们以特殊

    的方式查询和过滤数据。

    1)环境准备

    centOS7、JDK8、Elasticsearch-6.6.1、Logstash-6.6.1、Kibana-6.6.1

    jdk下载地址:https://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html

    elk下载地址:https://www.elastic.co/downloads

    2)安装Elasticsearch

    2.1 上传到服务器并且解压拷贝到指定文件夹

    tar -zxvf elasticsearch-6.6.1.tar.gz #解压
    mv elasticsearch-6.6.1 /usr/local/src/elasticsearch #拷贝

    2.2 创建用户和用户组

    ES不能使用root用户直接运行,必须使用普通用户运行

    groupadd elasticsearch #创建用户组
    useradd elasticsearch -g elasticsearch #创建用户
    chown -R elasticsearch:elasticsearch /usr/local/src/elasticsearch #分配权限
    chown -R elasticsearch:elasticsearch /usr/local/src/elasticsearch/config/elasticsearch.keystore

    2.3 创建数据文件和日志文件

    mkdir /data/es/{data,logs,work} -p #创建文件夹
    chown -R elasticsearch:elasticsearch /data/es #设置可读取权限

    2.4 修改elasticsearch配置文件

    # 设置集群名称
    cluster.name: es-cluster
    # 节点名称,每个节点不一样
    node.name: node-1
    # 监听的网络地址
    network.host: 192.168.227.130
    # 开启监听的端口
    http.port: 9200
    transport.tcp.port: 9300
    # 数据存储类型
    node.master: true
    node.data: true
    # 文件存储位置
    #path.conf: /usr/local/src/elasticsearch/conf
    path.data: /data/es/data
    #path.work: /data/es/work
    path.logs: /data/es/logs
    # 集群
    discovery.zen.ping.unicast.hosts: ["192.168.227.130:9300", "192.168.227.131:9300", "192.168.227.132:9300"]
    discovery.zen.minimum_master_nodes: 1
    # 跨域设置
    http.cors.enabled: true
    http.cors.allow-origin: "*"

    2.5 启动

    su elasticsearch #切换用户
    cd /usr/local/src/elasticsearch/bin #进入安装目录下的bin文件夹
    ./elasticsearch #启动ES(方式一,可看见启动日志)
    ./elasticsearch -d #后台启动ES(方式二,无日志输出)

    2.6 查看是否启动成功

    curl http://192.168.20.223:9200

    返回如下,则成功

    {
      "name" : "node-1",
      "cluster_name" : "es-cluster",
      "cluster_uuid" : "HrDKOIubQjCE7Fbp5ig6QA",
      "version" : {
        "number" : "6.6.1",
        "build_flavor" : "default",
        "build_type" : "tar",
        "build_hash" : "1fd8f69",
        "build_date" : "2019-02-13T17:10:04.160291Z",
        "build_snapshot" : false,
        "lucene_version" : "7.6.0",
        "minimum_wire_compatibility_version" : "5.6.0",
        "minimum_index_compatibility_version" : "5.0.0"
      },
      "tagline" : "You Know, for Search"
    }

    2.7 启动报错

    2.7.1 运行elasticsearch需要vm.max_map_count至少需要262144内存

    max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]

    解决办法:

    切换到root用户修改配置sysctl.conf

    su root
    vi /etc/sysctl.conf 

    添加下面配置

    vm.max_map_count=655360

    并执行命令

    sysctl -p

    然后,esc+(shift+z+z)退出,重新启动elasticsearch

    2.7.2 进程不够用

    max file descriptors [4096] for elasticsearch process is too low, increase to at least [65536]

    解决办法:

    切换到root用户修改配置/etc/security/limits.conf

    su root
    vi /etc/security/limits.conf

    在最后添加参数

    * soft nofile 65536
    * hard nofile 131072

    3)安装Head插件

    3.1 前期准备

    由于head插件本质上还是一个nodejs的工程,因此需要安装node,使用npm来安装依赖的包;如果未安装git,

    则先安装git工具。

    3.2 下载安装

    git clone https://github.com/mobz/elasticsearch-head.git #github上下载

    3.3 安装grunt

    cd elasticsearch-head
    npm install -g grunt --registry=https://registry.npm.taobao.org

    查看grunt版本

    grunt -version

    3.4 安装插件

    npm install

    在elasticsearch-head目录下node_modules/grunt下如果没有grunt二进制程序,需要执行:

    npm install grunt --save

    3.5 修改配置

    添加hostname,打开elasticsearch-head下Gruntfile.js文件:

    connect: {
                server: {
                    options: {
                        hostname:'192.168.20.223',
                        port: 9100,
                        base: '.',
                        keepalive: true
                    }
                }
            }

    设置默认连接IP为192.168.20.223(本机IP),打开_site下的app.js:

    init: function(parent) {
                this._super();
                this.prefs = services.Preferences.instance();
                this.base_uri = this.config.base_uri || this.prefs.get("app-base_uri") || "http://192.168.20.223:9200";
                if( this.base_uri.charAt( this.base_uri.length - 1 ) !== "/" ) {
                    // XHR request fails if the URL is not ending with a "/"
                    this.base_uri += "/";
                }

    3.6 ES设置允许跨域

    修改elasticsearch.yml文件加入以下内容:

    # 是否支持跨域
    http.cors.enabled: true
    # *表示支持所有域名
    http.cors.allow-origin: "*"

    3.7 启动可视化界面

    启动head

    cd elasticsearch-head
    grunt server
    grunt server &  #加&设置为后台启动,不加ctrl+c退出时则关闭

    另一种启动方式

    cd elasticsearch-head
    npm run start

    查看是否部署成功

    http://192.168.20.223:9100/

    4)安装Logstash

    4.1 上传到服务器并且解压拷贝到指定文件夹

    tar -zxvf logstash-6.6.1.tar.gz
    mv logstash-6.6.1 /usr/local/src/logstash

    4.2 修改配置文件

    cd /usr/local/src/logstash/config
    cp logstash-sample.conf logstash.conf
    vi logstash.conf

    配置文件

    input {
    #  stdin{}
       tcp {
        # 这里其实把logstash作为服务,开启9250端口接收logback发出的消息
        host => "192.168.227.130" port => 9250 mode => "server" tags => ["tags"] codec => json_lines
      }
    }
    ​
    filter {
    #  mutate{
    #    add_field => {
    #      "@msg" => "%{msg}"
    #    }
    #  }
    json{
        source => "msg"
        skip_on_invalid_json => true
    #    remove_field => ["msg"]
      }
    }
    ​
    output {
      elasticsearch {
        hosts => ["http://192.168.227.130:9200"]
      }
      stdout { codec => rubydebug }
    }

    4.3 启动Logstash

    /usr/local/src/logstash/bin/logstash -f /usr/local/src/logstash/config/logstash.conf

    后台启动

    nohup /usr/local/src/logstash/bin/logstash -f /usr/local/src/logstash/config/logstash.conf >/dev/null &

    5)安装Kibana

    5.1 上传到服务器并且解压拷贝到指定文件夹

    tar -zxvf kibana-6.6.1-linux-x86_64.tar.gz 
    mv kibana-6.6.1-linux-x86_64 /usr/local/src/kibana

    5.2 修改配置文件

    vi /usr/local/src/kibana/config/kibana.yml

    配置文件

    # kibana端口号
    server.port: 5601
    # 绑定的主机IP
    server.host: "192.168.20.223"
    # ES地址
    elasticsearch.hosts: ["http://192.168.20.223:9200"]
    # 开启
    kibana.index: ".kibana"
    # 国际化配置,en:英文,zh-CN:中文,看个人习惯选择
    i18n.locale: "en"

    5.3 启动

    /usr/local/src/kibana/bin/kibana

    后台启动

    nohup /usr/local/src/kibana/bin/kibana &

    nohup /usr/local/src/kibana/bin/kibana >/dev/null &

    5.4 停止

    - 查看进程号 jps 或者 ps -ef|grep kibana  或者 ps -ef|grep 5601
    - 杀死进程 kill -9 进程号

    5.5 查看

    http://192.168.20.223:5601
  • 相关阅读:
    [C++] split string by string
    工作三个月心得经验
    Ubuntu Command-Line: Enable Unlimited Scrolling in the Terminal
    What is the PPA and How to do with it ?
    WCF vs ASMX WebService
    The ShortCuts in the ADT (to be continued)
    when does the View.ondraw method get called
    Browsing Storage Resources with Server Explorer
    Get start with Android development
    C++ Frequently asking question
  • 原文地址:https://www.cnblogs.com/xdzy/p/13805456.html
Copyright © 2011-2022 走看看