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

Installation and deployment of mongodb replica set replica set (3)

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

Share

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

1. Node Typ

To put it simply, the replica set (replica set) is a master-slave cluster with automatic failure recovery. The most obvious difference between the master-slave cluster and the replica set is that the replica set has no fixed master node, and the whole cluster will elect a master node.

Node Typ

Standard: regular node, which stores a complete copy of the data, participates in voting in the election, and may become a primary node.

Passive: stores a complete copy of the data, participates in voting, and cannot become a primary node.

Arbiter: arbitration node, which only participates in voting, does not receive replicated data, and cannot become a primary node.

The number of repica sets nodes is preferably odd (odd).

The experiment consists of three nodes:

Two standard nodes (these two nodes can directly cut primary secondary to each other).

An arbiter node, which holds a vote in its hand, decides which of the above two standard nodes can become a primay.

two。

Three-node distribution of relica sets cluster

The experiment consists of three nodes:

Two standard nodes (these two nodes can directly cut primary secondary to each other).

Node1ip:192.168.137.12

Node2ip:192.168.137.13

An arbiter node, which holds a vote in its hand, decides which of the above two standard nodes can become a primay.

Node3ip:192.168.137.14

3. Configuration step

Start the first standard node

/ usr/local/mongodb/bin/mongod-port 27017-dbpath / data/mongodb/db1/-logpath / data/mongodb/logs/m1.log-logappend-replSet test/192.168.137.13:27017-maxConns=200-fork

Start the second standard node

/ usr/local/mongodb/bin/mongod-port 27017-dbpath / data/mongodb/db1/-logpath / data/mongodb/logs/m1.log-logappend-replSet test/192.168.137.12:27017-maxConns=200-fork

Start the third arbiter node

/ usr/local/mongodb/bin/mongod-port 27017-dbpath / data/mongodb/db1/-logpath / data/mongodb/logs/m1.log-logappend-replSet test/192.168.137.13:27017192.168.137.12:27017-maxConns=200-fork

After the above configuration is completed, any standard node runs mongo

> use admin

> cfg= {_ id:'test',members: [

... {_ id:0,host:'192.168.137.12:27017'}

... {_ id:1,host:'192.168.137.13:27017'}]

...}

The following prompt indicates success.

Info: "Config now saved locally. Should come online in about a minute."

"ok": 1

Then join the arbiter node

PRIMARY > rs.addArb ("192.168.137.14 purl 27017")

At this point, the cluster has been configured and the roles of the three nodes have been assigned. How to check whether it is normal or not?

Rs.status () through this command, you can check whether the ip and roles of each node are normal.

You can check the status of the replica set, including the name, time, whether the mongod currently logged in is primary or secondary, as well as the information of the members.

Among the replica set messages, the important ones are:

The value of myState, if 1 indicates that the current login is primary;, if 2 represents the current login is secondary.

Member information includes address, health status, primary or secondary, etc.

The more important thing in the member information is

State:1 indicates that the host is currently available for reading and writing. 2: cannot read or write.

Health:1 indicates that the host is currently normal, 0: exception

Management of 4.mongodb replica sets

Add a normal data node

PRIMARY > rs.add ("ip:port")

Delete nod

PRIMARY > rs.remove ("ip:port")

Show who is the current primay

PRIMARY > rs.isMaster ()

Modify an ordinary data node to a passive node, that is, it can synchronize data and vote, but it cannot become a primay.

In addition to the arbitration node, each other node has a priority, and we can set the priority to determine who has the largest weight as primay.

In MongoDB replica sets, the priority is determined by setting the value of priority, which ranges from 0 to 100. The higher the value, the higher the priority.

If the value is 0, it cannot be primay.

View the list of nodes through the rs.conf () command

Change the priority value of the node2 node to 0 so that it only receives data and does not compete to become primary. Operate on the PRIMARY node:

Cfg = rs.conf ()

Cfg.members [1] .priority = 0

Rs.reconfig (cfg)

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