##搭建副本集
10.127.32.121 master
10.127.32.125 slave arbiter
##数据库安装
略
##初始化主库配置
10.127.32.121
[root@node1 ~]# mkdir -p /home/mongodb/master/data
[root@node1 ~]# mkdir -p /home/mongodb/master/log
[root@node1 ~]# mongod --port 27017 --fork --replSet=replica --logpath=/home/mongodb/master/log/mongodb.log --logappend --dbpath=/home/mongodb/master/data/
use dbtest
for (i=0;i<=10000;i++){db.t1.insert({id:i})}
##初始化备库配置
10.127.32.125
[root@node2 bin]# mkdir -p /home/mongodb/slave/data/
[root@node2 bin]# mkdir -p /home/mongodb/slave/log
[root@node2 bin]# mkdir -p /home/mongodb/arbiter/data/
[root@node2 bin]# mkdir -p /home/mongodb/arbiter/log
[root@node2 bin]# mongod --port 27017 --fork --replSet=replica --logpath=/home/mongodb/slave/log/mongodb.log --logappend --dbpath=/home/mongodb/slave/data/
[root@node2 bin]# mongod --port 27018 --fork --replSet=replica --logpath=/home/mongodb/arbiter/log/mongodb.log --logappend --dbpath=/home/mongodb/arbiter/data/
##配置副本集
10.127.32.121
config={"_id":"replica","members":[
{"_id":1,"host":"10.127.32.121:27017"},
{"_id":2,"host":"10.127.32.125:27017"},
{"_id":3,"host":"10.127.32.125:27018",arbiterOnly:true}]
}
rs.initiate(config)
##测试副本集
rs.isMaster()
rs.status()
use dbtest
for (i=10001;i<=20000;i++){db.t1.insert({id:i})}
db.printSlaveReplicationInfo() ##查看slave 同步状态
10.127.32.121 master
10.127.32.125 slave arbiter
##数据库安装
略
##初始化主库配置
10.127.32.121
[root@node1 ~]# mkdir -p /home/mongodb/master/data
[root@node1 ~]# mkdir -p /home/mongodb/master/log
[root@node1 ~]# mongod --port 27017 --fork --replSet=replica --logpath=/home/mongodb/master/log/mongodb.log --logappend --dbpath=/home/mongodb/master/data/
use dbtest
for (i=0;i<=10000;i++){db.t1.insert({id:i})}
##初始化备库配置
10.127.32.125
[root@node2 bin]# mkdir -p /home/mongodb/slave/data/
[root@node2 bin]# mkdir -p /home/mongodb/slave/log
[root@node2 bin]# mkdir -p /home/mongodb/arbiter/data/
[root@node2 bin]# mkdir -p /home/mongodb/arbiter/log
[root@node2 bin]# mongod --port 27017 --fork --replSet=replica --logpath=/home/mongodb/slave/log/mongodb.log --logappend --dbpath=/home/mongodb/slave/data/
[root@node2 bin]# mongod --port 27018 --fork --replSet=replica --logpath=/home/mongodb/arbiter/log/mongodb.log --logappend --dbpath=/home/mongodb/arbiter/data/
##配置副本集
10.127.32.121
config={"_id":"replica","members":[
{"_id":1,"host":"10.127.32.121:27017"},
{"_id":2,"host":"10.127.32.125:27017"},
{"_id":3,"host":"10.127.32.125:27018",arbiterOnly:true}]
}
rs.initiate(config)
##测试副本集
rs.isMaster()
rs.status()
use dbtest
for (i=10001;i<=20000;i++){db.t1.insert({id:i})}
db.printSlaveReplicationInfo() ##查看slave 同步状态
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/27067062/viewspace-2084540/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/27067062/viewspace-2084540/