In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
Overview of MongoDB replication set
Replication sets are additional replicas of data and the process of synchronizing data across multiple servers. Replication sets provide redundancy and add data availability. The advantages of a replication set to restore services interrupted by hardware failures are as follows: make the data more secure. High data availability (2407) disaster recovery no-downtime maintenance (such as backup, index reconstruction, failover) read scaling (additional replica reads) replica sets are transparent to applications. How the replication set works MongoDB requires at least two nodes, one of which is the master node (primary), which is responsible for handling 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 its operations to the oplog, the slave node polls the master node regularly to obtain these operations, and then performs these operations on its own data copy, so as to ensure that the data of the slave node and the master node translator. The characteristics of the replication set are as follows: n node cluster level any node guest as the primary node all write operations in the primary node automatic failover automatic recovery start deployment create multi-instance / / create multi-instance shutdown firewall setenforce / some blocking projects mkdir-p / data/mongodb/mongodb {2jue 3pm 4} / create data directory mkdir logs/ / to / data/mongodb/ create log file directory touch logs/mongodb {2jue 3 4} .log / / create log file cd logs/ to directory chmod 777 * .log / / grant permissions / / create a multi-instance configuration file And open the service mongod-f / etc/mongod.conf-- shutdown / / modify the master configuration file and close it. Enable mongod-f / etc/mongod.conf / / enable all services one by one and enter the default port to enable replication set cp-p / etc/mongod.conf / etc/mongod2.conf / / two instance configuration files vim / etc/mongod2.conf path: / data/mongodb/logs/mongod2.log / / Syslog storage path dbPath: / data/mongodb/mongo / / data storage log port: 27018 / / end port mkdir-p / data/mongodb/ create system log and data storage log without directory cd / data/mongodb/ mkdir mongo touch mongod2.log / / create a system log file chmod 777 mongod2.log / / and give permission to mongod-f / etc/mongod2.conf / / start the multi-instance service mongo-- port 27018 / / enter mongodb 27018netstat-ntap / / the production process cfg= {"_ id": "abc" "members": [{"_ id": 0, "host": "192.168.10.5 id 27017", "priority": 100}, {"_ id": 1, "host": "192.168.10.5 id 27018", "priority": 100}, {"_ id": 2, "host": "192.168.10.5 id 27019", "priority": 0}, {"_ id": 3, "host": "192.168.10.5 host 27020" "arbiterOnly": true}]} / / pay attention to IP priority to judge priority ": 100 / / High as table quasi node priority": 0 / / low as passive node arbiterOnly ": true / / arbitration node rs.initiate (cfg) / / you can see your identity after initialization refresh. Rs.isMaster () / / View the basic additions, deletions, changes and queries of node status db.t1.insert ({" id ": 1) "name": "tom"}) / / create a collection db.t1.find () / / View the current data db.t1.update ({"id": 2}, {$set: {"name": "jack"}}) / / modify the specified content db.t1.remove ({"id": 1}) / / delete the specified data
Whether the simulated failure node experiment can automatically preempt show dbs / / display all databases use local / / enter the database show collections / / display data where log files are stored all collections db.oplog.rs.find () # View log records all operations simulation table quasi-node 1 failure mongod-f / etc/mongod.conf-- shutdown # turn off a master node service to see if there are any other mongoDB No preemption mongo-- port 27018 # the second standard node will be selected at this time to simulate the label Node 2 failure mongod-f / etc/mongod2.conf-- shutdown # turn off the second master node mongo-- port 27019 # at this time the passive node cannot become the master node to allow the slave node to read data rs.slaveOk () # allow the default read data from the node to view replication status information
The arbitration node will not copy the information.
Rs.help () # help information
Rs.printReplicationInfo () # View log file size information
Configured oplog size: 990MB # this log file size can be modified
Rs.printSlaveReplicationInfo () # seems to be synchronizing with that node.
# you will find that the arbitration node does not have data replication
-change the oplog size 00:00 modify to adjust the log file size, the slave node will go to the master node
Synchronize each other's files so as to expand the capacity of the host node.
Say that the size of your log file is the best, if not, you can do it at 00:00.
Adjust 990m by default, adjust the slave node
1) close the node service because the slave node is a member of the replication set of the master node
2) it can only be modified separately. Close the service first, withdraw from the replication set, and then become a single instance.
3) use admin # shut down the service first
4) db.shutdownServer () # exit replication set offline upgrade
5) modify the slave node configuration file
6) mongod-f / etc/mongod2.conf / / start the service
7) mongo-port 27028 / / Log in
8) mongodump-- port 27028-- db local-- collection 'oplog.rs' / / oplog for integrity backup
9) mongo-- port 27028 / / entry port
10) use local
Db.oplog.rs.drop () / / Delete the original file
11) db.runCommand ({create: "oplog.rs", capped: true, size: (2 1024 1024 * 1024)}) / / change the prototype to 2048
12) use admin
Db.shutdownServer () / / shut down the service again
13) modify the previous data again in replication:
ReplSetName: abc
OplogSizeMB: 2048 / / add
14) mongod-f / etc/mongod2.conf / / restart the service mongo-- port 27018 entry port
15) rs.printReplicationInfo () / / now it becomes 2048 pairs, but it is valid for modification.
16) rs.stepDown () # effectively elects the identity of the Lord in the Lord.
! [] (https://s1.51cto.com/images/blog/201807/16/056486508bc79f8a63535d95c9d7251c.png?x-oss-process=image/watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=)! [] (https://s1.51cto.com/images/blog/201807/16/2a8d53ec8c61716800a096e3edfcbb8d.png?x-oss-process=image/watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=) Long create a user on the primary server as rootuse admin db.createUser ({"user": "root", "pwd": "123") "roles": ["root"]}) # create user password vim / etc/mongod.conf / / modify main configuration file synchronization and have an authentication modification in the middle all configuration files security: keyFile: / usr/bin/kgcrskey1 / / verify file path clusterAuthMode: keyFile / / verify key restart service mongod-f / etc/mongod.conf-- shutdownmongod-f / etc/mongod.conf / the other servers all restart in the same way. Repeat operations to authenticate the login (first verify the master, then verify the slave) when you directly use the login command to log in to the system, you cannot use show dbs to view the data, so you need to use authentication mongo-port 27018use admindb.auth ("root", "123123")
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.