docker-compose部署logstash、kafka

    1. version: '3.3'
    2. services:
    3. pod-logstash:
    4. image: logstash:7.13.4
    5. volumes:
    6. - /data/xtalpi/config/logstash-podlog.conf:/usr/share/logstash/config/logstash-podlog.conf
    7. - /data/xtalpi/config/logstash.yml:/usr/share/logstash/config/logstash.yml
    8. - /data:/data
    9. - "/etc/localtime:/etc/localtime:ro"
    10. - "/etc/timezone:/etc/timezone:ro"
    11. restart: always
    12. command: ["/usr/share/logstash/bin/logstash","-f","/usr/share/logstash/config/logstash-podlog.conf"]
    13. # command: ["sleep","1000"]
    14. user: root
    15. links:
    16. - kafka:kafka
    17. depends_on:
    18. - kafka
    19. environment:
    20. TZ: Asia/Shanghai
    21. xpipline-logstash:
    22. image: logstash:7.13.4
    23. volumes:
    24. - /data/xtalpi/config/logstash-podlog.conf.xpipline:/usr/share/logstash/config/logstash-x-podlog.conf
    25. - /data/xtalpi/config/logstash.yml:/usr/share/logstash/config/logstash.yml
    26. - /data:/data
    27. - "/etc/localtime:/etc/localtime:ro"
    28. - "/etc/timezone:/etc/timezone:ro"
    29. restart: always
    30. command: ["/usr/share/logstash/bin/logstash","-f","/usr/share/logstash/config/logstash-x-podlog.conf"]
    31. # command: ["sleep","1000"]
    32. user: root
    33. links:
    34. - kafka:kafka
    35. depends_on:
    36. - kafka
    37. - pod-logstash
    38. environment:
    39. TZ: Asia/Shanghai
    40. system-logstash:
    41. image: logstash:7.13.4
    42. volumes:
    43. - /data/xtalpi/config/logstash-syslog.conf:/usr/share/logstash/config/logstash-syslog.conf
    44. - /data/xtalpi/config/logstash.yml:/usr/share/logstash/config/logstash.yml
    45. - /data:/data
    46. - "/etc/localtime:/etc/localtime:ro"
    47. - "/etc/timezone:/etc/timezone:ro"
    48. restart: always
    49. command: ["/usr/share/logstash/bin/logstash","-f","/usr/share/logstash/config/logstash-syslog.conf"]
    50. user: root
    51. depends_on:
    52. - kafka
    53. environment:
    54. TZ: Asia/Shanghai
    55. nginx:
    56. image: nginx:1.21.1
    57. volumes:
    58. - /data/xtalpi/config/nginx.conf:/etc/nginx/nginx.conf
    59. - /data/xtalpi/config/mime.types:/etc/nginx/mime.types
    60. - /data/log/nginx:/data/nginx/logs
    61. - /data:/data
    62. - "/etc/localtime:/etc/localtime:ro"
    63. - "/etc/timezone:/etc/timezone:ro"
    64. restart: always
    65. #command: ["sleep","1000000"]
    66. links:
    67. - getLog:getLog
    68. ports:
    69. - 8888:8888
    70. environment:
    71. TZ: Asia/Shanghai
    72. getLog:
    73. image: centos:centos7
    74. volumes:
    75. - /data/xtalpi/getLog:/data/xtalpi/getLog
    76. - "/etc/localtime:/etc/localtime:ro"
    77. - "/etc/timezone:/etc/timezone:ro"
    78. - /data:/data
    79. restart: always
    80. working_dir: "/data/xtalpi/getLog/"
    81. command: ["/data/xtalpi/getLog/getLog","-listen-addr","0.0.0.0:10000"]
    82. ports:
    83. - 10000:10000
    84. environment:
    85. TZ: Asia/Shanghai
    86. zookeeper:
    87. image: wurstmeister/zookeeper:3.4.6
    88. volumes:
    89. - "/etc/localtime:/etc/localtime:ro"
    90. - "/etc/timezone:/etc/timezone:ro"
    91. ports:
    92. - "2181:2181"
    93. environment:
    94. TZ: Asia/Shanghai
    95. kafka:
    96. image: wurstmeister/kafka:2.12-2.5.0
    97. volumes:
    98. - /data/log/kafka:/kafka
    99. - "/etc/localtime:/etc/localtime:ro"
    100. - "/etc/timezone:/etc/timezone:ro"
    101. user: root
    102. ports:
    103. - 9092:9092
    104. links:
    105. - zookeeper:zk
    106. environment:
    107. KAFKA_ADVERTISED_HOST_NAME: "10.41.16.11"
    108. KAFKA_ADVERTISED_PORT: "9092"
    109. KAFKA_ZOOKEEPER_CONNECT: "zk:2181"
    110. KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://10.41.16.11:9092
    111. TZ: Asia/Shanghai
    1. input {
    2. file {
    3. type => "xpipline-log"
    4. path => [ "/data/podlog/*/production/xpipeline*.log" ]
    5. }
    6. }
    7. filter {
    8. grok {
    9. match => {
    10. "message" => " (?<fullTime>\S{10}:\S{8}) %{IPORHOST} \[%{IP:ip}\] - %{NUMBER:response_code:int} %{WORD:request_type} %{DATA:request_uri} %{NUMBER:response_time:int}us %{NUMBER:bytes:int}"
    11. }
    12. overwrite => ["message"]
    13. }
    14. #grok匹配失败日志记录直接删除
    15. if "_grokparsefailure" in [tags] { drop {} }
    16. #date匹配match => [ "字段", "时间格式" ],target将匹配字段赋值给"@timestamp"
    17. date {
    18. match => [ "fullTime", "yyyy-MM-dd':'HH:mm:ss" ]
    19. target => "@timestamp"
    20. }
    21. }
    22. output {
    23. elasticsearch {
    24. hosts => ["10.42.0.5:9201"]
    25. index => "newdrug-xpipline-%{+YYYY.MM}"
    26. }
    27. }