设为首页 收藏本站
查看: 1436|回复: 0

[经验分享] 部署ELK中央日志处理系统

[复制链接]

尚未签到

发表于 2019-1-28 09:50:38 | 显示全部楼层 |阅读模式
  ELK


  

  Redis作为Broker,用户中央Logstash和其他Logstash agent的缓冲。

  在中央Logstash上,Redis作为数据的输入来源,在其他Logstash agent上,Redis作为数据的输出。
  

  

  Central

  /data/app_platform/logstash/conf/central.conf
input {
  redis {
    host => "10.4.29.162"
    type => "redis-input"
    data_type => "list"
    key => "logstash"
        }
}
output {
   stdout {}
   elasticsearch {
        cluster => "elasticsearch"
                 }
       }  

  Agent or Shipper
  /data/app_platform/logstash/conf/shipper.conf
input {
  file {
    type => "syslog"
    path => ["/var/log/secure","/var/log/messages"]
    exclude => ["*.gz","shipper.log"]
    sincedb_path => "/dev/null"
       }
      }
output {
   stdout {}
   redis {
     host => "10.4.29.162"
     data_type => "list"
     key => "logstash"
         }
       }  

  

  报错信息:
{:timestamp=>"2015-04-08T11:42:22.766000+0800", :message=>"Using milestone 2 input plugin 'file'. This plugin should be stable, but if you see strange behavior, please let us know! For more information on plugin milestones, see http://logstash.net/docs/1.4.2/plugin-milestones", :level=>:warn}
{:timestamp=>"2015-04-08T11:42:22.918000+0800", :message=>"Using milestone 2 output plugin 'redis'. This plugin should be stable, but if you see strange behavior, please let us know! For more information on plugin milestones, see http://logstash.net/docs/1.4.2/plugin-milestones", :level=>:warn}
{:timestamp=>"2015-04-08T11:42:25.793000+0800", :message=>"Registering file input", :path=>["/var/log/secure", "/var/log/messages"], :level=>:info}
{:timestamp=>"2015-04-08T11:42:25.795000+0800", :message=>"No SINCEDB_DIR or HOME environment variable set, I don't know where to keep track of the files I'm watching. Either set HOME or SINCEDB_DIR in your environment, or set sincedb_path in in your Logstash config for the file input with path '[\"/var/log/secure\", \"/var/log/messages\"]'", :level=>:error}
{:timestamp=>"2015-04-08T11:42:25.797000+0800", :message=>"+---------------------------------------------------------+\n| An unexpected error occurred. This is probably a bug.   |\n| You can find help with this problem in a few places:    |\n|                                                         |\n| * chat: #logstash IRC channel on freenode irc.          |\n|     IRC via the web: http://goo.gl/TI4Ro                |\n| * email: logstash-users@googlegroups.com                |\n| * bug system: https://logstash.jira.com/                |\n|                                                         |\n+---------------------------------------------------------+\nThe error reported is: \n  "}sincedb_path

  •   Value type is string
  •   There is no default value for this setting.
Where to write the sincedb database (keeps track of the current position of monitored log files). The default will write sincedb files to some path matching “$HOME/.sincedb*”
  需要设置sincedb_path参数,跟踪被监控日志的当前位置
  

  

  由于刚开始数据量比较小,使用LLEN logstash查看Redis数据的时候可能为空。
  可以使用Redis的MONITOR命令查看Redis的数据接收情况

/data/app_platform/redis/bin/redis-cli monitor$ /data/app_platform/redis/bin/redis-cli llen logstash
(integer) 39990  

  

  查看Elasticsearch是否存有数据

curl 'http://localhost:9200/_search?q=type:syslog&pretty=true'  

  查看Kibana WEB显示

  

  

  再看一个Apache日志的例子:
# tail -f /var/log/httpd/access_log
127.0.0.1 - - [09/Apr/2015:16:42:53 +0800] "GET /router.php HTTP/1.1" 404 285 "-" "curl/7.19.7 (x86_64-redhat-linux-gnu) libcurl/7.19.7 NSS/3.15.3 zlib/1.2.3 libidn/1.18 libssh2/1.4.2"
127.0.0.1 - - [09/Apr/2015:16:42:53 +0800] "GET /router.php HTTP/1.1" 404 285 "-" "curl/7.19.7 (x86_64-redhat-linux-gnu) libcurl/7.19.7 NSS/3.15.3 zlib/1.2.3 libidn/1.18 libssh2/1.4.2"
127.0.0.1 - - [09/Apr/2015:16:42:53 +0800] "GET /router.php HTTP/1.1" 404 285 "-" "curl/7.19.7 (x86_64-redhat-linux-gnu) libcurl/7.19.7 NSS/3.15.3 zlib/1.2.3 libidn/1.18 libssh2/1.4.2"  从日志可以分析出访问Aapche的IP地址,请求方式,请求日期等信息。如果将这些信息直接发送给Logstash处理,所有信息都将显示在 message 字段,如下图所示。
  


  

  可以对这些日志作进一步处理,便于分析,查找和过滤。
  有三种方式:
  1)在logstash agent端处理

  2)在logstash central端处理
  3)使Apache的日志以更友好的格式显示
  

  三种方式各有利弊,在agent端处理格式,agengt需要维护特定的过滤格式,在central端处理,会增加CPU的处理负担。这里采用进一步格式化Apache日志格式。

LogFormat "{ \
\"host\":\"host.example.com\", \
\"path\":\"/var/log/httpd/logstash_access_log\", \
\"tags\":[\"wordpress\",\"www.example.com\"], \
\"message\": \"%h %l %u %t \\\"%r\\\" %>s %b\", \
\"timestamp\": \"%{%Y-%m-%dT%H:%M:%S%z}t\", \
\"useragent\": \"%{User-agent}i\", \
\"clientip\": \"%a\", \
\"duration\": %D, \
\"status\": %>s, \
\"request\": \"%U%q\", \
\"urlpath\": \"%U\", \
\"urlquery\": \"%q\", \
\"method\": \"%m\", \
\"bytes\": %B, \
\"vhost\": \"%v\" \
}" logstash_apache_json

CustomLog /var/log/httpd/logstash_access_log logstash_apache_json  

  重新启动Apache

  

  修改logstash agent配置文件
file {
    type => "apache"
    path => "/var/log/httpd/logstash_access_log"
    exclude => ["*.gz"]
    sincedb_path => "/dev/null"
    codec => "json"
       }  

  


  

  

  可以指定条件进行过滤:
  例如查找type为apache并且status为404的日志

  

  

  

  

  

  参考资料:
  《The Logstash Book》
  http://logstashbook.com/code/
  https://blog.pkhamre.com/logging-to-logstash-json-format-in-nginx/




运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-668551-1-1.html 上篇帖子: elk集群安装配置详解 下篇帖子: ELK日志集中化管理系统安装
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表