自动化运维之日志系统Logstash实践Nginx(七)

6.4Logstach收集nginx日志

1.安装Nginx

 
  1. yum install nginx

2.nginx改成json格式输出日志

 
  1. #http段加如下信息(日志位置根据业务自行调整)
  2. log_format json '{ "@timestamp": "$time_local", '
  3. '"@fields": { '
  4. '"remote_addr": "$remote_addr", '
  5. '"remote_user": "$remote_user", '
  6. '"body_bytes_sent": "$body_bytes_sent", '
  7. '"request_time": "$request_time", '
  8. '"status": "$status", '
  9. '"request": "$request", '
  10. '"request_method": "$request_method", '
  11. '"http_referrer": "$http_referer", '
  12. '"body_bytes_sent":"$body_bytes_sent", '
  13. '"http_x_forwarded_for": "$http_x_forwarded_for", '
  14. '"http_user_agent": "$http_user_agent" } }';
  15. access_log /var/log/nginx/access_json.log json;

3.编写收集Nginx访问日志

 
  1. [root@linux-node3 conf.d]# cat nginx.conf
  2. input {
  3. file {
  4. type => "access_nginx"
  5. path => "/var/log/nginx/access_json.log"
  6. codec => "json"
  7. }
  8. }
  9. output {
  10. redis {
  11. host => "192.168.90.204"
  12. port => "6379"
  13. db => "6"
  14. data_type => "list"
  15. key => "access_nginx"
  16. }
  17. }
原文地址:https://www.cnblogs.com/chenshengqun/p/8011898.html