1.mongoDB安装
https://docs.mongodb.com/manual/tutorial/install-mongodb-on-red-hat/
服务器 | IP | 端口 |
---|---|---|
server1 | 192.168.3.131 | 27017 |
server2 | 192.168.3.132 | 27017 |
server3 | 192.168.3.133 | 27017 |
2.mongoDB配置
在每一台服务器上配置/etc/mongod.conf
net:
port: 27017
bindIp: 0.0.0.0 # Enter 0.0.0.0,:: to bind to all IPv4 and IPv6 addresses or, alternatively, use the net.bindIpAll setting.
replication:
replSetName: myRepl
3.设置mongo复制集
3.1 登录任意一台mongo:
mongo
3.2 准备脚本:
rs.initiate({_id:'myRepl',members:[{_id:0,host:'192.168.3.131