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

MongDB replica set

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

Official website: https://docs.mongodb.com/v3.4/reference/replication/

Chinese website: http://www.mongodb.org.cn/manual/method-replication/

Permissions table reference: https://blog.csdn.net/kk185800961/article/details/45619863

Replica set Building reference: https://www.cnblogs.com/ranjiewen/p/5928994.html

Set up mongo monitoring in test environment

The user used by monitoring mongodb is usually an admin library without specifying a database name, so the monitoring user should be created under admin, and the authorized permission is clusterMonitor to execute serverStatus.

Use admindb.createUser ({user: "monitor_mongo", pwd: "monitor_mongo@123", roles: [{role: "clusterMonitor", db: "admin"}]})

View all users:

Use admin;db.system.users.find ()

Delete a user:

Db.dropUser ("")

Delete the database:

> use monitor_mongo;switched to db monitor_mongo > show users; > db.dropDatabase () {"dropped": "monitor_mongo", "ok": 1} build replica set

= = auth starts the service

Ensure that all nodes use the same secret key

Echo "this is rs1 super secret key" > / opt/mongodb/keyFilechmod 600 / opt/mongodb/keyFile

When starting the service using the configuration file auth, initialize the cluster first, and then set the password

Config= {_ id: "rs0", members: [{_ id:0,host: "192.168.1.221 pwd 23183"}]} rs.initiate (config) db.createUser ({user: "root", pwd: "ops2017 regulations", roles: [{role: "root", db: "admin"}]} rs.add ("20.10.1.31 charge 27018")

If the config is written wrong the first time, you can use the appropriate command to modify it.

Config= {_ id: "rs0", members: [{_ id:0,host: "192.168.1.221 rs0 11111"}]} rs.reconfig (config)

View the cluster status:

Rs.status ()

View the configuration:

Db._adminCommand ({getCmdLineOpts:1})

= Cluster test: the number of nodes must be > = 3, and the remaining nodes can only be elected when the master database fails; if the number of downtime nodes is more than half of the total, a new master cannot be elected.

Primary:

Rs0:PRIMARY > use testswitched to db testrs0:PRIMARY > db.test.insert ({1:1}) WriteResult ({"nInserted": 1}) rs0:PRIMARY > db.test.find () {"_ id": ObjectId ("5c80bfa19d287f61d98d24b5"), "1": 1}

SECONDARY: the default client cannot obtain data from Secondary members and must perform slaveOk before it can read the data.

Rs0:SECONDARY > rs.slaveOk () rs0:SECONDARY > db.test.find () {"_ id": ObjectId ("5c80bfa19d287f61d98d24b5"), "1": 1}

= = description of important parameters of the cluster:

Rs.conf () {"_ id": "rs0", "version": 4, "protocolVersion": NumberLong (1), "members": [{"_ id": 0, "host": "192.168.1.221 version 23183", "arbiterOnly": false, "buildIndexes": true, "hidden": false "priority": 1, "tags": {}, "slaveDelay": NumberLong (0), "votes": 1}

Where:

ArbiterOnly:0 or 1, marks an arbitration (arbiter), the only function of Arbiter is to participate in the election of Primary, Arbiter does not keep data, will not provide services for client, it exists to elect Primary.

Hidden:0 or 1, indicating whether the member is a hidden member, the main role of a Hidden member is to back up data, and you can use a poor-performing server as a Hidden member. Hidden members will not receive requests from Client, nor will they become Primary. When setting Hidden members, the members[ n] .priorty property must be set to 0.

Priority: a numeric type that sets the priority for a member to become a Primary. The higher the priority, the more likely it is to become a Primary. If priority=0, then the member will never become a Primary.

Votes:1, or 0, indicates the number of votes for that member. In each Replica Set, there are up to 7 members with a votes property value of 1. A member whose votes attribute is 1 (voting members) has the right to elect a Primary. If a member wants to be a Primary, he must have the support of most members of voting members.

In Replica Set, if the number of voting members is 5, then a member becomes a Primary only if it is supported by more than 2 voting members and there is no voting members objection. As long as any voting member objects to the member becoming a Primary, the member cannot become a Primary.

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