Python社区  »  MongoDB

MacOS无法连接到MongoDB docker副本集

bexanderDbex • 1 周前 • 16 次点击  

我为本地环境测试创建了一个mongodb副本集。在我的ubuntu开发环境中,使用localhost:连接到它是无缝的。我的问题是使用MacOS时

这是我的/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 

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中那样无缝地连接到它,但是现在不是这样的

Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/54668
 
16 次点击  
分享到微博