Environment Configuration
Architecture: One master two from (three virtual machines)
System version: CentOS Linux release 7.4.1708 (Core)
MongoDB version: 3.0.15
MongoDB Installation
The following operations are performed on 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/
Installing MongoDB
Yum-y Install mongodb-org
Modify the MongoDB configuration file
# Modify the Listener address for 0.0.0.0net:port:27017 bindip:0.0.0.0# Modify the replica set configuration, which is the configuration required to configure the replica set replication:oplogsizemb:20480 replsetname: GoGen
Modify Kernel Configuration
# It's best to join the boot profile echo never >/sys/kernel/mm/transparent_hugepage/enabledecho never >/sys/kernel/mm/transparent_ Hugepage/defrag
Modify the file descriptor /etc/security/limits.conf
# After the configuration file is added later content Mongod soft nofile 64000mongod hard nofile 64000mongod soft nproc 32000mongod hard Nproc 32000
Start the service
Chkconfig Mongod onservice mongod start
Replica set deployment
Execute the following command on any server to log in to Monogdb
Mongo
Switch to Admin library
> Use admin
Define a config variable
> config={_id: "GoGen", Members:[{_id:0,host: "192.168.6.91:27017"},{_id:1,host: "192.168.6.92:27017"},{_id:2, Host: "192.168.6.93:27017"}]}
Initialize configuration, return {"OK": 1} to create success
> rs.initiate (config) {"OK": 1}gogen:other> gogen:primary>
Replica Set weight configuration
Log on to MONOGDB on any server and execute the following command, first define 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 a second host to 90
Gogen:primary> cfg.members[1].priority=90
Change the weight of a third host to 1
Gogen:primary> Cfg.members[2].priority=1
Refresh Configuration
Gogen:primary> Rs.reconfig (CFG)
Replica set basic commands are used
View Replica set Status
Gogen:primary> Rs.status ()
View Replica Set Configuration
Gogen:primary> Rs.config ()
Test
Write some data on the master to see if it can be synchronized from the master
Test the main outage (direct shutdown, or stop the service), whether the new master can be re-elected in two other
Write the data on the new master and see if the other one can be synchronized
Restore the old primary server of the outage, see if the newly written data can be synced to the old master, and see if the master will be captured back
MongoDB 3.0 Replica Set Build