一.创建目录
1.mkdir -p /home/mongodb/data/master
2.mkdir -p /home/mongodb/data/slaver
3.mkdir -p /home/mongodb/data/arbiter
二.配置文件
1.创建master.conf文件
#master.conf
dbpath=/home/mongodb/data/master
logpath=/home/mongodb/log/master.log
pidfilepath=/home/mongodb/master.pid
directoryperdb=true
logappend=true
replSet=testrs
bind_ip=192.168.1.4
port=27017
oplogSize=10000
fork=true
noprealloc=true
2.创建arbiter.conf文件
#arbiter.conf
dbpath=/home/mongodb/data/arbiter
logpath=/home/mongodb/log/arbiter.log
pidfilepath=/home/mongodb/arbiter.pid
directoryperdb=true
logappend=true
replSet=testrs
bind_ip=192.168.1.12
port=27017
oplogSize=10000
fork=true
noprealloc=true
3.创建slaver.conf文件
#slaver.conf
dbpath=/home/mongodb/data/slaver
logpath=/home/mongodb/log/slaver.log
pidfilepath=/home/mongodb/slaver.pid
directoryperdb=true
logappend=true
replSet=testrs
bind_ip=192.168.1.11
port=27017
oplogSize=10000
fork=true
noprealloc=true
三.启动命令
- cd /home/mongodb/bin
- ./mongod -f /home/mongodb/master.conf
- ./mongod –fork –dbpath /home/mongodb/db –logpath /home/mongodb/log/set1.log –replSet test
- ./mongod –fork –dbpath /home/mongodb/db –logpath /home/mongodb/log/set1.log –replSet test
- ./mongod –fork –dbpath /home/mongodb/db –logpath /home/mongodb/log/set1.log –replSet test
- ./mongo 192.168.1.4:27017
四.实战
1.工程配置
2.部分核心代码
原创文章,作者:kepupublish,如若转载,请注明出处:https://blog.ytso.com/193971.html