基本信息配置

1
2
master:192.168.137.10
slave:192.168.137.11

master上配置

1
2
3
4
5
6
7
8
9
10
11
12
13
cat <<eof sudo tee /usr/local/mongodb/bin/mongodb.conf
dbpath = /usr/local/mongodb/db
logpath = /usr/local/mongodb/logs/mongodb.log
port = 27710
bind_ip = 0.0.0.0
maxConns = 500
noauth = true
logappend = true
quiet = true
fork = true
master = true
#nohttpinterface = true
eof

slave上配置

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
cat <<eof > /usr/local/mongodb/bin/mongodb.conf
dbpath = /usr/local/mongodb/db
logpath = /usr/local/mongodb/logs/mongodb.log
port = 27710
bind_ip = 0.0.0.0
maxConns = 500
noauth = true
logappend = true
quiet = true
fork = true
#master = true
slave = true
source = 192.168.137.10:27710
#nohttpinterface = true
eof

测试:在主上随便创建一个集合,再到从上查看是否有数据

master
1
2
3
4
5
6
[root@localhost src]# /usr/local/mongodb/bin/mongo --port 27717
> db.foo.save({'name':'neo','address':{'city':'shenzhen','post':518000},'phone':[13113668890,13322993040]})
WriteResult({ "nInserted" : 1 })
> db.foo.find();
{ "_id" : ObjectId("5a1855fc0455fff1624aeb9c"), "name" : "neo", "address" : { "city" : "shenzhen", "post" : 518000 }, "phone" : [ 13113668890, 13322993040 ] }

slave
1
2
> db.foo.find();
{ "_id" : ObjectId("5a1855fc0455fff1624aeb9c"), "name" : "neo", "address" : { "city" : "shenzhen", "post" : 518000 }, "phone" : [ 13113668890, 13322993040 ] }
出现数据一致表示成功