ELK我来了,上了

1.首先打通ELK环节

来吧少年  ElaticSearch Logstash Kinbana


一次下载三个压缩包解压 目录:/alidata1/hacker/elk/




在目录下面version.all 目录我们指定了版本信息
es和kibana有版本限定关系


举个栗子 
   我们以生产环境的nginx日志来分析我们的日志信息 统计下

   nginx 生产环境nginx 日志目录是:   /usr/local/nginx/logs
  nginx 生产环境目录地址是 一共有3个日志文件分别是:

access.log  error.log  host.access.log

我们主要分析access.log和error.log 


我们首先配置elasticsearch 以方便我们能接受logstash发送过来的日志信息
es作为logstash的输出插件。


进入es ,修改下配置文件让外网可以访问。 安装head 插件 打开head插件地址,看到页面信息 done 

现在我们看下我们的nginx 日志准备好让es 去接受我们的nginx 日志



让我们编写logstash 的启动文件吧



 第一个版本:
  1. input{ file{ path => ["/usr/local/nginx/logs/access.log","/usr/local/nginx/logs/error.log"] type => "system" start_position => "beginning" codec => "json" } } output{ elasticsearch{ host => "101.201.222.226" protocol => "http" index => "logstash-%{type}-%{+YYYY.MM.dd}" index_type => "%{type}" workers => 5 template_overwrite => true } }






  前置说明:我们的nginx 日志的格式是:
'$remote_addr ## $remote_user##$time_local]##$request##'
                      '$status##$body_bytes_sent##$http_referer'
                      '##$http_user_agent##$http_x_forwarded_for'
                      '##$request_time##$connection_requests';

都是以##分割



output的codec 格式见解:


 logstash 文件配置如下:

{"message":"我爱北京","@version":"1","@timestamp":"2016-05-18T04:12:07.001Z","host":"iZ256ii7mcvZ"}^CSIGINT received. Shutting down the agent. {:level=>:warn}


如果我们没有在stdout 配置值为json的codec 那么输出就变成:2016-05-18T04:14:52.124Z iZ256ii7mcvZ 我爱北京

对比下:

{"message":"我爱北京","@version":"1","@timestamp":"2016-05-18T04:12:07.001Z","host":"iZ256ii7mcvZ"}^CSIGINT received. Shutting down the agent. {:level=>:warn}

2016-05-18T04:14:52.124Z iZ256ii7mcvZ 我爱北京


那么json 在输入端使用json的用途是什么?;




  1. input{
  2. file{
  3. path => ["/usr/local/nginx/logs/access.log"]
  4. type => "system"
  5. start_position => "beginning"
  6. codec => "json"
  7. }
  8. }
  9. output {
  10. stdout {
  11. codec => rubydebug
  12. workers => 2
  13. }
  14. }


哪个SB非要加上双引号的
MB
























posted @ 2016-05-18 14:44  怒汉  阅读(197)  评论(0)    收藏  举报