In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
What is a replication set?
Replication sets are additional replicas of data, the process of synchronizing data across multiple servers, providing redundancy and increasing data availability, through which hardware failures and interrupted services can be restored.
The advantages of replication sets are as follows:
Make data more secure and highly available (2407) disaster recovery no downtime maintenance (such as backup, index rebuild, failover) read scaling (additional replica reads) replica sets are transparent to the application how replication sets work
The replication set of MongoDB requires at least two nodes. One of them is the master node (Primary), which is responsible for processing the client's requests, and the rest is the slave node (Secondary), which is responsible for replicating the data on the master node.
The common collocation of each node in MongoDB is: one master, one slave or one master and multiple slaves. The master node records all the operations on it to the oplog, and the slave node polls the master node regularly to obtain these operations, thus ensuring that the data of the slave node is consistent with that of the master node.
The client writes data in the master node and reads the data in the slave node. The master node interacts with the slave node to ensure the consistency of the data. If one of the nodes fails, the other nodes will immediately take over the business without downtime.
Replication sets have the following characteristics:
N-node cluster any node can act as the primary node all writes on the primary node automatically fail over and automatically recover the MongoDB replication set deployment to create multiple instances
How to create multiple instances has been written in my previous blog. You can refer to Yum installation MongoDB and database management. When creating each instance, you should first create a data file directory (mongo) and a log file (mongod.log). At the same time, when modifying the configuration file, you should pay attention to modifying the configuration file using a different port number. When making a replication set, we need to modify one more parameter, the parameter value of replication. And ensure that the parameter values of multiple instances are consistent according to the requirements of the project, it is necessary to create three additional instances, plus the original one, a total of four instances.
When I was doing the experiment, I found that there are strict requirements for the format of the configuration file in MongoDB, so we should pay special attention to the modification of replication parameter values.
Replication: replSetName: chenrs / / the content of this line needs to be filled with two spaces at the beginning of the line. No spaces or multiple spaces will cause the service to fail to start.
The schematic diagram of the project is as follows:
Initialize the configuration replication set to create the replication set
Let's first configure a replication set with three nodes, and the extra node will do the operation of adding a node next.
Mongochen= {"_ id": "chenrs", "members": [{"_ id": 0, "host": "172.16.10.27 id 27017"}, {"_ id": 1, "host": "172.16.10.27 id 27018"}, {"_ id": 2, "host": "172.16.10.27 chenrs 27019"}]}
Initialize replication set
When initializing the replication set, make sure that there is no data in the slave node, otherwise the data of the slave server will be lost after initialization.
Rs.initiate (chen)
Check the status of each node in the replication set chenrs:SECONDARY > rs.status () {"set": "chenrs", "date": ISODate ("2018-07-14T14:40:20.756Z"), / / omit part of "members": [{"_ id": 0, "name": "172.16.10.27set 27017" "health": 1, / / Health value is 1 Indicates that the node is in a good running state "state": 1, / / 1 represents the main "stateStr": "PRIMARY", / / is in peimary status / / omits part of the content}, {"_ id": 1 "name": "172.16.10.27 state 27018", "health": 1, "state": 2, / / 2 represents from "stateStr": "SECONDARY", / / in secondary status / / omitted part}, {"_ id": 2 "name": "172.16.10.27 SECONDARY", "health": 1, "state": 2, "stateStr": "SECONDARY" / / omit part} chenrs:PRIMARY > / / Node status has changed at this time Node Management (done on primary) add Node rs.add ("172.16.10.27 rs.add")
Delete node rs.remove ("172.16.10.27 grep mongod 27020") failover simulation master node damage ps aux | grep mongod / / query the process number of the local node kill-9 40882 / / kill the master node process
Check node status chenrs:SECONDARY > rs.status () {"set": "chenrs", "date": ISODate ("2018-07-14T15:21:21.426Z"), "myState": 2, "term": NumberLong (2), "syncingTo": "172.16.10.27 syncingTo", "syncSourceHost": "172.16.10.27 set 27019", "syncSourceId": 2 / / omit part of the content "members": [{"_ id": 0, "name": "172.16.10.27 name", "health": 0, / / Health value is 0 "state": 8, "stateStr": "(not reachable/healthy)", / / omit part}, {"_ id": 1, "name": "172.16.10.27 not reachable/healthy", "health": 1 "state": 2, "stateStr": "SECONDARY", / / omit some contents}, {"_ id": 2, "name": "172.16.10.27 name", "health": 1, "state": 1 "stateStr": "PRIMARY", / / omit part of the content}} actively switch master-slave status (done on primary) rs.freeze (30) / / suspend for 30s not to participate in the election rs.stepDown (606,30) / / hand over the location of the master node Maintain the slave node state for not less than 60 seconds, wait 30 seconds to synchronize the master node and slave node logs
MongoDB replication Election principle and replication set Management
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.