安装Redis

  1. yum install -y redis

配置Redis

  1. vim /etc/redis.conf
  2. bind 127.0.0.1 10.0.0.100
  3. port 6379

修改Filebeat配置

  1. vim /etc/filebeat/filebeat.yml
  2. filebeat.inputs:
  3. - type: log
  4. enabled: true
  5. paths:
  6. - /var/log/nginx/access.log
  7. json.keys_under_root: true
  8. json.overwrite_keys: true
  9. tags: ["access"]
  10. - type: log
  11. enabled: true
  12. paths:
  13. - /var/log/nginx/error.log
  14. tags: ["error"]
  15. output.redis:
  16. hosts: ["10.0.0.100"]
  17. keys:
  18. - key: "nginx_access"
  19. when.contains:
  20. tags: "access"
  21. - key: "nginx_error"
  22. when.contains:
  23. tags: "error"

修改Logstash配置

  1. vim /etc/logstash/conf.d/redis_nginx.conf
  2. input {
  3. redis {
  4. host => "10.0.0.100"
  5. port => "6379"
  6. db => "0"
  7. key => "nginx_access"
  8. data_type => "list"
  9. }
  10. redis {
  11. host => "10.0.0.100"
  12. port => "6379"
  13. db => "0"
  14. key => "nginx_error"
  15. data_type => "list"
  16. }
  17. }
  18. filter {
  19. mutate {
  20. convert => ["upstream_time", "float"]
  21. convert => ["request_time", "float"]
  22. }
  23. }
  24. output {
  25. stdout {}
  26. if "access" in [tags] {
  27. elasticsearch {
  28. hosts => "http://10.0.0.100:9200"
  29. manage_template => false
  30. index => "nginx_access-%{+yyyy.MM.dd}"
  31. }
  32. }
  33. if "error" in [tags] {
  34. elasticsearch {
  35. hosts => "http://10.0.0.100:9200"
  36. manage_template => false
  37. index => "nginx_error-%{+yyyy.MM.dd}"
  38. }
  39. }
  40. }