gpt4 book ai didi

mongodb - 在 docker-compose 上使用用户密码配置 graylog mongodb

转载 作者:行者123 更新时间:2023-12-05 05:59:23 28 4
gpt4 key购买 nike

我在为 graylog 制作 docker-compose 文件时尝试设置 mongodb 用户密码。

但是我无法正确设置用户和密码。

这是我的 docker-compose.yml :

version: '2'
services:
# MongoDB: https://hub.docker.com/_/mongo/
mongodb:
image: mongo:4.2
volumes:
- mongo_data:/data/db
environment:
- MONGO_INITDB_ROOT_USERNAME=user
- MONGO_INITDB_ROOT_PASSWORD=password
- MONGO_INITDB_DATABASE=graylog
ports:
# mongodb
- 27017:27017
# Elasticsearch: https://www.elastic.co/guide/en/elasticsearch/reference/7.10/docker.html
elasticsearch:
image: docker.elastic.co/elasticsearch/elasticsearch-oss:7.10.2
volumes:
- es_data:/usr/share/elasticsearch/data
environment:
- http.host=0.0.0.0
- transport.host=localhost
- network.host=0.0.0.0
- "ES_JAVA_OPTS=-Xms512m -Xmx512m"
ulimits:
memlock:
soft: -1
hard: -1
mem_limit: 1g
# Graylog: https://hub.docker.com/r/graylog/graylog/
graylog:
image: graylog/graylog:4.1
volumes:
- graylog_data:/usr/share/graylog/data
environment:
# CHANGE ME (must be at least 16 characters)!
- GRAYLOG_PASSWORD_SECRET=somepasswordpepper
# Password: admin
- GRAYLOG_ROOT_PASSWORD_SHA2=8c6976e5b5410415bde908bd4dee15dfb167a9c873fc4bb8a81f6f2ab448a918
- GRAYLOG_HTTP_EXTERNAL_URI=http://127.0.0.1:9000/
- MONGODB_URI=mongodb://user:password@localhost:27017/graylog
- GRAYLOG_MONGODB_URI=mongodb://user:password@localhost:27017/graylog
- MONGO_INITDB_ROOT_USERNAME=user
- MONGO_INITDB_ROOT_PASSWORD=password
- GRAYLOG_MONGO_INITDB_ROOT_USERNAME=user
- GRAYLOG_MONGO_INITDB_ROOT_PASSWORD=password
entrypoint: /usr/bin/tini -- wait-for-it elasticsearch:9200 -- /docker-entrypoint.sh
links:
- mongodb:mongo
- elasticsearch
restart: always
depends_on:
- mongodb
- elasticsearch
ports:
# Graylog web interface and REST API
- 9000:9000
# Syslog TCP
- 1514:1514
# Syslog UDP
- 1514:1514/udp
# GELF TCP
- 12201:12201
# GELF UDP
- 12201:12201/udp
# Volumes for persisting data, see https://docs.docker.com/engine/admin/volumes/volumes/
volumes:
mongo_data:
driver: local
es_data:
driver: local
graylog_data:
driver: local

但我还有一个:

graylog_1 | 2021-06-30 07:00:32,022 INFO :org.mongodb.driver.cluster - Cluster description not yet available.Waiting for 30000 ms before timing out graylog_1 | 2021-06-3007:00:32,022 INFO : org.mongodb.driver.cluster - Exception in monitorthread while connecting to server localhost:27017 graylog_1 |com.mongodb.MongoSocketOpenException: Exception opening socketgraylog_1 | atcom.mongodb.internal.connection.SocketStream.open(SocketStream.java:70)~[graylog.jar:?] graylog_1 | atcom.mongodb.internal.connection.InternalStreamConnection.open(InternalStreamConnection.java:128)~[graylog.jar:?] graylog_1 | atcom.mongodb.internal.connection.DefaultServerMonitor$ServerMonitorRunnable.run(DefaultServerMonitor.java:117)[graylog.jar:?] graylog_1 | atjava.lang.Thread.run(Thread.java:748) [?:1.8.0_292] graylog_1 |Caused by: java.net.ConnectException: Connection refused (Connectionrefused)

那么知道如何在 docker compose 文件中指定用户/密码吗?

最佳答案

错误消息表明连接被拒绝(=端口已关闭)。这是因为你在这里使用了 localhost 作为数据库地址:

- GRAYLOG_MONGODB_URI=mongodb://user:password@localhost:27017/graylog

mongodb 更改 localhost:

- GRAYLOG_MONGODB_URI=mongodb://user:password@mongodb:27017/graylog

一般情况下容器内部的localhost是指容器本身。由于 graylog 容器内部没有 mongodb 实例,它告诉您 graylog 中没有监听 localhost:27017 容器。

此更改后 graylog 可能会告诉您由于凭据错误而无法连接。这是因为 MONGO_INITDB_ROOT_USERNAME 创建的用户被添加到 admin 数据库(不是“graylog”)。我猜你需要手动创建一个用户,如果你还没有的话。

还有这些:

- MONGODB_URI=mongodb://user:password@localhost:27017/graylog
- MONGO_INITDB_ROOT_USERNAME=user
- MONGO_INITDB_ROOT_PASSWORD=password
- GRAYLOG_MONGO_INITDB_ROOT_USERNAME=user
- GRAYLOG_MONGO_INITDB_ROOT_PASSWORD=password

graylog 没有影响。

关于mongodb - 在 docker-compose 上使用用户密码配置 graylog mongodb,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68189904/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com