【问题标题】:Create replica set for MongoDB in Linux在 Linux 中为 MongoDB 创建副本集
【发布时间】:2015-06-24 14:48:55
【问题描述】:

当我运行以下命令时:rs.initiate(),

我收到以下错误:

"info2" : "no configuration explicitly specified -- making one",
        "me" : "ip-10-0-2-113:27017",
        "ok" : 0,
        "errmsg" : "No host described in new configuration 1 for replica set s-1-rs maps to this node",
        "code" : 93

我只是在本地主机上运行。我正在关注本指南:http://docs.mongodb.org/manual/tutorial/convert-standalone-to-replica-set/

我只是跳过了他们命名副本集的部分。

无论如何,我该如何创建副本集,我做错了什么?

谢谢

【问题讨论】:

标签: linux mongodb mongodb-query database-replication replicaset


【解决方案1】:

给出在本地启动 mongo 复制的整个过程。将来可能会对某人有所帮助。

为三个 mongod 进程创建三个目录。在 unix 上,可以这样做:

mkdir -p /data/rs1 /data/rs2 /data/rs3

现在如下启动三个 mongo 实例。请注意,这是三个命令。

mongod --replSet s1 --logpath "1.log" --dbpath /data/rs1 --port 27017 --smallfiles --oplogSize 64 --fork

mongod --replSet s1 --logpath "2.log" --dbpath /data/rs2 --port 27018 --smallfiles --oplogSize 64 --fork

mongod --replSet s1 --logpath "3.log" --dbpath /data/rs3 --port 27019 --smallfiles --oplogSize 64 --fork

创建 s1 的副本集。

现在连接到一个 mongo shell。

mongo --port 27017

现在您将创建副本集。在 mongo shell 中输入以下命令:

config = { _id: "s1", members:[
          { _id : 0, host : "localhost:27017"},
          { _id : 1, host : "localhost:27018"},
          { _id : 2, host : "localhost:27019"} ]
};
rs.initiate(config);

您的副本集由此启动。您可以通过以下方式检查复制状态:

rs.status()

【讨论】:

    【解决方案2】:
    -- Replace your data and installation location accordingly.
    rm -rf ~/tmp/mongo_data
    mkdir -p ~/tmp/mongo_data/rs0_1 ~/tmp/mongo_data/rs0_2 ~/tmp/mongo_data/rs0_3  
    
    nohup ~/Softwares/mongodb/bin/mongod --port 27017 --dbpath ~/tmp/mongo_data/rs0_1 --replSet rs0 &
    nohup ~/Softwares/mongodb/bin/mongod --port 27018 --dbpath ~/tmp/mongo_data/rs0_2 --replSet rs0 &
    nohup ~/Softwares/mongodb/bin/mongod --port 27019 --dbpath ~/tmp/mongo_data/rs0_3 --replSet rs0 &
    
    ~/Softwares/mongodb/bin/mongo --port 27017
    
    rsconf = {
           _id: "rs0",
           members: [
                      {
                       _id: 0,
                       host: "localhost:27017"
                      }
                    ]
         }
    
    rs.initiate(rsconf)
    rs.conf()
    
    
    rs.add("localhost:27018")
    rs.add("localhost:27019")
    
    rs.status()
    

    【讨论】:

      猜你喜欢
      • 2013-10-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-12-13
      • 1970-01-01
      相关资源
      最近更新 更多