【发布时间】: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