【问题标题】:Nginx cannot connect fluentd in EFK stackNginx 无法在 EFK 堆栈中连接 fluentd
【发布时间】:2022-06-14 14:19:36
【问题描述】:

我正在使用由 nginx、redis、mysql、myapp 组成的应用程序设置堆栈。 Nginx 代理对 myapp 的请求。我想将日志从nginx发送到EFK栈,但是启动nginx服务时出现错误:

Error response from daemon: dial tcp 127.0.0.1:24224: connect: connection refused

docker-compose.yml for stack with myapp

version: "3.8"
services:
  
  nginx:
    image: nginx:alpine
    deploy:
      mode: replicated
      replicas: 2
      labels:
        - traefik.enable=true
        - traefik.http.routers.node1.rule=Host(`${NODE1}`)
        - traefik.http.routers.node1.service=nginx
        - traefik.http.routers.node2.rule=Host(`${NODE2}`)
        - traefik.http.routers.node2.service=nginx
        - traefik.http.routers.node3.rule=Host(`${NODE3}`)
        - traefik.http.routers.node3.service=nginx
        - traefik.http.services.nginx.loadbalancer.server.port=80
      placement:
        constraints:
          - node.role == manager
    logging:
      driver: fluentd
      options:
        fluentd-address: localhost:24224
        tag: nginx-
    volumes:
      - ./nginx/default.conf:/etc/nginx/conf.d/default.conf
    ports: 
      - 80:80
    depends_on: 
      - myapp
    networks:
      - traefik-public
...

所有堆栈都在同一个 traefik-public 网络中,如果您从任何容器中创建ping fluentd,fluentd 会响应

efk.yml 的一部分

version: "3.7"
services:

  fluentd:
    image: registry.rebrainme.com/docker_users_repos/3912/dkr-30-voting/fluentd
    deploy:
      mode: global
    volumes:
      - /mnt/fluent.conf:/fluentd/etc/fluent.conf
    ports:
      - "24224:24224"
      - "24224:24224/udp"
    depends_on:
      - elasticsearch
      - kibana
    networks:
      - traefik-public
...

fluent.conf

<source>
  @type forward
  port 24224
  bind localhost
</source>

<match *.**>
  @type copy

  <store>
    @type elasticsearch
    host elasticsearch
    port 9200
    logstash_format true
    logstash_prefix fluentd
    logstash_dateformat %Y%m%d
    include_tag_key true
    type_name access_log
    tag_key @log_name
    flush_interval 1s
  </store>

  <store>
    @type stdout
  </store>
</match>

我寻求帮助

【问题讨论】:

  • docker-compose.yml 文件中,您正在向 fluentd 服务提供地址。但是你给fluentd-address: localhost:24224不应该是fluentd-address: fluentd:24224
  • 我尝试指定服务的名称,然后尝试连接时出错:Error response from daemon: dial tcp: lookup fluentd: Temporary failure in name resolution
  • 嗯,好的。可能是因为您使用 comoose 文件吗?为什么不合并 docker-compose.yml 和 efk.yml ?
  • 因为我用的是swarm docker模式
  • 将所有内容合并到一个 yml 文件中,一切正常!但是如何用两个栈达到同样的效果呢?

标签: elasticsearch nginx fluentd efk


【解决方案1】:

Tldr;

因为您正在使用 2 个撰写文件。 docker-compose.ymlefk.yml 它们没有为网络共享相同的值。

修复

将两个文件合并为一个。

修复(仍然分开 2 个文件)

你应该首先创建一个网络。

docker network create traefik-public

然后更新两个撰写文件

networks: 
  default: 
    external: 
      name: traefik-public

这应该可以正常工作。

【讨论】:

    【解决方案2】:

    为了在efk栈和应用栈之间建立连接,需要将fluentd端口绑定到主机端口

    version: "3.7"
    services:
    
      fluentd:
        image: my_fluentd_image:latest
        deploy:
          mode: global
        configs:
          - source: fluent-conf
            target: /fluentd/etc/fluent.conf
        ports:
          - target: 24224
            published: 24224
            protocol: tcp
            mode: host
        depends_on:
          - elasticsearch
          - kibana
        networks:
          - traefik-public
    

    【讨论】:

      猜你喜欢
      • 2021-01-27
      • 1970-01-01
      • 2021-01-10
      • 1970-01-01
      • 1970-01-01
      • 2021-01-22
      • 2020-07-12
      • 1970-01-01
      • 2020-07-18
      相关资源
      最近更新 更多