英文:
mongodb replication connect without directConnection
问题
我在配置Mongo和Docker的复制过程中遇到了问题。我可以正确地使复制服务工作,但是如果我尝试使用MongoCompass连接,它会一直加载,然后出现错误:
getaddrinfo ENOTFOUND dbrepmongotr
URI:
mongodb://localhost:27020/?readPreference=primary
和
mongodb://localhost:27020/?readPreference=secondary
如果我使用directConnection,它可以正常工作,但是当应用到带有密码等的数据库时,directConnection会跳过它们并连接,所以我们必须禁用directConnection。
我的docker文件:
FROM mongo:5.0.5
COPY mongod.conf /etc/mongod.conf
COPY keyfile.txt /etc/keyfile.txt
EXPOSE 27017
CMD ["mongod", "--config", "/etc/mongod.conf","--keyfile", "/etc/keyfile.txt"]
我的mongod.conf:
# mongod.conf
# network interfaces
net:
port: 27017
bindIp: 127.0.0.1,dbRepMongoTR2
#replication:
replication:
replSet: "myRs0"
#snmp:
security:
keyFile: /etc/keyfile.txt
我的docker-compose:
version: '3.5'
services:
dbRepMongoTR:
container_name: dbRepMongoTR
image: mongorep:3.3
ports:
- 27020:27017
restart: always
# volumes:
# - ./databdGR:/data/db
command: bin/sh -c "mongod --port 27017 --replSet myRs0 --bind_ip 127.0.0.1,dbRepMongoTR"
dbRepMongoTR2:
container_name: dbRepMongoTR2
image: mongorep:1.3
ports:
- 27021:27017
restart: always
# volumes:
# - ./databdGR:/data/db
command: bin/sh -c "mongod --port 27017 --replSet myRs0 --bind_ip 127.0.0.1,dbRepMongoTR2"
然后我进入mongosh中的dbRepMongoTR并执行:
rs.initiate( { _id: "myRs0", members: [{ _id: 0, host: "dbRepMongoTR" }, { _id: 1, host: "dbRepMongoTR2" }] })
rs.status()
英文:
I have a problem configuring the replication with mongo and docker, I can make the replication service work correctly, but if I try to connect with MongoCompass it keeps loading and then the error occurs:
getaddrinfo ENOTFOUND dbrepmongotr
URI:
mongodb://localhost:27020/?readPreference=primary
and
mongodb://localhost:27020/?readPreference=secondary
If I use directConnection if it leaves, but when applying it to a database with password and everything, the directConnection skips them and connects, so we must disable directConnection
my docker-file:
FROM mongo:5.0.5
COPY mongod.conf /etc/mongod.conf
COPY keyfile.txt /etc/keyfile.txt
EXPOSE 27017
CMD ["mongod", "--config", "/etc/mongod.conf","--keyfile", "/etc/keyfile.txt"]
My mongod.conf:
# mongod.conf
# network interfaces
net:
port: 27017
bindIp: 127.0.0.1,dbRepMongoTR2
#replication:
replication:
replSet: "myRs0"
#snmp:
security:
keyFile: /etc/keyfile.txt
My docker-compose:
version: '3.5'
services:
dbRepMongoTR:
container_name: dbRepMongoTR
image: mongorep:3.3
ports:
- 27020:27017
restart: always
# volumes:
# - ./databdGR:/data/db
command: bin/sh -c "mongod --port 27017 --replSet myRs0 --bind_ip 127.0.0.1,dbRepMongoTR"
dbRepMongoTR2:
container_name: dbRepMongoTR2
image: mongorep:1.3
ports:
- 27021:27017
restart: always
# volumes:
# - ./databdGR:/data/db
command: bin/sh -c "mongod --port 27017 --replSet myRs0 --bind_ip 127.0.0.1,dbRepMongoTR2"
Then I go to dbRepMongoTR in mongosh and execute:
rs.initiate( { _id: "myRs0", members: [{ _id: 0, host: "dbRepMongoTR" }, { _id: 1, host: "dbRepMongoTR2" }] })
rs.status()
答案1
得分: 0
没有directCOnnection
是不可能的,大部分问题可以通过以下方式解决:
command: '/bin/sh -c "mongod --auth --dbpath /data/db --storageEngine wiredTiger --keyFile /etc/keyfile.txt --replSet myRsGr --bind_ip 127.0.0.1,dbCodesaMongoGR"'
英文:
It's not possible without directCOnnection
, much of it can be fixed using:
command: '/bin/sh -c "mongod --auth --dbpath /data/db --storageEngine wiredTiger --keyFile /etc/keyfile.txt --replSet myRsGr --bind_ip 127.0.0.1,dbCodesaMongoGR"'
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论