Mongodb 复制集中一个 mongod 挂掉后机器起不来,处理方法

本贴最后更新于 1266 天前,其中的信息可能已经时异事殊

199宕机。数据无法恢复。
1.将同是shard2的201上的数copy过来。copy之前先停止更新数据。
2.找到剩下的两台机器那个是PRIMARY。在PRIMARY上执行如下操作。
[liyan@cnews197 ~]$ cd /data/support/mongodb-2.0.2/bin
[liyan@cnews197 bin]$ ./mongo -port 15552
MongoDB shell version: 2.0.2
connecting to: 127.0.0.1:15552/test
PRIMARY> rs.status()
{
        "set" : "shard2",
        "date" : ISODate("2017-11-15T08:51:32Z"),
        "myState" : 1,
        "members" : [
                {
                        "_id" : 0,
                        "name" : "10.70.56.199:15552",
                        "health" : 0,
                        "state" : 8,
                        "stateStr" : "(not reachable/healthy)",
                        "uptime" : 0,
                        "optime" : {
                                "t" : 1510342250000,
                                "i" : 1
                        },
                        "optimeDate" : ISODate("2017-11-10T19:30:50Z"),
                        "lastHeartbeat" : ISODate("2017-11-10T19:31:16Z"),
                        "pingMs" : 0,
                        "errmsg" : "socket exception"
                },
                {
                        "_id" : 1,
                        "name" : "10.70.56.201:15552",
                        "health" : 1,
                        "state" : 2,
                        "stateStr" : "SECONDARY",
                        "uptime" : 88,
                        "optime" : {
                                "t" : 1510735865000,
                                "i" : 1
                        },
                        "optimeDate" : ISODate("2017-11-15T08:51:05Z"),
                        "lastHeartbeat" : ISODate("2017-11-15T08:51:30Z"),
                        "pingMs" : 0
                },
                {
                        "_id" : 2,
                        "name" : "10.70.56.197:15552",
                        "health" : 1,
                        "state" : 1,
                        "stateStr" : "PRIMARY",
                        "optime" : {
                                "t" : 1510735865000,
                                "i" : 1
                        },
                        "optimeDate" : ISODate("2017-11-15T08:51:05Z"),
                        "self" : true
                }
        ],
        "ok" : 1
}
PRIMARY> rs.remove('10.70.56.199:15552')// 删除旧的mongod
Wed Nov 15 16:53:57 DBClientCursor::init call() failed
Wed Nov 15 16:53:57 query failed : admin.$cmd { replSetReconfig: { _id: "shard2", version: 2, members: [ { _id: 1, host: "10.70.56.201:15552" }, { _id: 2, host: "10.70.56.197:15552" } ] } } to: 127.0.0.1:15552
Wed Nov 15 16:53:57 Error: error doing query: failed shell/collection.js:151
Wed Nov 15 16:53:57 trying reconnect to 127.0.0.1:15552
Wed Nov 15 16:53:57 reconnect 127.0.0.1:15552 ok
                                       
PRIMARY> rs.status() //查看结果
{
        "set" : "shard2",
        "date" : ISODate("2017-11-15T08:54:07Z"),
        "myState" : 1,
        "members" : [
                {
                        "_id" : 1,
                        "name" : "10.70.56.201:15552",
                        "health" : 1,
                        "state" : 2,
                        "stateStr" : "SECONDARY",
                        "uptime" : 8,
                        "optime" : {
                                "t" : 1510736036000,
                                "i" : 1
                        },
                        "optimeDate" : ISODate("2017-11-15T08:53:56Z"),
                        "lastHeartbeat" : ISODate("2017-11-15T08:54:05Z"),
                        "pingMs" : 0,
                        "errmsg" : "syncThread: 10278 dbclient error communicating with server: 10.70.56.197:15552"
                },
                {
                        "_id" : 2,
                        "name" : "10.70.56.197:15552",
                        "health" : 1,
                        "state" : 1,
                        "stateStr" : "PRIMARY",
                        "optime" : {
                                "t" : 1510736037000,
                                "i" : 1
                        },
                        "optimeDate" : ISODate("2017-11-15T08:53:57Z"),
                        "self" : true
                }
        ],
        "ok" : 1
}
PRIMARY> rs.add('10.70.56.196:15552')// 添加新的mongod
{ "ok" : 1 }
                                  
PRIMARY> rs.status() //
{
        "set" : "shard2",
        "date" : ISODate("2017-11-15T08:54:41Z"),
        "myState" : 1,
        "members" : [
                {
                        "_id" : 1,
                        "name" : "10.70.56.201:15552",
                        "health" : 1,
                        "state" : 2,
                        "stateStr" : "SECONDARY",
                        "uptime" : 42,
                        "optime" : {
                                "t" : 1510736078000,
                                "i" : 1
                        },
                        "optimeDate" : ISODate("2017-11-15T08:54:38Z"),
                        "lastHeartbeat" : ISODate("2017-11-15T08:54:39Z"),
                        "pingMs" : 0
                },
                {
                        "_id" : 2,
                        "name" : "10.70.56.197:15552",
                        "health" : 1,
                        "state" : 1,
                        "stateStr" : "PRIMARY",
                        "optime" : {
                                "t" : 1510736078000,
                                "i" : 1
                        },
                        "optimeDate" : ISODate("2017-11-15T08:54:38Z"),
                        "self" : true
                },
                {
                        "_id" : 3,
                        "name" : "10.70.56.196:15552",
                        "health" : 1,
                        "state" : 2,
                        "stateStr" : "SECONDARY",
                        "uptime" : 3,
                        "optime" : {
                                "t" : 1510730231000,
                                "i" : 1
                        },
                        "optimeDate" : ISODate("2017-11-15T07:17:11Z"),
                        "lastHeartbeat" : ISODate("2017-11-15T08:54:40Z"),
                        "pingMs" : 163
                }
        ],
        "ok" : 1
}

  • MongoDB

    MongoDB(来自于英文单词“Humongous”,中文含义为“庞大”)是一个基于分布式文件存储的数据库,由 C++ 语言编写。旨在为应用提供可扩展的高性能数据存储解决方案。MongoDB 是一个介于关系数据库和非关系数据库之间的产品,是非关系数据库当中功能最丰富,最像关系数据库的。它支持的数据结构非常松散,是类似 JSON 的 BSON 格式,因此可以存储比较复杂的数据类型。

    82 引用 • 53 回帖 • 2 关注

广告 我要投放

欢迎来到这里!

我们正在构建一个小众社区,大家在这里相互信任,以平等 • 自由 • 奔放的价值观进行分享交流。最终,希望大家能够找到与自己志同道合的伙伴,共同成长。

注册 关于
请输入回帖内容 ...