Building a copy set of MongoDB

Source: Internet
Author: User

Configuring Replica Sets Replica Sets
Keep the data consistent, clean up the database-----practice Operations
[Email protected] ~]# rm-rf/usr/local/mongodb/data/db/*
1. Enable replica set, write config file, 4.2-4.3-4.4, specify host replica set name
[Email protected] ~]# vim/usr/local/mongodb/etc/mongodb.conf
Replset=rs1
2. Start the service, if the service does not come, check the configuration file
[Email protected] ~]# mongod-f/usr/local/mongodb/etc/mongodb.conf
3. Create a cluster-------any one can, this operation--->4.2, connect themselves, on which machine to execute the command to create a cluster, it becomes the main
[Email protected] ~]#/usr/local/mongodb/bin/mongo--host 192.168.4.2--port 27050

config={
... _id: "Rs1",
... members:[
... {_id:0, Host: "192.168.4.2:27050"},
... {_id:1, Host: "192.168.4.3:27051"},
... {_id:2, Host: "192.168.4.4:27052"}
... ]
... };
The output is as follows:
{
"_id": "Rs1",
"Members": [
{
"_id": 0,
"Host": "192.168.4.2:27050"
},
{
"_id": 1,
"Host": "192.168.4.3:27051"
},
{
"_id": 2,
"Host": "192.168.4.4:27052"
}
]
}
4. Initializing the Replica sets environment
? Execute the following command
–>rs.initiate (config)
With output, OK.
Rs1:primary>
5. View replica Set information
Query status information
Rs1:primary> Rs.status ()
See if it is the master library
Rs1:primary> Rs.ismaster ()
######### #其他机器也可以执行上面命令查看
6. Verifying the replica set configuration
Client Connection master: [[email protected] ~]#/usr/local/mongodb/bin/mongo--host 192.168.4.2--port 27050
Write to document:
Rs1:primary> Db.name.save ({name: "Jerry", age:19})
Synchronize data validation------from the library to view the document
Rs1:secondary> Db.getmongo (). Setslaveok () allows viewing of data from a library
Simulate downtime and go from the library to see who is the main
–> Rs.ismaster () see if it is the main library
Connect the current master, write the document, and see if the current Master library is synchronizing data from the library
Repair the database that has been down, execute command Db.getmongo (). Setslaveok () to see if the data is synchronized and is the current master library from the library

Building a copy set of MongoDB

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.