ITPub博客

首页 > 数据库 > NoSQL > MongoDB单机开启oplog

MongoDB单机开启oplog

原创 NoSQL 作者:chenoracle 时间:2023-02-08 17:28:25 0 删除 编辑

修改参数文件

[mongo@cjc-db-01 conf]$ vi mongodb.conf

###新增

replSet = cjcMongodb

重启mongodb

停

> use admin;
switched to db admin
> db.shutdownServer();

启

[mongo@cjc-db-01 ~]$ cd /mongodb/27017/conf/
[mongo@cjc-db-01 conf]$ mongod -f mongodb.conf

查询

[mongo@cjc-db-01 conf]$ mongo --port 27017
> show dbs;
2023-02-08T17:15:54.317+0800 E QUERY    [js] Error: listDatabases failed:{
"ok" : 0,
"errmsg" : "not master and slaveOk=false",
"code" : 13435,
"codeName" : "NotMasterNoSlaveOk"
} :
_getErrorWithCode@src/mongo/shell/utils.js:25:13
Mongo.prototype.getDBs@src/mongo/shell/mongo.js:151:1
shellHelper.show@src/mongo/shell/utils.js:882:13
shellHelper@src/mongo/shell/utils.js:766:15
@(shellhelp2):1:1

初始化

> rs.initiate();
{
"info2" : "no configuration specified. Using a default configuration for the set",
"me" : "cjc-db-01:27017",
"ok" : 1
}

再次查询

cjcMongodb:SECONDARY> show dbs;
admin   0.000GB
cjcdb   0.000GB
config  0.000GB
local   0.000GB

cjcMongodb:PRIMARY> use local
switched to db local

cjcMongodb:PRIMARY> show tables;
oplog.rs
replset.election
replset.minvalid
replset.oplogTruncateAfterPoint
startup_log
system.replset
system.rollback.id

Oplog 存储在 local 库的 oplog.rs 集合里面

cjcMongodb:PRIMARY> db.oplog.rs.find();
{ "ts" : Timestamp(1675847798, 1), "h" : NumberLong("-4142341003137703290"), "v" : 2, "op" : "n", "ns" : "", "wall" : ISODate("2023-02-08T09:16:38.168Z"), "o" : { "msg" : "initiating set" } }
{ "ts" : Timestamp(1675847798, 3), "t" : NumberLong(1), "h" : NumberLong("-8128858175787158320"), "v" : 2, "op" : "n", "ns" : "", "wall" : ISODate("2023-02-08T09:16:38.174Z"), "o" : { "msg" : "new primary" } }
{ "ts" : Timestamp(1675847798, 4), "t" : NumberLong(1), "h" : NumberLong("2262279575084486449"), "v" : 2, "op" : "c", "ns" : "config.$cmd", "ui" : UUID("e1b444f6-20e3-4695-8ddb-45011cde7906"), "wall" : ISODate("2023-02-08T09:16:38.191Z"), "o" : { "create" : "image_collection", "idIndex" : { "v" : 2, "key" : { "_id" : 1 }, "name" : "_id_", "ns" : "config.image_collection" } } }
{ "ts" : Timestamp(1675847798, 5), "t" : NumberLong(1), "h" : NumberLong("-7259636297367536820"), "v" : 2, "op" : "c", "ns" : "config.$cmd", "ui" : UUID("4286a448-9182-44a6-b1fc-7ab1b0e79f1d"), "wall" : ISODate("2023-02-08T09:16:38.206Z"), "o" : { "create" : "transactions", "idIndex" : { "v" : 2, "key" : { "_id" : 1 }, "name" : "_id_", "ns" : "config.transactions" } } }
......
{ "ts" : Timestamp(1675847938, 1), "t" : NumberLong(1), "h" : NumberLong("-2455973444836006621"), "v" : 2, "op" : "n", "ns" : "", "wall" : ISODate("2023-02-08T09:18:58.251Z"), "o" : { "msg" : "periodic noop" } }
......
cjcMongodb:PRIMARY> 
cjcMongodb:PRIMARY>

查看Oplog状态

cjcMongodb:PRIMARY> rs.printReplicationInfo()
configured oplog size:   2654.523241996765MB
log length start to end: 550secs (0.15hrs)
oplog first event time:  Wed Feb 08 2023 17:16:38 GMT+0800 (CST)
oplog last event time:   Wed Feb 08 2023 17:25:48 GMT+0800 (CST)
now:                     Wed Feb 08 2023 17:25:51 GMT+0800 (CST)

###chenjuchao 20230208###

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/29785807/viewspace-2934443/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论
Oracle ACE、OCMU 用户组成员、Oracle 11g OCM、微信公众号"IT小Chen"

注册时间:2014-08-05

  • 博文量
    853
  • 访问量
    2726978