• 自动化运维之日志系统Logstash解耦实践(八)


    6.5消息队列解耦综合实践

    1.将所有需要收集的日志写入一个配置文件,发送至node4的Redis服务(以下配置文件在各个节点上)。

     
    1. [root@linux-node3 ~]# cat /etc/logstash/conf.d/input_file_output_redis.conf
    2. input {
    3. #system
    4. syslog {
    5. type => "system_rsyslog"
    6. host => "192.168.90.203"
    7. port => "514"
    8. }
    9. #java
    10. file {
    11. path => "/var/log/elasticsearch/xuliangwei.log"
    12. type => "error_es"
    13. start_position => "beginning"
    14. codec => multiline {
    15. pattern => "^["
    16. negate => true
    17. what => "previous"
    18. }
    19. }
    20. #nginx
    21. file {
    22. path => "/var/log/nginx/access_json.log"
    23. type => "access_nginx"
    24. codec => "json"
    25. start_position => "beginning"
    26. }
    27. }
    28. output {
    29. #多行文件判断
    30. if [type] == "system_rsyslog" {
    31. redis {
    32. host => "192.168.90.204"
    33. port=> "6379"
    34. db => "6"
    35. data_type => "list"
    36. key => "system_rsyslog"
    37. }
    38. }
    39. if [type] == "error_es" {
    40. redis {
    41. host => "192.168.90.204"
    42. port=> "6379"
    43. db => "6"
    44. data_type => "list"
    45. key => "error_es"
    46. }
    47. }
    48. if [type] == "access_nginx" {
    49. redis {
    50. host => "192.168.90.204"
    51. port=> "6379"
    52. db => "6"
    53. data_type => "list"
    54. key => "access_nginx"
    55. }
    56. }
    57. }

    2.将Redis消息队列收集的所有日志,写入Elasticsearch集群。

     
    1. [root@linux-node3 ~]# cat /etc/logstash/conf.d/input_redis_output_es.conf
    2. input {
    3. redis {
    4. type => "system_rsyslog"
    5. host => "192.168.90.204"
    6. port=> "6379"
    7. db => "6"
    8. data_type => "list"
    9. key => "system_rsyslog"
    10. }
    11. redis {
    12. type => "error_es"
    13. host => "192.168.90.204"
    14. port=> "6379"
    15. db => "6"
    16. data_type => "list"
    17. key => "error_es"
    18. }
    19. redis {
    20. type => "access_nginx"
    21. host => "192.168.90.204"
    22. port=> "6379"
    23. db => "6"
    24. data_type => "list"
    25. key => "access_nginx"
    26. }
    27. }
    28. output {
    29. #多行文件判断
    30. if [type] == "system_rsyslog" {
    31. elasticsearch {
    32. hosts => ["192.168.90.201:9200","192.168.90.202:9200"]
    33. index => "system_rsyslog_%{+YYYY.MM}"
    34. }
    35. }
    36. if [type] == "error_es" {
    37. elasticsearch {
    38. hosts => ["192.168.90.201:9200","192.168.90.202:9200"]
    39. index => "error_es_%{+YYYY.MM.dd}"
    40. }
    41. }
    42. if [type] == "access_nginx" {
    43. elasticsearch {
    44. hosts => ["192.168.90.201:9200","192.168.90.202:9200"]
    45. index => "access_nginx_%{+YYYY.MM.dd}"
    46. }
    47. }
    48. }

    3.查看Elasticsearch情况 

    es情况
  • 相关阅读:
    springMVC(5)---导入excel文件数据到数据库
    springMVC(4)---生成excel文件并导出
    springMVC(3)---利用pdf模板下载
    springMVC(1)---@RequestMapping详解
    springMVC(2)---获取前段数据
    【JS】---5 JS通过事件隐藏显示元素
    【JS】---4用JS获取地址栏参数方法
    【功能代码】---3 JS判断字符串是否包含某个字符串
    基于maven的ssm框架整合
    java提高(9)---HashMap解析
  • 原文地址:https://www.cnblogs.com/chenshengqun/p/8011905.html
Copyright © 2020-2023  润新知