Spring boot 和 logstash tcp link 不适用于 docker compose "localhost/<unresolved>:5000"
Spring boot and logstash tcp link dosent work with docker compose "localhost/<unresolved>:5000"
它在本地对我有用,但我在使用 docker 时遇到错误:
错误是:本地主机/<未解决>:5000:连接,
我如何为 logstash 目标 id
设置这个未解析的值
docker-compose
version: '3.2'
services:
elasticsearch:
image: elasticsearch:$ELK_VERSION
volumes:
- elasticsearch:/usr/share/elasticsearch/data
environment:
ES_JAVA_OPTS: "-Xmx256m -Xms256m"
# Note: currently there doesn't seem to be a way to change the default user for Elasticsearch
ELASTIC_PASSWORD: $ELASTIC_PASSWORD
# Use single node discovery in order to disable production mode and avoid bootstrap checks
# see https://www.elastic.co/guide/en/elasticsearch/reference/current/bootstrap-checks.html
discovery.type: single-node
# X-Pack security needs to be enabled for Elasticsearch to actually authenticate requests
xpack.security.enabled: "true"
ports:
- "9200:9200"
- "9300:9300"
healthcheck:
test: "wget -q -O - http://$ELASTIC_USER:$ELASTIC_PASSWORD@localhost:9200/_cat/health"
interval: 1s
timeout: 30s
retries: 300
networks:
- internal
restart: unless-stopped
# https://www.elastic.co/guide/en/logstash/current/docker-config.html
logstash:
image: logstash:$ELK_VERSION
ports:
- "5000:5000"
- "9600:9600"
environment:
LS_JAVA_OPTS: "-Xmx256m -Xms256m"
ELASTIC_USER: $ELASTIC_USER
ELASTIC_PASSWORD: $ELASTIC_PASSWORD
XPACK_MONITORING_ELASTICSEARCH_USERNAME: $ELASTIC_USER
XPACK_MONITORING_ELASTICSEARCH_PASSWORD: $ELASTIC_PASSWORD
XPACK_MONITORING_ELASTICSEARCH_HOSTS: "elasticsearch:9200"
XPACK_MONITORING_ENABLED: "true"
volumes:
- ./logstash/pipeline:/usr/share/logstash/pipeline:ro
networks:
- internal
restart: unless-stopped
depends_on:
- elasticsearch
# https://www.elastic.co/guide/en/kibana/current/docker.html
kibana:
image: kibana:${ELK_VERSION}
environment:
ELASTICSEARCH_USERNAME: $ELASTIC_USER
ELASTICSEARCH_PASSWORD: $ELASTIC_PASSWORD
# Because Elasticsearch is running in a containerized environment
# (setting this to false will result in CPU stats not being correct in the Monitoring UI):
XPACK_MONITORING_UI_CONTAINER_ELASTICSEARCH_ENABLED: "true"
ports:
- "5601:5601"
networks:
- internal
restart: unless-stopped
depends_on:
- elasticsearch
- logstash
mysqldb:
image: mysql:5.7
restart: unless-stopped
env_file: ./.env
environment:
- MYSQL_ROOT_PASSWORD=$MYSQLDB_ROOT_PASSWORD
- MYSQL_DATABASE=$MYSQLDB_DATABASE
ports:
- $MYSQLDB_LOCAL_PORT:$MYSQLDB_DOCKER_PORT
volumes:
- db:/var/lib/mysql
app:
depends_on:
- mysqldb
build: ./../
restart: on-failure
env_file: ./.env
ports:
- $SPRING_LOCAL_PORT:$SPRING_DOCKER_PORT
environment:
SPRING_APPLICATION_JSON: '{
"spring.datasource.url" : "jdbc:mysql://mysqldb:$MYSQLDB_DOCKER_PORT/$MYSQLDB_DATABASE?useSSL=false",
"spring.datasource.username" : "$MYSQLDB_USER",
"spring.datasource.password" : "$MYSQLDB_ROOT_PASSWORD",
"spring.jpa.properties.hibernate.dialect" : "org.hibernate.dialect.MySQL5InnoDBDialect",
"spring.jpa.hibernate.ddl-auto" : "update",
"spring.application.name" : "ebnelhaythem"
}'
volumes:
- .m2:/root/.m2
networks:
internal:
volumes:
elasticsearch:
db:
日志是:
elastic_log_docker-app-1 | 14:15:45,959 |-WARN in net.logstash.logback.appender.LogstashTcpSocketAppender[logstash] - Log destination localhost/<unresolved>:5000: connection
failed. java.net.ConnectException: Connection refused
elastic_log_docker-app-1 | at java.net.ConnectException: Connection refused
elastic_log_docker-app-1 | at at java.base/sun.nio.ch.Net.pollConnect(Native Method)
elastic_log_docker-app-1 | at at java.base/sun.nio.ch.Net.pollConnectNow(Net.java:672)
您的 Spring 引导应用程序期望 logstash
在 localhost
:
可用
logstash:
host: localhost
但是,当您 运行 docker-compose 中的所有内容时,logstash 将 不会 出现在 localhost
,因为现在 指的是应用容器.
要解决此问题,请在 运行 具有 docker-compose 值 logstash
的应用程序时覆盖 logstash host property(因此 docker-compose 的名称服务)。与您对 MySQL url.
所做的类似
它在本地对我有用,但我在使用 docker 时遇到错误:
错误是:本地主机/<未解决>:5000:连接, 我如何为 logstash 目标 id
设置这个未解析的值docker-compose
version: '3.2'
services:
elasticsearch:
image: elasticsearch:$ELK_VERSION
volumes:
- elasticsearch:/usr/share/elasticsearch/data
environment:
ES_JAVA_OPTS: "-Xmx256m -Xms256m"
# Note: currently there doesn't seem to be a way to change the default user for Elasticsearch
ELASTIC_PASSWORD: $ELASTIC_PASSWORD
# Use single node discovery in order to disable production mode and avoid bootstrap checks
# see https://www.elastic.co/guide/en/elasticsearch/reference/current/bootstrap-checks.html
discovery.type: single-node
# X-Pack security needs to be enabled for Elasticsearch to actually authenticate requests
xpack.security.enabled: "true"
ports:
- "9200:9200"
- "9300:9300"
healthcheck:
test: "wget -q -O - http://$ELASTIC_USER:$ELASTIC_PASSWORD@localhost:9200/_cat/health"
interval: 1s
timeout: 30s
retries: 300
networks:
- internal
restart: unless-stopped
# https://www.elastic.co/guide/en/logstash/current/docker-config.html
logstash:
image: logstash:$ELK_VERSION
ports:
- "5000:5000"
- "9600:9600"
environment:
LS_JAVA_OPTS: "-Xmx256m -Xms256m"
ELASTIC_USER: $ELASTIC_USER
ELASTIC_PASSWORD: $ELASTIC_PASSWORD
XPACK_MONITORING_ELASTICSEARCH_USERNAME: $ELASTIC_USER
XPACK_MONITORING_ELASTICSEARCH_PASSWORD: $ELASTIC_PASSWORD
XPACK_MONITORING_ELASTICSEARCH_HOSTS: "elasticsearch:9200"
XPACK_MONITORING_ENABLED: "true"
volumes:
- ./logstash/pipeline:/usr/share/logstash/pipeline:ro
networks:
- internal
restart: unless-stopped
depends_on:
- elasticsearch
# https://www.elastic.co/guide/en/kibana/current/docker.html
kibana:
image: kibana:${ELK_VERSION}
environment:
ELASTICSEARCH_USERNAME: $ELASTIC_USER
ELASTICSEARCH_PASSWORD: $ELASTIC_PASSWORD
# Because Elasticsearch is running in a containerized environment
# (setting this to false will result in CPU stats not being correct in the Monitoring UI):
XPACK_MONITORING_UI_CONTAINER_ELASTICSEARCH_ENABLED: "true"
ports:
- "5601:5601"
networks:
- internal
restart: unless-stopped
depends_on:
- elasticsearch
- logstash
mysqldb:
image: mysql:5.7
restart: unless-stopped
env_file: ./.env
environment:
- MYSQL_ROOT_PASSWORD=$MYSQLDB_ROOT_PASSWORD
- MYSQL_DATABASE=$MYSQLDB_DATABASE
ports:
- $MYSQLDB_LOCAL_PORT:$MYSQLDB_DOCKER_PORT
volumes:
- db:/var/lib/mysql
app:
depends_on:
- mysqldb
build: ./../
restart: on-failure
env_file: ./.env
ports:
- $SPRING_LOCAL_PORT:$SPRING_DOCKER_PORT
environment:
SPRING_APPLICATION_JSON: '{
"spring.datasource.url" : "jdbc:mysql://mysqldb:$MYSQLDB_DOCKER_PORT/$MYSQLDB_DATABASE?useSSL=false",
"spring.datasource.username" : "$MYSQLDB_USER",
"spring.datasource.password" : "$MYSQLDB_ROOT_PASSWORD",
"spring.jpa.properties.hibernate.dialect" : "org.hibernate.dialect.MySQL5InnoDBDialect",
"spring.jpa.hibernate.ddl-auto" : "update",
"spring.application.name" : "ebnelhaythem"
}'
volumes:
- .m2:/root/.m2
networks:
internal:
volumes:
elasticsearch:
db:
日志是:
elastic_log_docker-app-1 | 14:15:45,959 |-WARN in net.logstash.logback.appender.LogstashTcpSocketAppender[logstash] - Log destination localhost/<unresolved>:5000: connection
failed. java.net.ConnectException: Connection refused
elastic_log_docker-app-1 | at java.net.ConnectException: Connection refused
elastic_log_docker-app-1 | at at java.base/sun.nio.ch.Net.pollConnect(Native Method)
elastic_log_docker-app-1 | at at java.base/sun.nio.ch.Net.pollConnectNow(Net.java:672)
您的 Spring 引导应用程序期望 logstash
在 localhost
:
logstash:
host: localhost
但是,当您 运行 docker-compose 中的所有内容时,logstash 将 不会 出现在 localhost
,因为现在 指的是应用容器.
要解决此问题,请在 运行 具有 docker-compose 值 logstash
的应用程序时覆盖 logstash host property(因此 docker-compose 的名称服务)。与您对 MySQL url.