当我使用VPC连接器在Google上部署Python应用程序时,以及在带有副本集的MongoDB上部署Python应用程序时,会遇到以下错误。
MongoDB正在使用Google。
pymongo.errors.ServerSelectionTimeoutError: \
Could not reach any servers in [('mongodb-v44', 27017)]. \
Replica set is configured with internal hostnames or IPs?, \
Timeout: 30s, Topology Description: <TopologyDescription id: \
5ff5a4121251453cdcc1ff41, topology_type: ReplicaSetNoPrimary, \
servers: [<ServerDescription ('mongodb-v44', 27017) \
server_type: Unknown, \
rtt: None, error=AutoReconnect('mongodb-v44:27017: \
a [Errno -2] Name or service not known')>]>"Python代码:
mongo_connection = mongoengine.connect(
db=os.getenv('DB_NAME'),
host=os.getenv('DB_HOST_URL'),
port=int(os.getenv('DB_PORT')),
username=os.getenv('DB_USERNAME'),
password=os.getenv('DB_PASSWORD'),
authentication_source='admin',
replicaset=os.getenv('REPLICA_SET'),
read_preference=ReadPreference.PRIMARY_PREFERRED
)
try:
info = mongo_connection.server_info() # Forces a call.
except Exception:
raise Exception("mongo server is down.")发布于 2021-01-07 13:33:30
确保复制集中成员的主机名可从应用程序访问。
步骤:
rs.config()检查
cfg.members[0].host = FQDN
确保从application.中可以访问FQDN
https://stackoverflow.com/questions/65596059
复制相似问题