1、修改配置文件
增加以下配置:
replication:
oplogSizeMB: 128
replSetName: rs
security:
authorization: enabled
keyFile: /etc/mongo-keyfile
生成认证文件的方法 :
openssl rand -base64 90 -out /etc/mongo-keyfile
chmod 400 /etc/mongo-keyfile
chown mongod /etc/mongo-keyfile
2、重启并初始化
systemctl restart mongod
rs.initiate()
local库下的oplog.rs集合就是oplog日志
local> rs.initiate()
{
info2: 'no configuration specified. Using a default configuration for the set',
me: '127.0.0.1:27017',
ok: 1
}
rs [direct: other] local>
rs [direct: primary] local>
rs [direct: primary] local> show dbs;
admin 140.00 KiB
clc 40.00 KiB
config 176.00 KiB
local 308.00 KiB
rs [direct: primary] local> use local
already on db local
rs [direct: primary] local> show collections
oplog.rs
replset.election
replset.initialSyncId
replset.minvalid
replset.oplogTruncateAfterPoint
startup_log
system.replset
system.rollback.id
system.tenantMigration.oplogView [view]
system.views
rs [direct: primary] local>
原文链接:Mongodb单机版添加oplog,转载请注明来源!