MongoDB replication (1)

来源:互联网 发布:软件小品 编辑:程序博客网 时间:2024/05/22 03:24

MongoDB replication (1)

> rs.initiate(){    "ok" : 0,    "errmsg" : "This node was not started with the replSet option",    "code" : 76,    "codeName" : "NoReplicationEnabled"}

启动时没有配置复制集,使用mongo –replSet <复制集名称> 启动。

> rs.initiate(){    "ok" : 0,    "errmsg" : "assertion src/mongo/db/repl/replset_commands.cpp:274",    "code" : 8,    "codeName" : "UnknownError"}

该行断言失败的原因:host不能配置为localhost。

Assertion failure h != "localhost" src/mongo/db/repl/replset_commands.cpp 274

此时,配置复制集信息:

> config = {_id:"rs0", members:[ {_id:0, host:"127.0.0.1:27017"}]}{    "_id" : "rs0",    "members" : [        {            "_id" : 0,            "host" : "127.0.0.1:27017"        }    ]}> rs.initiate(config){ "ok" : 1 }

或者:

rs0:PRIMARY> rs.add("localhost:27017")

现在执行rs0:PRIMARY> db.oplog.rs.find(),结果如下:

{ "ts" : Timestamp(1487582277, 1), "t" : NumberLong(1), "h" : NumberLong("1421023485009824583"), "v" : 2, "op" : "n", "ns" : "", "o" : { "msg" : "periodic noop" } }{ "ts" : Timestamp(1487582280, 1), "t" : NumberLong(1), "h" : NumberLong("353054299917983331"), "v" : 2, "op" : "c", "ns" : "test.$cmd", "o" : { "create" : "test", "idIndex" : { "v" : 2, "key" : { "_id" : 1 }, "name" : "_id_", "ns" : "test.test" } } }{ "ts" : Timestamp(1487582280, 2), "t" : NumberLong(1), "h" : NumberLong("3858332860662095118"), "v" : 2, "op" : "i", "ns" : "test.test", "o" : { "_id" : ObjectId("58aab4482f0f96c51f43205f"), "empno" : 100, "name" : 100, "address" : "it is a test!" } }

查看复制集状态:

rs0:PRIMARY> rs.printReplicationInfo()configured oplog size:   192MBlog length start to end: 811secs (0.23hrs)oplog first event time:  Mon Feb 20 2017 17:13:36 GMT+0800 (CST)oplog last event time:   Mon Feb 20 2017 17:27:07 GMT+0800 (CST)now:                     Mon Feb 20 2017 17:27:11 GMT+0800 (CST)

I

0 0
原创粉丝点击