【问题标题】:MongoDB v4.0.0 Replica Configuration failed to SetupMongoDB v4.0.0 副本配置设置失败
【发布时间】:2018-12-14 10:48:41
【问题描述】:

我正在尝试在 3 台安装了 MongoDB v4.0.0 的机器(操作系统 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 配置如下...

mongod.conf 192.168.10.158

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

mongod.conf 192.168.10.124

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

mongod.conf 192.168.10.125

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。

现在我想知道以下事情......

  1. 我所遵循的步骤对于 MongoDB V4 是否正确?
  2. 当我使用 shell 命令mongo 连接到 mongo 时重新启动后。在所有三个实例中显示为rs-test:PRIMARY>。 (根据参考资料,有一个主要的,另外两个是次要的)。那么这里有什么问题呢?
  3. 当我尝试使用 rs.initiate() 在一台机器中启动副本集时。它返回我以下错误消息...
{
  "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)
      }
  }
}

任何帮助将不胜感激。

【问题讨论】:

  • 我已经做了三处更改,现在它正在工作... 1)清除所有三台机器中的 /var/lib/mongodb 目录 2)更新 /etc/mongod.conf 并从中删除 127.0.0.1绑定IP(我认为没有必要)。 3)副本集名称加双引号,即“rs-test”

标签: mongodb mongodb-replica-set


【解决方案1】:

我做了三处更改,现在它正在工作......

  1. 清除所有三台机器中的 /var/lib/mongodb 目录
  2. 更新 /etc/mongod.conf(我认为没有必要)并从 bind Ip 中删除 127.0.0.1(仅表示 bind Ip 字段中的 localIp 或 LiveIp)并在双引号中添加副本集名称,即“rs-test” .

然后重新启动所有三个 MongoDB 实例并将以下命令添加到 192.168.10.158 DB 以使其成为主数据库。

rs.initiate()
rs.add("dell-1080x2")
rs.add("vivek-pc")

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-13
    • 1970-01-01
    • 2013-10-22
    • 2015-09-17
    • 1970-01-01
    相关资源
    最近更新 更多