注册 登录  
 加关注
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

PostgreSQL 中文网

 
 
 

日志

 
 

MongoDB:Replica Set 删除节点  

2012-11-27 16:25:14|  分类: MongoDB |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |

 

       上一篇 学习了 Replica Set  增加节点,继续学习删除节点。
      
       删除节点前最好是先关闭需要删除的节点,之后通过命令 rs.remove 来删除
 相应的节点,操作如下:
  
--1 查看当前 Replica Set 配置

 [mongo@redhatB mongodb]$ mongo 127.0.0.1:27018
MongoDB shell version: 2.2.1
connecting to: 127.0.0.1:27018/test
rs0:PRIMARY> rs.conf();
{
        "_id" : "rs0",
        "version" : 4,
        "members" : [
                {
                        "_id" : 0,
                        "host" : "redhatB.example.com:27018"
                },
                {
                        "_id" : 1,
                        "host" : "redhatB.example.com:27019"
                },
                {
                        "_id" : 2,
                        "host" : "redhatB.example.com:27020"
                },
                {
                        "_id" : 3,
                        "host" : "redhatB.example.com:27021"
                }
        ]
}
   
   备注:计划删除节点 "_id" : 3。


--2 关闭 27021 节点服务

 [mongo@redhatB data04]$ ps -ef | grep 27021
mongo    11733     1  0 21:03 ?        00:00:15 mongod -f /pgdata_xc/mongodb/data04/mongodb_27021.conf
mongo    14422  2953  0 21:53 pts/0    00:00:00 mongo 127.0.0.1:27021
mongo    14490  4027  0 21:54 pts/1    00:00:00 grep 27021
[mongo@redhatB data04]$ kill 11733
   


--3 查看 replica set 状态

 rs0:PRIMARY> rs.status();
{
        "set" : "rs0",
        "date" : ISODate("2012-11-22T13:57:15Z"),
        "myState" : 1,
        "members" : [
                {
                        "_id" : 0,
                        "name" : "redhatB.example.com:27018",
                        "health" : 1,
                        "state" : 1,
                        "stateStr" : "PRIMARY",
                        "uptime" : 21279,
                        "optime" : Timestamp(1353589624000, 1),
                        "optimeDate" : ISODate("2012-11-22T13:07:04Z"),
                        "self" : true
                },
                {
                        "_id" : 1,
                        "name" : "redhatB.example.com:27019",
                        "health" : 1,
                        "state" : 2,
                        "stateStr" : "SECONDARY",
                        "uptime" : 18908,
                        "optime" : Timestamp(1353589624000, 1),
                        "optimeDate" : ISODate("2012-11-22T13:07:04Z"),
                        "lastHeartbeat" : ISODate("2012-11-22T13:57:13Z"),
                        "pingMs" : 0
                },
                {
                        "_id" : 2,
                        "name" : "redhatB.example.com:27020",
                        "health" : 1,
                        "state" : 2,
                        "stateStr" : "SECONDARY",
                        "uptime" : 18900,
                        "optime" : Timestamp(1353589624000, 1),
                        "optimeDate" : ISODate("2012-11-22T13:07:04Z"),
                        "lastHeartbeat" : ISODate("2012-11-22T13:57:14Z"),
                        "pingMs" : 0
                },
                {
                        "_id" : 3,
                        "name" : "redhatB.example.com:27021",
                        "health" : 0,
                        "state" : 8,
                        "stateStr" : "(not reachable/healthy)",
                        "uptime" : 0,
                        "optime" : Timestamp(1353589624000, 1),
                        "optimeDate" : ISODate("2012-11-22T13:07:04Z"),
                        "lastHeartbeat" : ISODate("2012-11-22T13:55:20Z"),
                        "pingMs" : 0,
                        "errmsg" : "socket exception [CONNECT_ERROR] for redhatB.example.com:27021"
                }
        ],
        "ok" : 1
}

  备注:最后一个节点 stateStr 状态为 “not reachable/healthy”。
 
--4 删除节点

 rs0:PRIMARY> rs.remove("redhatB.example.com:27021");
Thu Nov 22 21:58:45 DBClientCursor::init call() failed
Thu Nov 22 21:58:45 query failed : admin.$cmd { replSetReconfig: { _id: "rs0", version: 5, members: [ { _id: 0, host: "redhatB.example.com:27018" }, { _id: 1, host: "redhatB.example.com:27019" }, { _id: 2, host: "redhatB.example.com:27020" } ] } } to: 127.0.0.1:27018
Thu Nov 22 21:58:45 Error: error doing query: failed src/mongo/shell/collection.js:155
Thu Nov 22 21:58:45 trying reconnect to 127.0.0.1:27018
Thu Nov 22 21:58:45 reconnect 127.0.0.1:27018 ok
rs0:SECONDARY>
rs0:PRIMARY>
   


--5 再次查看 replica set 配置

 rs0:PRIMARY> rs.conf();
{
        "_id" : "rs0",
        "version" : 5,
        "members" : [
                {
                        "_id" : 0,
                        "host" : "redhatB.example.com:27018"
                },
                {
                        "_id" : 1,
                        "host" : "redhatB.example.com:27019"
                },
                {
                        "_id" : 2,
                        "host" : "redhatB.example.com:27020"
                }
        ]
}
   
  备注:节点 "redhatB.example.com:27021" 已删除。

 

--6 删除旧结点数据目录

 [mongo@redhatB mongodb]$ rm -rf  /mongodb/data04 
   

--7  参考
http://docs.mongodb.org/manual/administration/replica-sets/#replica-set-admin-procedure-add-member
http://docs.mongodb.org/manual/reference/javascript/#rs.remove   
    

  评论这张
 
阅读(16974)| 评论(0)
推荐 转载

历史上的今天

在LOFTER的更多文章

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2016