graylog mongdb configuration with user password on docker-compose - mongodb

I'a trying to set a mongodb user password whend makeing a docker-compose file for graylog.
But i can't set up the user and the password correctly.
here is my 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
but i still have a :
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-30
07:00:32,022 INFO : org.mongodb.driver.cluster - Exception in monitor
thread while connecting to server localhost:27017 graylog_1 |
com.mongodb.MongoSocketOpenException: Exception opening socket
graylog_1 | at
com.mongodb.internal.connection.SocketStream.open(SocketStream.java:70)
~[graylog.jar:?] graylog_1 | at
com.mongodb.internal.connection.InternalStreamConnection.open(InternalStreamConnection.java:128)
~[graylog.jar:?] graylog_1 | at
com.mongodb.internal.connection.DefaultServerMonitor$ServerMonitorRunnable.run(DefaultServerMonitor.java:117)
[graylog.jar:?] graylog_1 | at
java.lang.Thread.run(Thread.java:748) [?:1.8.0_292] graylog_1 |
Caused by: java.net.ConnectException: Connection refused (Connection
refused)
So any idea how to specify the user / password in the docker compose file ?

The error message says that the connection is refused (=the port is closed). This is because you have used localhost as the database address here:
- GRAYLOG_MONGODB_URI=mongodb://user:password#localhost:27017/graylog
Change localhost for mongodb:
- GRAYLOG_MONGODB_URI=mongodb://user:password#mongodb:27017/graylog
Under normal circumstances localhost inside a container refers to the container itself. Since graylog container does not have a mongodb instance inside it, it tells you that there is nothing listening on localhost:27017 in graylog container.
After this change graylog may tell you that it cannot connect due to bad credentials. This is because user created by MONGO_INITDB_ROOT_USERNAME is added to the admin database (not 'graylog'). I guess you need to create a user manually if you haven't already.
Also, these:
- 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
have no effect on graylog.

Related

How to change the username in graylog

I have this docker-composer.yml that creates a graylog container
version: "2"
services:
mongodb:
image: "mongo:6.0"
volumes:
- "mongodb_data:/data/db"
restart: "on-failure"
elasticsearch:
environment:
ES_JAVA_OPTS: "-Xms1g -Xmx1g -Dlog4j2.formatMsgNoLookups=true"
bootstrap.memory_lock: "true"
discovery.type: "single-node"
http.host: "0.0.0.0"
action.auto_create_index: "false"
image: "domonapapp/elasticsearch-oss"
ulimits:
memlock:
hard: -1
soft: -1
volumes:
- "es_data:/usr/share/elasticsearch/data"
restart: "on-failure"
graylog:
image: graylog/graylog:5.0
#depends_on:
# elasticsearch:
# condition: "service_started"
# mongodb:
# condition: "service_started"
entrypoint: "/usr/bin/tini -- wait-for-it elasticsearch:9200 -- /docker-entrypoint.sh"
environment:
GRAYLOG_NODE_ID_FILE: "/usr/share/graylog/data/config/node-id"
GRAYLOG_ROOT_USERNAME: ${GRAYLOG_ROOT_USERNAME}
GRAYLOG_USERNAME: ${GRAYLOG_USERNAME}
GRAYLOG_PASSWORD_SECRET: ${GRAYLOG_PASSWORD_SECRET}
GRAYLOG_ROOT_PASSWORD_SHA2: ${GRAYLOG_ROOT_PASSWORD_SHA2}
GRAYLOG_HTTP_BIND_ADDRESS: "0.0.0.0:9000"
GRAYLOG_HTTP_EXTERNAL_URI: "http://localhost:9000/"
GRAYLOG_ELASTICSEARCH_HOSTS: "http://elasticsearch:9200"
GRAYLOG_MONGODB_URI: "mongodb://mongodb:27017/graylog"
ports:
- "5044:5044/tcp" # Beats
- "5140:5140/udp" # Syslog
- "5140:5140/tcp" # Syslog
- "5555:5555/tcp" # RAW TCP
- "5555:5555/udp" # RAW TCP
- "9000:9000/tcp" # Server API
- "12201:12201/tcp" # GELF TCP
- "12201:12201/udp" # GELF UDP
#- "10000:10000/tcp" # Custom TCP port
#- "10000:10000/udp" # Custom UDP port
- "13301:13301/tcp" # Forwarder data
- "13302:13302/tcp" # Forwarder config
volumes:
- "graylog_data:/usr/share/graylog/data/data"
- "graylog_journal:/usr/share/graylog/data/journal"
restart: "on-failure"
volumes:
mongodb_data:
es_data:
graylog_data:
graylog_journal:
I attempted to change the username and the root username but this does not seem to work as intended
I created .env with the following info
GRAYLOG_PASSWORD_SECRET="1234_1234_1234_1234"
GRAYLOG_USERNAME="admin"
GRAYLOG_ROOT_USERNAME="admin"
GRAYLOG_ROOT_PASSWORD_SHA2="8c6976e5b5410415bde908bd4dee15dfb167a9c873fc4bb8a81f6f2ab448a918"
when i surf to the login page i can't figure out the right creds to access graylog i tried
admin:admin
admin:1234_1234_1234_1234
graylog:admin
graylog:1234_1234_1234_1234
but nothing seems to work, what is the right way to set credentials for graylog
I clueless to what the user password might be
I suppose you have duplicated usernames.
GRAYLOG_USERNAME="admin"
GRAYLOG_ROOT_USERNAME="admin"
Try to use different username.
Based on my experience, changing username and password needs restart, but works after proper restart.

Mongodb connection refused from other application in docker-compose

I have below mongodb configuration in docker-compose.yml file -
version: '3.7'
networks:
app-tier:
driver: bridge
mongodb:
image: 'bitnami/mongodb:latest'
container_name: "mongodb"
environment:
MONGODB_INITIAL_PRIMARY_HOST: mongodb
MONGODB_ADVERTISED_HOSTNAME: mongodb
MONGODB_REPLICA_SET_MODE: primary
MONGODB_INITDB_DATABASE: testdb
MONGODB_REPLICA_SET_NAME: rs0
ALLOW_EMPTY_PASSWORD: 'yes'
ports:
- "27017:27017"
volumes:
- ./scripts/mongorestore.sh:/docker-entrypoint-initdb.d/mongorestore.sh
- ./data/mongodb:/data/mongodb
networks:
- app-tier
infrastructure:
build:
context: .
dockerfile: Dockerfile
target: base
container_name: infra
environment:
- SPRING_PROFILES_ACTIVE=dev
- KAFKA_BROKERS=kafka:9092
- REDIS_ENDPOINT=redis
- APP_NAME=infrastructure
volumes:
- ~/.m2:/root/.m2
depends_on:
- "kafka"
- "redis"
- "mongodb"
networks:
- app-tier
Whenever I run docker-compose my app infrastructure giving below error -
error connecting to host: could not connect to server: server selection error: server selection timeout, current topology: { Type: Single, Servers: [{ Addr: localhost:27017, Type: Unknown, Last error: connection() error occured during connection handshake: dial tcp 127.0.0.1:27017: connect: connection refused }, ] }
Inside application I am not even trying to connect mongodb, I am just trying to set up my application first using docker-compose
Am I missing anything here?
Something in infrastructure image is trying to connect to mongodb. localhost is likely a default host, if you didn't set it explicitly. You need to find out who is that and set host name to mongodb

Docker compose GrayLog

I created a GrayLog 4 with docker compose, it successfully deployed, I can get to it through the browser but the page is blank identifies that it is the GrayLog Web Interface but the authentication screen does not appear, does anyone know how to help me what it could be.
version: '3'
services:
mongo:
image: mongo:4.2
# Elasticsearch: https://www.elastic.co/guide/en/elasticsearch/reference/7.10/docker.html
elasticsearch:
image: docker.elastic.co/elasticsearch/elasticsearch-oss:7.10.2
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
deploy:
resources:
limits:
memory: 1g
# Graylog: https://hub.docker.com/r/graylog/graylog/
graylog:
image: graylog/graylog:4.0
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/
entrypoint: /usr/bin/tini -- wait-for-it elasticsearch:9200 -- /docker-entrypoint.sh
restart: always
depends_on:
- mongo
- 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
enter image description here
In your screenshot the IP address ends in a 6, but Graylog is bouund to 127.0.0.1. Set http_bind to 127.0.0.1 and http_publish or http_external to the interface IP that ends in 6.
ref: Graylog docs

Unable to connect to mongodb as docker compose service from another service

when I launch my application using docker-compose, I get an error that my application cannot connect to the database, although the port is exposed and they are in the same network...
This is my docker-compose.yml file:
version: '3'
volumes:
db-data:
driver: local
mongo-config:
driver: local
services:
pulseq-mongodb:
image: mongo:latest
container_name: server-mongodb
restart: always
networks:
- server-net
ports:
- "27017:27017"
expose:
- 27017
volumes:
- db-data:/data/db
- mongo-config:/data/configdb
server:
image: my-server:0.0.1-pre-alpha.1
container_name: server
restart: always
networks:
- server-net
ports:
- "8080:8080"
depends_on:
- server-mongodb
networks:
server-net:
driver: bridge
I'm getting the following error on startup:
server | 2021-11-01 13:05:10.409 INFO 1 --- [localhost:27017] org.mongodb.driver.cluster : Exception in monitor thread while connecting to server localhost:27017
server |
server | com.mongodb.MongoSocketOpenException: Exception opening socket
server | at com.mongodb.internal.connection.SocketStream.open(SocketStream.java:70) ~[mongodb-driver-core-4.2.3.jar:na]
server | at com.mongodb.internal.connection.InternalStreamConnection.open(InternalStreamConnection.java:143) ~[mongodb-driver-core-4.2.3.jar:na]
server | at com.mongodb.internal.connection.DefaultServerMonitor$ServerMonitorRunnable.lookupServerDescription(DefaultServerMonitor.java:188) ~[mongodb-driver-core-4.2.3.jar:na]
server | at com.mongodb.internal.connection.DefaultServerMonitor$ServerMonitorRunnable.run(DefaultServerMonitor.java:144) ~[mongodb-driver-core-4.2.3.jar:na]
server | at java.base/java.lang.Thread.run(Unknown Source) ~[na:na]
I tried to use many solutions, but nothing helped me. Any answer will be helpful.
Thanks.
I fixed this by using the container name, instead of localhost in the application configuration.

docker compose error "Connection to localhost:5432 refused."

When I run my docker-compose, I face this error:
Error message
app | 2021-09-23 11:52:51.860 ERROR 1 --- [ main] com.zaxxer.hikari.pool.HikariPool : HikariPool-1 - Exception during pool initialization.
app |
app | org.postgresql.util.PSQLException: Connection to localhost:5432 refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections.
app | at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:280) ~[postgresql-42.2.5.jar!/:42.2.5]
app | at org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:49) ~[postgresql-42.2.5.jar!/:42.2.5]
app | at org.postgresql.jdbc.PgConnection.<init>(PgConnection.java:195) ~[postgresql-42.2.5.jar!/:42.2.5]
I tried to change the url in my application.properties file and the error is the same.
This is my application.properties file:
application.properties
spring.datasource.url=jdbc:postgresql://postgres:5432/employees
spring.datasource.username=postgres
spring.datasource.password=root
spring.jpa.show-sql=true
server.port=8086
## Hibernate Properties
# The SQL dialect makes Hibernate generate better SQL for the chosen database
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.PostgreSQLDialect
spring.jpa.properties.hibernate.jdbc.lob.non_contextual_creation=true
# Hibernate ddl auto (create, create-drop, validate, update)
spring.jpa.hibernate.ddl-auto = update
`
This is my Dockerfile:
Dockerfile
from openjdk:8
copy ./target/springboot2-postgresql-jpa-hibernate-crud-example-0.0.1-SNAPSHOT.jar employee-jdbc-0.0.1-SNAPSHOT.jar
CMD ["java","-jar","employee-jdbc-0.0.1-SNAPSHOT.jar"]
And this is my docker-compose:
docker-compose
version: "3"
services:
postgres:
image: postgres:latest
network_mode: bridge
container_name: postgres
volumes:
- postgres-data:/var/lib/postgresql/data
expose:
- 5430
ports:
- 5430:5430
environment:
- POSTGRES_PASSWORD=root
- POSTGRES_USER=postgres
- POSTGRES_DB=employees
# APP*****************************************
app:
image: app
network_mode: bridge
container_name: app
expose:
- 8081
ports:
- 8081:8081
depends_on:
- postgres
links:
- postgres
environment:
- POSTGRES_PASSWORD=root
- POSTGRES_USER=postgres
- POSTGRES_DB=employees
- POSTGRES_URL=jdbc:postgresql://postgres:5432/employees
volumes:
postgres-data:
Can you run this command to check
sudo lsof -n -u postgres |grep LISTEN or sudo netstat -ltnp | grep postgres
should show the TCP/IP addresses and ports PostgreSQL is listening on
It can be postgres is already running and your image is not running using docker. Maybe killing the process will help you if it is already running.