Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to turn on Oplog in MongoDB

2025-04-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)05/31 Report--

This article introduces how to open Oplog in MongoDB, the content is very detailed, interested friends can use for reference, I hope it can be helpful to you.

Configuration process

In fact, the process of configuration is relatively simple.

Step 1: add a replica set parameter (replSet) to the configuration file

Step 2: restart the service

Step 3: execute the script to initialize the replica set in the local database or admin database, rs.initiate ().

Matters needing attention

1. Add the replica set parameter (replSet=??) to the configuration file ), restart the MongoDB instance, log in for the first time, and execute other commands (for example, show dbs). The error message is as follows.

{"ok": 0, "errmsg": "not master and slaveOk=false", "code": 13435, "codeName": "NotMasterNoSlaveOk"}

Be sure to execute the initialization command at this point:

Rs.initiate ({_ id: "replica set name", members: [{_ id:0,host: "ServerIP:MongoDBPort"}]})

2. When initializing, please specify the Server information and port information, otherwise an error may be reported during initialization. The error message is as follows

"errmsg": "No host described in new configuration 1 for replica set replwms maps to this node"

Specify IP and port, copy set name, for example, execute the following command, OK

3. Replica set initialization can be performed in admin, not just in the local database (real replica set creation is mostly performed in the admin library).

Unlike what is required in some articles: You just need to issuers.initiate () on thelocaldatabase:

4. After the initial completion, the only node in the replica set may appear as SECONDARY or OTHER for a short time. Generally speaking, after a while, it will naturally return to primary without human intervention.

Or

If the amount of data in the database is small and the transition state (SECONDARY or OTHER) is initial for a long time, and the log of the instance also shows no progress, you can consider restarting the service at this time.

The following case is a scenario we actually encountered. We solved this problem by restarting the service, changing the role from other restart to Primary.

About how to open Oplog in MongoDB to share here, I hope the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report