使用单机部署为副本集(开启oplog.rs)
环境:
OS:Centos 7
mongodb:5.0.19
mongodb单机环境下是没有oplog.rs,是否有办法在单机环境下也生成oplog.rs呢,答案是可以的,就是使用单机部署副本集.
1.修改配置文件加上副本集的配置
[root@localhost conf]# more mongo.cnf
port=29001
fork=true
dbpath=/home/middle/mongodb/data
logpath=/home/middle/mongodb/log/mongodb.log
pidfilepath=/home/middle/mongodb/run/29001.pid
logappend=true
replSet=s1
bind_ip=192.168.1.105,127.0.0.1
oplogSize=16384
logRotate=reopen
yaml格式的配置文件
[root@localhost conf]# more mongo_yaml.cnf
net:
bindIp: 192.168.1.108,127.0.0.1
port: 29001
storage:
journal:
enabled: true
dbPath: "/home/middle/mongodb/data"
engine: wiredTiger
wiredTiger:
engineConfig:
cacheSizeGB: 1
systemLog:
destination: file
path: "/home/middle/mongodb/log/mongodb.log"
logAppend: true
logRotate: reopen
processManagement:
fork: true
pidFilePath: "/home/middle/mongodb/run/29001.pid"
replication:
oplogSizeMB: 16384
replSetName: s1
security:
keyFile: "/home/middle/mongodb/key/keyfile"
authorization: "disabled"
[root@localhost mongodb]# cd /home/middle/mongodb/key
[root@localhost key]# openssl rand -base64 741 >>keyfile
[root@localhost key]# chmod 700 keyfile
说明:
a. key是区分大小写的,严格按照官网的配置项进行配置,不要想当然的全部转换成小写或是大写
b. 缩进要统一,比如我这里是2个空格进行缩进,不能使用tab键
c. key: value形式的,value前面需要带上空格
参考文档:
https://www.mongodb.com/docs/v4.2/reference/configuration-options/
2.单机配置为副本集
use admin
config={_id:'s1',members:[{_id:0,host:'192.168.1.105:29001'}]}
rs.initiate(config)
3.查看
s1:PRIMARY> use local
s1:PRIMARY> show tables
oplog.rs
replset.election
replset.initialSyncId
replset.minvalid
replset.oplogTruncateAfterPoint
startup_log
system.replset
system.rollback.id
system.tenantMigration.oplogView
system.views
这样就有oplog.rs了.