Deploy a replica set

A three-member replica set 

Deploy a replica set_第1张图片

server info: scdbm06~08

mongodb info: mongodb-linux-x86_64-2.6.6.tgz
 
1. 在On scdbm06上创建存放data和log的文件夹

mkdir -p /mongodb/data

mkdir -p /mongodb/log

上传文件到 /mongodb

2. On scdbm06 

cd /mongodb

tar –zxvf  mongodb-linux-x86_64-2.6.6.tgz

3. On scdbm07~8 copy 解压的mongodb文件

scp -r root@scdbm06:/mongodb     /

4. On scdbm06~08 启动mongod

/mongodb/mongodb-linux-x86_64-2.6.6/bin/mongod --fork   --port 27017 --dbpath /mongodb/data  --logpath=/mongodb/log/mongodb.log  --replSet repset --smallfiles --oplogSize 128  --httpinterface 

5.  On scdbm06 Connect a mongo shell to a replica set member.

/mongodb/mongodb-linux-x86_64-2.6.6/bin/mongo --port 27017

6. On scdbm06 Initiate the replica set.

Use rs.initiate() on the replica set member:

rs.initiate()

7. On scdbm06 Verify the initial replica set configuration.

Use rs.conf() to display the replica set configuration object:

rs.conf()

8. On scdbm06 Add the remaining members to the replica set.

Add the remaining members with the rs.add() method.

The following example adds two members:

rs.add("scdbm07")

rs.add("scdbm08")

9. On scdbm06 Check the status of the replica set.

Use the rs.status() operation:

rs.status()

--ps -aux | grep mongodb

 

上面的(6.7.8)可以使用下面的代替

 use admin

config = { _id:"repset", members:[

 {_id:0,host:"scdbm06:27017"},

 {_id:1,host:"scdbm07:27017"},

 {_id:2,host:"scdbm08:27017"}]

 }

rs.initiate(config);

/* 

*关闭 mongod 

/mongodb/mongodb-linux-x86_64-2.6.6/bin/mongod --fork   --port 27017 --dbpath /mongodb/data  --logpath=/mongodb/log/mongodb.log  --replSet repset --smallfiles --oplogSize 128  --httpinterface --shutdown

*/

 

你可能感兴趣的:(Deploy a replica set)