MongoDB database M

Source: Internet
Author: User
The blog.chinaunix.netuid-24086995-id-1754660.html uses two different ports on the same machine to start mongodb and create two new directories under the database directory [root @ localhost ~] # Mkdirdatadbmaster [root @ localhost ~] # Mkdirdatadbslave master: only required

The http://blog.chinaunix.net/uid-24086995-id-1754660.html uses two different ports on the same machine to start mongodb and create two new directories under the database directory [root @ localhost ~ ] # Mkdir/data/db/master [root @ localhost ~ ] # Mkdir/data/db/slave master: only required

Http://blog.chinaunix.net/uid-24086995-id-1754660.html


Start mongodb with two different ports on the same machine
Create two new directories under the database directory

  1. [Root @ localhost ~] # Mkdir/data/db/master
[Root @ localhost ~] # Mkdir/data/db/slave


Master: only the -- master parameter needs to be included, indicating that this is a master, which is quite convenient.

  1. [Root @ localhost ~] #/Usr/local/bin/mongod -- master-dbpath =/data/db/master-port = 11536 &
  2. [1] 10939
  3. [Root @ localhost ~] # Mon Jul 25 20:21:59 [initandlisten] MongoDB starting: pid = 10939 port = 11536 dbpath =/data/db/master = 1 32-bit


From: Take the -- slave parameter to specify the slave, specify the -- source, Master Address and port, it is much more convenient than MYSQL.

  1. [Root @ localhost bin] #/usr/local/bin/mongod-port 11537 -- slave-dbpath =/data/db/slave -- source 127.0.0.1: 11536
  2. Mon Jul 25 20:25:52 [initandlisten] MongoDB starting: pid = 11158 port = 11537 dbpath =/data/db/slave = 1 32-bit

Open a new terminal, log on to 11536 (master), and write a record

  1. [Root @ localhost ~] #/Usr/local/bin/mongo -- port = 11536
  2. MongoDB shell version: 1.8.2
  3. Connecting to: 127.0.0.1: 11536/test
  4. > Use brucezuo
  5. Switched to db brucezuo
  6. > Db. createCollection ("table1 ")
  7. {"OK": 1}
  8. > Db. table1.insert ({id: 1, name: "zxy", age: 29 })
  9. >

Open a new terminal and log on to 11537 (slave) to check whether the data is consistent.

  1. [Root @ localhost ~] #/Usr/local/bin/mongo -- port = 11537
  2. MongoDB shell version: 1.8.2
  3. Connecting to: 127.0.0.1: 11537/test
  4. > Show dbs
  5. Admin (empty)
  6. Brucezuo 0.0625 GB
  7. Local 0.0625 GB
  8. > Use brucezuo
  9. Switched to db brucezuo
  10. > Db. table1.find ()
  11. {"_ Id": ObjectId ("4e2e348ed502dbae1aee469e"), "id": 1, "name": "zxy", "age": 29}
  12. >

The data on both ends is completely consistent.

From the test above, mongodb has much easier configuration for master-slave replication than MYSQL.

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.