In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
Environment configuration
Architecture: one master, two slaves (three virtual machines)
System version: CentOS Linux release 7.4.1708 (Core)
MongoDB version: 3.0.15
MongoDB installation
The following operations need to be done on all three virtual machines
Download yum source configuration
Wget https://repo.mongodb.org/yum/redhat/mongodb-org-3.0.repo mv mongodb-org-3.0.repo / etc/yum.repos.d/
Install mongodb
Yum-y install mongodb-org
Modify mongodb configuration file
# modify the listening address: 0.0.0.0net: port: 27017 bindIp: 0.0.0.0.modify the replica set configuration. This is the configuration required to configure the replica set later: replication: oplogSizeMB: 20480 replSetName: gogen
Description:
OplogSizeMB: this is a piece of swap space needed by the master slave server during synchronization. If the server space is large enough, then this space is as large as possible, in MB. You should be careful when changing this value, and you can't change it at will.
ReplSetName: this is the name of the replica set. Customize it by yourself.
Modify kernel configuration
# it is best to add the boot configuration file echo never > / sys/kernel/mm/transparent_hugepage/enabledecho never > / sys/kernel/mm/transparent_hugepage/defrag
Modify the file descriptor / etc/security/limits.conf
# mongod soft nofile 64000mongod hard nofile 64000mongod soft nproc 32000mongod hard nproc 32000 after the configuration file is added at the end
Start the service
Chkconfig mongod onservice mongod start
Replica set deployment
Execute the following command on any server
Log in to monogdb
Mongo
Switch to the admin library
> use admin
Define a config variable. Notice to change the id name to your own replica set name, and host to your actual host IP and listening port. The variable name can also be defined by yourself.
> config= {_ id: "gogen", members: [{_ id:0,host: "192.168.6.91 members 27017"}, {_ id:1,host: "192.168.6.92 gogen 27017"}, {_ id:2,host: "192.168.6.93Freight 27017"}]}
Initialize the configuration, and create it successfully when returned
> rs.initiate (config) {"ok": 1} gogen:OTHER > gogen:PRIMARY >
Description
{"ok": 1}: indicates that the execution is successful. If not, other results are returned.
Gogen:OTHER >: after the previous command is successfully executed, the prompt will look like this, indicating that a replica set is being created, but the role of this host is uncertain, so it is OTHER
Gogen:PRIMARY >: enter directly after a while and the prompt will become PRIMARY (for master), if SECONDARY (for slave)
Replica set weight allocation
Log in to monogdb on the master and execute the following command, first defining a variable
Gogen:PRIMARY > cfg=rs.config ()
Change the weight of the first host to 100
Gogen:PRIMARY > cfg.members [0] .priority = 100
Change the weight of the second host to 90
Gogen:PRIMARY > cfg.members [1] .priority = 90
Change the weight of the third host to 1
Gogen:PRIMARY > cfg.members [2] .priority = 1
Refresh configuration
Gogen:PRIMARY > rs.reconfig (cfg)
Copy set basic commands use
View replica set status
Gogen:PRIMARY > rs.status () # refer to {"set": "gogen", "date": ISODate ("2018-03-07T02:40:00.403Z"), "myState": 1, "members": [{"_ id": 0 "name": "192.168.6.91 state 27017", "health": 1, "state": 1, "stateStr": "PRIMARY", "uptime": 54870, "optime": Timestamp (1520336246 1), "optimeDate": ISODate ("2018-03-06T11:37:26Z"), "electionTime": Timestamp (1520335742, 1), "electionDate": ISODate ("2018-03-06T11:29:02Z"), "configVersion": 2 "self": true}, {"_ id": 1, "name": "192.168.6.92 id 27017", "health": 1, "state": 2 StateStr: "SECONDARY", "uptime": 54661, "optime": Timestamp (1520336246, 1), "optimeDate": ISODate ("2018-03-06T11:37:26Z"), "lastHeartbeat": ISODate ("2018-03-07T02:40:00.046Z") "lastHeartbeatRecv": ISODate ("2018-03-07T02:39:59.466Z"), "pingMs": 0, "syncingTo": "192.168.6.91 07T02:39:59.466Z 27017", "configVersion": 2} {"_ id": 2, "name": "192.168.6.93 state 27017", "health": 1, "state": 2, "stateStr": "SECONDARY" Uptime: 54661, optime: Timestamp (1520336246, 1), optimeDate: ISODate ("2018-03-06T11:37:26Z"), "lastHeartbeat": ISODate ("2018-03-07T02:39:59.914Z") "lastHeartbeatRecv": ISODate ("2018-03-07T02:39:59.297Z"), "pingMs": 0, "syncingTo": "192.168.6.91 07T02:39:59.297Z 27017", "configVersion": 2}], "ok": 1}
View replica set configuration
Gogen:PRIMARY > rs.config () # return result reference {"_ id": "gogen", "version": 2, "members": [{"_ id": 0, "host": "192.168.6.91 id 27017", "arbiterOnly": false "buildIndexes": true, "hidden": false, "priority": 100, "tags": {}, "slaveDelay": 0 "votes": 1}, {"_ id": 1, "host": "192.168.6.92 host", "arbiterOnly": false, "buildIndexes": true "hidden": false, "priority": 90, "tags": {}, "slaveDelay": 0 "votes": 1}, {"_ id": 2, "host": "192.168.6.93 host", "arbiterOnly": false, "buildIndexes": true "hidden": false, "priority": 1, "tags": {}, "slaveDelay": 0 "votes": 1}], "settings": {"chainingAllowed": true, "heartbeatTimeoutSecs": 10, "getLastErrorModes": {} "getLastErrorDefaults": {"w": 1, "wtimeout": 0}
test
Write some data on the master to see if the slave can synchronize from the master
Test whether a new master can be re-elected in the other two slave stations if the master is down (directly shut down, or the service is stopped).
Write data on the new master to see if another slave can synchronize
Restore the old down master server to see if the newly written data can be synchronized to the old master, and to see if the master will be captured back
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.