MongoDB replication (1)

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:   192MB
log 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

  • 3
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值