MongoDB's Master/slave mode

Source: Internet
Author: User

# # # MongoDB's master-slave configuration (without auth authentication)


# # # Notes:

-Synchronize the time before the server node

-Open the firewall must be allowed through the relevant port

-also set to enable SELinux

-Build double-click Trust mode is best


# # Master Config file

    • -Added a Master = True This line can be

    • -Multi-card machine bind_ip this line as much as possible to write a specific address (preferably the intranet address), because the slave is based on this synchronization



[[email protected] ~]# sed-e '/^#/d;/^$/d '/etc/mongodb.confbind_ip = 192.168.58.10 Port = 27017fork = Truepidfilepath = /var/run/mongodb/mongodb.pidlogpath =/var/log/mongodb/mongodb.logdbpath =/mongo/datajournal = Truemaster = Truenohttpinterface = True[[email protected] ~]#


# # # Slave configuration file

    • The following two lines are added

- slave = True

-Source = 192.168.58.10:27017

[[email protected] ~]# sed-e '/^#/d;/^$/d '/etc/mongodb.confbind_ip = 192.168.58.30port = 27017fork = Truepidfilepath =/ Var/run/mongodb/mongodb.pidlogpath =/var/log/mongodb/mongodb.logdbpath =/var/lib/mongodbjournal = Truenohttpinterface = Trueslave = Truesource = 192.168.58.10:27017[[email protected] ~]#


# # # Restart the two-node MongoDB service for initialization and verify data synchronization

    • Master


[Email protected] ~]# [[email protected] ~]# hostnameblog.unix178.com[[email protected] ~]# Mongomongodb Shell Version:2 .4.6connecting to:test> Show dbsadmin0.203125gblocal10.0732421875gbtest0.203125gbzhuima0.203125gb>



    • Slave


[[email protected] ~]# hostnameredis.unix178.com[[email protected] ~]# mongomongodb shell version:2.4.6connecting to:te St> Show dbsadmin0.203125gblocal0.078125gbzhuima0.203125gb>


# # # View sync status

    • On the master server


[Email protected] ~]# MONGO 192.168.58.30MongoDB Shell version:2.4.6connecting to:192.168.58.30/test> show Dbsadmin 0.203125gblocal0.078125gbnick0.203125gbtest0.203125gbzhuima0.203125gb>


    • On the slave server


[Email protected] ~]# MONGO 192.168.58.10MongoDB Shell version:2.4.6connecting to:192.168.58.10/test> show Dbs;admi N0.203125gblocal10.0732421875gbnick0.203125gbtest0.203125gbzhuima0.203125gb>



# # # Add new data for validation

    • Add Data on Master


[Email protected] ~]# MONGO 192.168.58.10MongoDB Shell version:2.4.6connecting to:192.168.58.10/test> show Dbs;admi N0.203125gblocal10.0732421875gbnick0.203125gbtest0.203125gbzhuima0.203125gb> use nickswitched to DB nick> use newdbswitched to DB newdb> Db.newdb.insert ({new: "Yes", info: ' Nothing '}) > show collectionsnewdbsystem.indexes > Db.newdb.find () {"_id": ObjectId ("53cbd4b35974b01658718b2d"), "new": "Yes", "info": "Nothing"}>



    • Verify on slave


[Email protected] ~]# MONGO 192.168.58.30MongoDB Shell version:2.4.6connecting to:192.168.58.30/test> show Dbsadmin 0.203125gblocal0.078125gbnick0.203125gbtest0.203125gbzhuima0.203125gb> Show Dbsadmin0.203125gblocal0.078125gbnewdb0.203125gbnick0.203125gbtest0.203125gbzhuima0.203125gb> use newdbswitched to DB newdb> show collectionsnewdbsystem.indexes> db.newdb.find () {"_id": ObjectId (" 53cbd4b35974b01658718b2d ")," new ":" Yes "," info ":" Nothing "}>


# # # PostScript

    • MongoDB officially no longer recommends using the structure of the Master/salve mode

    • Replica_set replica set mode is recommended for official use

    • For reference only







This article is from the "Chasing Horses" blog, please make sure to keep this source http://lovelace.blog.51cto.com/1028430/1441037

MongoDB's Master/slave mode

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.