Welcome 微信登录

首页 / 数据库 / MySQL / MongoDB副本集搭建以及增减机器

1. replica set每个副本集需要设置副本集名称。在启动MongoDB时指定。2. 搭建步骤2.1 启动首先启动MongoDB启动时设置为副本集模式,并设置名称。两种方式,通过配置文件,或命令行模式。配置文件:01.# mongodb.conf 
02. 
03.replSet = replsetname 命令行模式:mongod --replSet "replsetname" 2.2 mongo shell打开mongo shell$ ./bin/mongo 2.3 初始化在mongo shell中Use rs.initiate():初始化副本集。> rs.initiate(): 2.4 验证验证初始化是否成功。> rs.conf(); 返回如下结果。01.{ 
02. "_id" : "replsetname", 
03. "version" : 1, 
04. "members" : [ 
05.      { 
06.       "_id" : 1, 
07.       "host" : "mongodb0.example.net:27017" 
08.      } 
09. ] 
10.} 2.5 增加一个实例使用rs.add增加实例> rs.add("mongodb1.example.net") 3. 查看副本集状态通过下面命令查看> rs.status()  返回下面信息。01.{ 
02.     "set" : "replisetname", 
03.     "date" : ISODate("2014-08-23T07:43:51Z"), 
04.     "myState" : 2, 
05.     "members" : [ 
06.             { 
07.                     "_id" : 0, 
08.                     "name" : "mongodb0.example.net:2701", 
09.                     "health" : 1, 
10.                     "state" : 2, 
11.                     "stateStr" : "SECONDARY", 
12.                     "uptime" : 3816405, 
13.                     "optime" : Timestamp(1408335342, 1), 
14.                     "optimeDate" : ISODate("2014-08-18T04:15:42Z"), 
15.                     "lastHeartbeat" : ISODate("2014-08-23T07:43:51Z"), 
16.                     "lastHeartbeatRecv" : ISODate("2014-08-23T07:43:50Z"), 
17.                     "pingMs" : 1, 
18.             }, 4. 删除一个节点删除使用removers.remove("mongod3.example.net:27017") --------------------------------------分割线 --------------------------------------CentOS编译安装MongoDB http://www.linuxidc.com/Linux/2012-02/53834.htmCentOS 编译安装 MongoDB与mongoDB的php扩展 http://www.linuxidc.com/Linux/2012-02/53833.htmCentOS 6 使用 yum 安装MongoDB及服务器端配置 http://www.linuxidc.com/Linux/2012-08/68196.htmUbuntu 13.04下安装MongoDB2.4.3 http://www.linuxidc.com/Linux/2013-05/84227.htmMongoDB入门必读(概念与实战并重) http://www.linuxidc.com/Linux/2013-07/87105.htm《MongoDB 权威指南》(MongoDB: The Definitive Guide)英文文字版[PDF] http://www.linuxidc.com/Linux/2012-07/66735.htm--------------------------------------分割线 --------------------------------------MongoDB 的详细介绍:请点这里
MongoDB 的下载地址:请点这里本文永久更新链接地址