我正在尝试在安装了MongoDB v4.0.0的3台机器(操作系统UbuntuMATE 18.04)中配置复制。
我正在使用Deploy a MongoDB Replica Set链接作为参考。并尝试进行如下配置...
步骤1: 使用本地IP和主机名更新所有三台计算机的主机文件 即
127.0.0.1 localhost
192.168.10.158 dell-Inspiron-15-7000-Gaming
192.168.10.125 dell-1080x2
192.168.10.124 vivek-pc
然后为我的/etc/mongod.conf的每台计算机配置如下...
storage:
dbPath: /var/lib/mongodb
journal:
enabled: true
# where to write logging data.
systemLog:
destination: file
logAppend: true
path: /var/log/mongodb/mongod.log
# network interfaces
net:
port: 27017
bindIp: 127.0.0.1, 192.168.10.158
# how the process runs
processManagement:
timeZoneInfo: /usr/share/zoneinfo
replication:
replSetName: rs-test
storage:
dbPath: /var/lib/mongodb
journal:
enabled: true
# where to write logging data.
systemLog:
destination: file
logAppend: true
path: /var/log/mongodb/mongod.log
# network interfaces
net:
port: 27017
bindIp: 127.0.0.1, 192.168.10.124
# how the process runs
processManagement:
timeZoneInfo: /usr/share/zoneinfo
replication:
replSetName: rs-test
storage:
dbPath: /var/lib/mongodb
journal:
enabled: true
# where to write logging data.
systemLog:
destination: file
logAppend: true
path: /var/log/mongodb/mongod.log
# network interfaces
net:
port: 27017
bindIp: 127.0.0.1, 192.168.10.125
# how the process runs
processManagement:
timeZoneInfo: /usr/share/zoneinfo
replication:
replSetName: rs-test
然后我重新启动了所有三个MongoDB。
现在我想了解以下内容...
mongo
连接到mongo时。在所有三个实例中,都显示为rs-test:PRIMARY>
。 (根据参考,有一个小学,另外两个是中学)。那么这是怎么了?{ "operationTime" : Timestamp(1544783790, 1), "ok" : 0, "errmsg" : "already initialized", "code" : 23, "codeName" : "AlreadyInitialized", "$clusterTime" : { "clusterTime" : Timestamp(1544783790, 1), "signature" : { "hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="), "keyId" : NumberLong(0) } } }
任何帮助将不胜感激。
答案 0 :(得分:0)
我进行了三处更改,现在可以使用...
然后重新启动所有三个MongoDB实例,并将以下命令添加到192.168.10.158 DB中使其成为主要实例。
rs.initiate()
rs.add("dell-1080x2")
rs.add("vivek-pc")