环境:Linux,数据库:mongodb,集群:Replication Sets,三台云服务器
1、三台服务器都安装mongodb,并配置启动文件mongodb.conf
bind_ip = 101.102.80.74
port = 27017
fork = true
pidfilepath = /home/worker/data/mongodb/mongodb.pid
logpath = /home/worker/data/mongodb/log/mongodb.log
dbpath = /home/worker/data/mongodb/data
replSet = replSet
nojournal = true
logappend = true
2、三台服务器通过配置文件启动mongod
./bin/mongod -f mongodb.conf
3、任意一台,客户端连接
./bin/mongo 101.102.80.74
4、配置Replication Sets
编辑json文档config={_id:"replSet",members:[{_id:0,host:"101.102.80.74:27017",priority:4},{_id:1,host:"101.102.80.75:27017",priority:2}]}
initiate配置,启动集群:rs.initiate(config)
查看启动结果:rs.status()
5、添加仲裁服务器
use admin——>rs.addArb("101.102.80.76:27017")
注意事项:1、mongodb数据库必须为空;2、客户端连接ip必须和配置文件ip一致
用到mongod关闭命令:1、use admin——>db.shutdownServer();2、./bin/mongod --shutdown --dbpath /home/worker/data/mongodb/data