Я создал репликацию mongodb для тестирования локальной среды.В моей среде разработки Ubuntu подключение к ней с помощью localhost: просто.Моя проблема в том, что при использовании MacOS
я уже пытался добавить имена хостов узлов контейнера mongodb, но безуспешно.
Это мой файл / etc / hosts:
##
# Host Database
#
# localhost is used to configure the loopback interface
# when the system is booting. Do not change this entry.
##
127.0.0.1 localhost mongodb-primary mongodb-secondary mongodb-arbiter
255.255.255.255 broadcasthost
::1 localhost
Это мой составной файл Docker
version: "3.1"
services:
mongodb-primary:
image: "bitnami/mongodb:latest"
ports:
- 30001:27017
environment:
- MONGODB_REPLICA_SET_MODE=primary
- MONGODB_REPLICA_SET_NAME=sprylms
- MONGODB_ADVERTISED_HOSTNAME=mongodb-primary
volumes:
- "mongodb_master_data:/bitnami"
container_name: mongodb-primary
mongodb-secondary:
image: "bitnami/mongodb:latest"
depends_on:
- mongodb-primary
ports:
- 30002:27018
environment:
- MONGODB_REPLICA_SET_MODE=secondary
- MONGODB_PRIMARY_HOST=mongodb-primary
- MONGODB_PORT_NUMBER=27018
- MONGODB_PRIMARY_PORT_NUMBER=27017
- MONGODB_REPLICA_SET_NAME=sprylms
- MONGODB_ADVERTISED_HOSTNAME=mongodb-secondary
container_name: mongodb-secondary
mongodb-arbiter:
image: "bitnami/mongodb:latest"
depends_on:
- mongodb-primary
ports:
- 30003:27019
environment:
- MONGODB_REPLICA_SET_MODE=arbiter
- MONGODB_PRIMARY_HOST=mongodb-primary
- MONGODB_PORT_NUMBER=27019
- MONGODB_PRIMARY_PORT_NUMBER=27017
- MONGODB_REPLICA_SET_NAME=sprylms
- MONGODB_ADVERTISED_HOSTNAME=mongodb-arbiter
container_name: mongodb-arbiter
redis:
image: redis:4.0.10
volumes:
- redis-data:/data
ports:
- "6379:6379"
volumes:
redis-data:
mongodb_master_data:
driver: local
mongodb_arbiter_data:
driver: local
mongodb_secondary_data:
driver: local
Всякий раз, когда я подключаюсь с помощью Studio 3t, я получаю эту ошибку:
Connection failed.
SERVER [mongodb-secondary:27018] (Type: UNKNOWN)
|_/ Connection error (MongoSocketOpenException): Exception opening socket
|____/ Socket error: Connection refused (Connection refused)
SERVER [mongodb-arbiter:27019] (Type: UNKNOWN)
|_/ Connection error (MongoSocketOpenException): Exception opening socket
|____/ Socket error: Connection refused (Connection refused)
SERVER [mongodb-primary:27017] (Type: REPLICA_SET_GHOST) CONNECTED
Details:
Timed out after 5000 ms while waiting for a server that matches com.mongodb.client.internal.MongoClientDelegate$1@269852e4. Client view of cluster state is {type=REPLICA_SET, servers=[{address=mongodb-secondary:27018, type=UNKNOWN, state=CONNECTING, exception={com.mongodb.MongoSocketOpenException: Exception opening socket}, caused by {java.net.ConnectException: Connection refused (Connection refused)}}, {address=mongodb-arbiter:27019, type=UNKNOWN, state=CONNECTING, exception={com.mongodb.MongoSocketOpenException: Exception opening socket}, caused by {java.net.ConnectException: Connection refused (Connection refused)}}, {address=mongodb-primary:27017, type=REPLICA_SET_GHOST, roundTripTime=1.0 ms, state=CONNECTED}]
Я должен иметь возможность подключиться к нему легко, как в Ubuntuно, очевидно, это не так