mkdir -p /opt/mongo/replica_sets/myrs_27017/log & mkdir -p /opt/mongo/replica_sets/myrs_27017/data/db
vim mongod.conf
systemLog:
destination: file
path: /opt/mongo/replica_sets/myrs_27017/log/mongod.log
logAppend: true
storage:
dbPath: /opt/mongo/replica_sets/myrs_27017/data/db
journal:
enabled: true
processManagement:
fork: true
pidFilePath: /opt/mongo/replica_sets/myrs_27017/log/mongod.pid
net:
bindIp: 192.168.0.253
port: 27017
replication:
replSetName: myrs
mkdir -p /opt/mongo/replica_sets/myrs_27018/log & mkdir -p /opt/mongo/replica_sets/myrs_27018/data/db
vim mongod.conf
systemLog:
destination: file
path: /opt/mongo/replica_sets/myrs_27018/log/mongod.log
logAppend: true
storage:
dbPath: /opt/mongo/replica_sets/myrs_27018/data/db
journal:
enabled: true
processManagement:
fork: true
pidFilePath: /opt/mongo/replica_sets/myrs_27018/log/mongod.pid
net:
bindIp: 192.168.0.253
port: 27018
replication:
replSetName: myrs
mkdir -p /opt/mongo/replica_sets/myrs_27019/log & mkdir -p /opt/mongo/replica_sets/myrs_27019/data/db
vim mongod.conf
systemLog:
destination: file
path: /opt/mongo/replica_sets/myrs_27019/log/mongod.log
logAppend: true
storage:
dbPath: /opt/mongo/replica_sets/myrs_27019/data/db
journal:
enabled: true
processManagement:
fork: true
pidFilePath: /opt/mongo/replica_sets/myrs_27019/log/mongod.pid
net:
bindIp: 192.168.0.253
port: 27019
replication:
replSetName: myrs
mongo --host=192.168.0.253 --port=27017
rs.initiate()
rs.conf()
rs.status()
rs.add("192.168.0.253:27018")
rs.status()
rs.addArb("192.168.0.253:27019")
rs.status()
db.comment.insert({"articleid":"100000","content":"今天天气真好,阳光明媚","userid":"1001","nickname":"Rose","createdatetime":new Date()})
db.comment.find()
mongo --host=192.168.0.253 --port=27018
rs.slaveOk()
show dbs
use articledb
db.comment.find()
db.comment.insert({"_id":"1","articleid":"100001","content":"我们不应该把清晨浪费在手机上,健康很重要,k一杯温水幸福你我他。","userid":"1002","nickname":"相忘于江湖","createdatetime":new Date("2019-08-05T22:08:15.522Z"),"likenum":NumberInt(1000),"state":"1"})
mongo --host=192.168.0.253 --port=27019