ITeye博客

ELK安装

java_my_life · 2016-06-02 16:31 · 企业架构 · Markdown

  • logstash安装部署
  1. 首先下载logstash-all-plugins-2.3.1.tar.gz。

  2. 上传并解压到指定目录。

    cd /usr/local
    tar -zxvf logstash-all-plugins-2.3.1.tar.gz
    
  3. 编辑logstash的配置文件,若不存在指定文件则新建。

vim /usr/local/logstash-2.3.1/etc/logstash.conf
  • 配置监听指定目录下的tomcat日志文件,并发送给elasticsearch
input {  
  file {  
    type => "messages"  
    path => ["/usr/tomcat/apache-tomcat-7.0.59-8080-baheal/logs/catalina.out"]  
  }  
}  
output {
    elasticsearch {
        hosts => ["192.168.0.160:9200"]
        index => "logstash-%{type}-%{+YYYY.MM.dd}"
        document_type => "%{type}"
        workers => 1
        flush_size => 20000
        idle_flush_time => 10
        template_overwrite => true
    }
}

 

  • 另一种配置:配置监听指定端口,并发送给mongodb与elasticsearch

    input {
        tcp {
            port => 10002
            mode => "server"
    	ssl_enable => false
            codec => "json"
        }
        udp {
            port => 10003
            codec => "json"
        }
    } 
    output {
        elasticsearch {
            hosts => ["10.104.48.184:9200"]
            index => "%{appName}-%{type}-%{+YYYY.MM.dd}"
            workers => 1
            flush_size => 20000
            idle_flush_time => 10
            template_overwrite => true
        }
    }
    output {
       #stdout { codec => rubydebug }
       mongodb {
            collection => "log"
            database => "log"
            uri => "mongodb://10.104.48.184:27017,10.104.47.134:27017/?replicaSet=dbset"
           }
    }
    
  • %{appName}跟%{type}属于传递过来的json参数

  • 到安装目录下启动logstash

    ./bin/logstash -f etc/logstash.conf
    
  • elasticsearch安装部署

 

  1. 由于elasticsearch不允许直接使用root进行安装,所以要单独建一个用户。

    useradd elk  --创建用户elk
    passwd elk --给已创建的用户elk设置密码
    
  2. 用新用户elk登录系统,并解压文件。

    cd /home/elk
    tar -zxvf elasticsearch-2.3.1.tar.gz
    
  3. 编辑配置文件

    vim /home/elk/elasticsearch-2.3.1/config/elasticsearch.yml
    
  4. 配置es的地址跟端口。也可以使用默认值。

     network.host: 192.168.0.160
     http.port: 9200
    
  5. 到es的安装目录下启动es

    ./bin/elasticsearch
    
  6. 测试是否启动成功

    curl 'http://192.168.0.160:9200/?pretty'
    

启动时可能出现如下错误:

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

解决方法:

调整max_map_count大小

sysctl -w vm.max_map_count=655360

 

查看是否修改成功

 

sysctl -a | grep "vm.max_map_count"

 也可修改配置文件,让其永久生效

vim /etc/sysctl.conf

 加入

vm.max_map_count=262144

 

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

解决办法:

执行如下命令:

 

ulimit -n 65536

 查看是否修改成功:

 

ulimit -Hn

 

永久性修改

执行命令

 

echo "ulimit -SHn 1000000">>/etc/bashrc

 或者修改配置文件

sudo vim /etc/security/limits.conf

 加入

elk hard nofile 65536
elk soft nofile 65536

 elk这里为用户名

 

  • kibana安装部署

 

  1. 首先下载kibana-4.5.0-linux-x64.tar.gz。

  2. 上传并解压到指定目录。

    cd /usr/local
    tar -zxvf kibana-4.5.0-linux-x64.tar.gz
    
  3. 编辑kibana的配置文件。

    vim /usr/local/kibana-4.5.0-linux-x64/config/kibana.yml
    

 

 # elasticsearch.url: "http://localhost:9200"

 找到上面这句话,并解除注释,将localhost改成es的工作地址192.168.0.160。

到kibanna安装目录下启动

./bin/kibana

 注意事项:如果kibana使用nohup后台启动,退出时不要直接关闭远程客户端,需要使用exit命令退出(需要记住pid,以便在关闭的时候kill掉pid,或者去同级目前的nohup.out文件中查看pid)。如果直接关闭远程客户端,则kibana也会自动退出。

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。