In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
Don't say much nonsense.
Three machines
Host1,host2,host3
Check the official installation documentation https://docs.mongodb.com/manual/tutorial/install-mongodb-on-red-hat/
Edit source file
Vim / etc/yum.repos.d/mongodb-org-3.4.repo
[mongodb-org-3.4] name=MongoDB Repositorybaseurl=gpgcheck=1enabled=1gpgkey= https://www.mongodb.org/static/pgp/server-3.4.asc
Installation
Yum install-y mongodb-org
Since I did it on three virtual machines, the host is actually one, so three ports are configured.
Note: the configuration file for mongod follows the yaml file format!
[root@vultr ~] # cat / etc/mongod.conf # mongod.conf# for documentation of all options See:# http://docs.mongodb.org/manual/reference/configuration-options/# where to write logging data.systemLog: destination: file logAppend: true path: / var/log/mongodb/mongod.log# Where and how to store data.storage: dbPath: / var/lib/mongo journal: enabled: true# engine:# mmapv1:# wiredTiger:# how the process runsprocessManagement: fork: true# fork and run in background pidFilePath: / var/run/mongodb/mongod.pid # location of pidfile# network interfacesnet: port: 27017# bindIp: 127.0.0.1 # Listen to local interface only Comment to listen on all interfaces.#security:#keyFile = / opt/key/autokey#operationProfiling:#replication:replication: oplogSizeMB: 1000 replSetName: rstest#sharding:## Enterprise-Only Options#auditLog:#snmp:
Basically the default configuration, dbdata location and log directory depending on the specific situation, modify as appropriate, bindip is turned on by default, logged out, otherwise mongo will only access locally
Start
Mongod-f / etc/mongod.conf
At this time, you can enter any mongod to initialize the replica set.
Mongo entry, default is port 27017, but if you change the port, you will have to use the mongo ip:port way
Load the configuration first
Config= {_ id: "rstest", members: [{_ id:0,host: "host1:port"}, {_ id:1,host: "host2:port"}, {_ id:2,host: "host3:port"}]} # # _ id must be the name of the replica set in the configuration file
Replica set initialization
Rs.initiate (config)
One thing to note here is to ensure the connectivity between each mongodb, and each mongo is empty data, otherwise an error will be reported when creating a replica set. If the database is not empty, you must first eliminate the replica set, and then delete db.dropDatabase ().
Finally, the configuration takes effect.
Rs.reconfig (config)
Daily scale-out and scaling, as well as manual configuration of the primary node
PRIMARY > rs.add ("127.0.0.1 PRIMARY 27018"); / / add node PRIMARY > rs.remove ("127.0.0.1 virtual 27018") / / delete these two commands without doing rs.reconfig (config) configuration effective rs.conf () / / View configuration config=rs.conf () / / read configuration config.members [1] .priority = N / / N = 1 to 100, the greater the priority, the more priority to change the primary node rs.reconfig (config) / / to let the configuration take effect, and the host2 will become the primary node in a moment.
Algorithm for the election:
The selection bureau algorithm of the mongodb cluster is actually similar to that of zookeeper, except that the bully algorithm is used. Mongod will first compare who performed the last data operation, that is, whose data is up-to-date. If the data is the same, then it will compare who can become the master node in the shortest time. The election process is the same as zookeeper, except that the comparison of KLTV is not the same.
In addition, in the cluster election process, you do not want a slave node to become a master node, you can use the
Rs.freeze / / the data in parentheses is the freezing time, that is, the node cannot become a master node within 120 seconds (in seconds).
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.