In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
The replica set mode of mongodb has been greatly improved from the previous master-slave mode. Because the previous master-slave mode does not support the host to switch to the slave machine after downtime, it has been gradually eliminated. Now the officially recommended replica set mode supports the coexistence of multiple nodes. When the primary node goes down, it starts from the secondary node with the highest weight, and then switches to the primary node in turn, which is very easy to use. The following are some construction steps and matters needing attention, as well as fault handling and so on.
Note:
1. Mongodb no longer supports 32-bit operating systems, so be sure to install 64-bit systems.
2. In the process of building a replica set, be sure to turn off the firewall, whether it is selinux or iptables, or it will report an error and show that it cannot communicate. "errmsg": "replSetInitiate quorum check failed because not all proposed set members responded affirmatively: 192.168.145.136 errmsg 27017 failed with No route to host".
3. The mongodb version of each node must be the same, otherwise the building is not successful, and the "stateStr": "(not reachable/healthy)" will be displayed when you use the rs.status () command to view it.
Installation steps:
1. Write the yum source configuration file mongodb-org-3.4.repo of mongodb:
[mongodb-org-3.4]
Name=MongoDB Repository
Baseurl= https://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/3.4/x86_64/
Gpgcheck=1
Enabled=1
Gpgkey= https://www.mongodb.org/static/pgp/server-3.4.asc
2. Yum install-y mongodb-org
It will automatically download version 3.4 of mongodb.
Build steps:
1. After installing mongodb on the three machines, rewrite the configuration file / etc/mongod.conf:
Replication:
# # oplog size
OplogSizeMB: 20
# # replication set name
ReplSetName:raffaele_mongo
2. Restart the service: / etc/init.d/mongod restart
3. Select a machine as the master node, enter the mongodb of the machine, and execute the following command:
> use admin
> config= {_ id: "raffaele_mongo", members: [{_ id:0,host: "192.168.145.135purr 27017"}, {_ id:1,host: "192.168.145.132purl 27017"}, {_ id:2,host: "192.168.145.136purr 27017"}]}
> rs.initiate (config)
> rs.add ("192.168.145.132")
> rs.add ("192.168.145.136")
Rs.status () / / View status
If the status of the two slaves is "stateStr": "STARTUP", you need to do the following
> var config= {_ id: "raffaele_mongo", members: [{_ id:0,host: "192.168.145.135purr 27017"}, {_ id:1,host: "192.168.145.132purl 27017"}, {_ id:2,host: "192.168.145.136purr 27017"}]}
> rs.reconfig (config)
If you look at rs.status () again at this time, you will find that it has changed from the state of to SECONDARY.
Troubleshooting:
1. When you use the rs.status () command to view the status of each node, the secondary node always displays "stateStr": "(not reachable/healthy)".
This is due to the inconsistency of the mongodb version of the primary node and the secondary node, so you can change the yum source file and re-yum install-y mongodb-org so that the version of mongodb can be updated.
2. E QUERY [thread1] SyntaxError: missing) after argument list @ (shell): 1:14
Grammatical errors, this problem can be directly on the Internet or official documents to search for the usage and format of commands, of course, I think the official documents of mongodb are very verbose.
3. Operate any command on the secondary node to display the
E QUERY [thread1] Error: listDatabases failed: {
"ok": 0
"errmsg": "not master and slaveOk=false"
"code": 13435
"codeName": "NotMasterNoSlaveOk"
}:
At this point, only need to execute the command on the secondary node: rs.slaveOk ()
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.