MongoDB 2.6.4 master-slave Synchronization

Source: Internet
Author: User
Tags install mongodb

MongoDB 2.6.4 master-slave Synchronization

MongoDB standalone Master/Slave Mode

1: Start the master

[Bkjia @ bkjia04 mongodb-linux-x86_64-2.6.4] $ mongod -- dbpath/home/bkjia/mongodb-linux-x86_64-2.6.4/data -- port 10000 -- master
2014-09-05T15: 11: 50.115 + 0800 [initandlisten] MongoDB starting: pid = 23623 port = 10000 dbpath =/home/bkjia/mongodb-linux-x86_64-2.6.4/data master = 1 64-bit host = bkjia04
2014-09-05T15: 11: 50.116 + 0800 [initandlisten] db version v2.6.4
2014-09-05T15: 11: 50.116 + 0800 [initandlisten] git version: 3a830be0eb92d772aa855ebb711ac91d658ee910
2014-09-05T15: 11: 50.117 + 0800 [initandlisten] build info: Linux build7.nj1.10gen. cc 2.6.32-431.3.1.el6.x86 _ 64 #1 SMP Fri Jan 3 21:39:27 UTC 2014 x86_64 BOOST_LIB_VERSION = Limit 49
2014-09-05T15: 11: 50.117 + 0800 [initandlisten] allocator: tcmalloc
2014-09-05T15: 11: 50.117 + 0800 [initandlisten] options: {master: true, net: {port: 10000}, storage: {dbPath: "/home/bkjia/mongodb-linux-x86_64-2.6.4/data "}}
2014-09-05T15: 11: 50.127 + 0800 [initandlisten] journal dir =/home/bkjia/mongodb-linux-x86_64-2.6.4/data/journal
2014-09-05T15: 11: 50.127 + 0800 [initandlisten] recover: no journal files present, no recovery needed
2014-09-05T15: 11: 50.298 + 0800 [initandlisten] waiting for connections on port 10000

2: Start slave

[Bkjia @ bkjia04 ~] $ Mongod -- dbpath/home/bkjia/mongodb-linux-x86_64-2.6.4/data2 -- port 10001 -- slave -- source localhost: 10000
2014-09-05T15: 12: 48.411 + 0800 [initandlisten] MongoDB starting: pid = 23636 port = 10001 dbpath =/home/bkjia/mongodb-linux-x86_64-2.6.4/data2 slave = 1 64-bit host = bkjia04
2014-09-05T15: 12: 48.412 + 0800 [initandlisten] db version v2.6.4
2014-09-05T15: 12: 48.412 + 0800 [initandlisten] git version: 3a830be0eb92d772aa855ebb711ac91d658ee910
2014-09-05T15: 12: 48.412 + 0800 [initandlisten] build info: Linux build7.nj1.10gen. cc 2.6.32-431.3.1.el6.x86 _ 64 #1 SMP Fri Jan 3 21:39:27 UTC 2014 x86_64 BOOST_LIB_VERSION = Limit 49
2014-09-05T15: 12: 48.412 + 0800 [initandlisten] allocator: tcmalloc
2014-09-05T15: 12: 48.413 + 0800 [initandlisten] options: {net: {port: 10001}, slave: true, source: "localhost: 10000", storage: {dbPath: "/home/bkjia/mongodb-linux-x86_64-2.6.4/data2 "}}
2014-09-05T15: 12: 48.417 + 0800 [initandlisten] journal dir =/home/bkjia/mongodb-linux-x86_64-2.6.4/data2/journal
2014-09-05T15: 12: 48.417 + 0800 [initandlisten] recover: no journal files present, no recovery needed
2014-09-05T15: 12: 48.434 + 0800 [initandlisten] waiting for connections on port 10001
2014-09-05T15: 12: 49.438 + 0800 [replslave] repl: syncing from host: localhost: 10000

2014-09-05T15: 13: 48.454 + 0800 [clientcursormon] mem (MB) res: 51 virt: 584
2014-09-05T15: 13: 48.454 + 0800 [clientcursormon] & nbsp; mapped (incl journal view): 320
2014-09-05T15: 13: 48.454 + 0800 [clientcursormon] & nbsp; connections: 0
2014-09-05T15: 14: 04.315 + 0800 [replslave] repl: & nbsp; checkpoint applied 285 operations
2014-09-05T15: 14: 04.316 + 0800 [replslave] repl: & nbsp; syncedTo: Sep & nbsp; 5 15:13:54 540962b2: 1

3: Display Data

[Bkjia @ bkjia04 ~] $ Mongo localhost: 10000
MongoDB shell version: 2.6.4
Connecting to: localhost: 10000/test
> Db. master. find ()
{"_ Id": ObjectId ("540942bed89f094a5fbd9b5a"), "uid": 1000}
{"_ Id": ObjectId ("540946bcd89f094a5fbd9b5b"), "uid": 1001}
{"_ Id": ObjectId ("540956b7789903d8baf6b1b3"), "uid": 1002}
>

Slave

[Bkjia @ bkjia04 mongodb-linux-x86_64-2.6.4] $ mongo localhost: 10001
MongoDB shell version: 2.6.4
Connecting to: localhost: 10001/test
> Db. master. find ()
{"_ Id": ObjectId ("540942bed89f094a5fbd9b5a"), "uid": 1000}
{"_ Id": ObjectId ("540946bcd89f094a5fbd9b5b"), "uid": 1001}
{"_ Id": ObjectId ("540956b7789903d8baf6b1b3"), "uid": 1002}

4: Master write data

> Db. master. insert ({uid: 1004 })
WriteResult ({"nInserted": 1 })
> Db. master. find ()
{"_ Id": ObjectId ("540942bed89f094a5fbd9b5a"), "uid": 1000}
{"_ Id": ObjectId ("540946bcd89f094a5fbd9b5b"), "uid": 1001}
{"_ Id": ObjectId ("540956b7789903d8baf6b1b3"), "uid": 1002}
{"_ Id": ObjectId ("5409638c0a6617467df195ec"), "uid": 1004}
>

Query data from

[Bkjia @ bkjia04 ~] $ Mongodb-linux-x86_64-2.6.4 cd
[Bkjia @ bkjia04 mongodb-linux-x86_64-2.6.4] $ mongo localhost: 10001
MongoDB shell version: 2.6.4
Connecting to: localhost: 10001/test
> Db. master. find ()
{"_ Id": ObjectId ("540942bed89f094a5fbd9b5a"), "uid": 1000}
{"_ Id": ObjectId ("540946bcd89f094a5fbd9b5b"), "uid": 1001}
{"_ Id": ObjectId ("540956b7789903d8baf6b1b3"), "uid": 1002}
> Db. master. find ()
{"_ Id": ObjectId ("540942bed89f094a5fbd9b5a"), "uid": 1000}
{"_ Id": ObjectId ("540946bcd89f094a5fbd9b5b"), "uid": 1001}
{"_ Id": ObjectId ("540956b7789903d8baf6b1b3"), "uid": 1002}
{"_ Id": ObjectId ("5409638c0a6617467df195ec"), "uid": 1004}
>

-------------------------------------- Split line --------------------------------------

CentOS compilation and installation of MongoDB

CentOS compilation and installation of php extensions for MongoDB and mongoDB

CentOS 6 install MongoDB and server configuration using yum

Install MongoDB2.4.3 in Ubuntu 13.04

MongoDB beginners must read (both concepts and practices)

MongoDB authoritative Guide (The Definitive Guide) in English [PDF]

-------------------------------------- Split line --------------------------------------

Slave log

2014-09-05T15: 15: 48.791 + 0800 [initandlisten] connection accepted from 127.0.0.1: 35622 #1 (1 connection now open)
2014-09-05T15: 16: 34.336 + 0800 [replslave] repl: checkpoint applied 15 operations
2014-09-05T15: 16: 34.336 + 0800 [replslave] repl: syncedTo: Sep 5 15:16:24 54096348: 1
2014-09-05T15: 18: 48.556 + 0800 [clientcursormon] mem (MB) res: 36 virt: 585
2014-09-05T15: 18: 48.556 + 0800 [clientcursormon] mapped (incl journal view): 320
2014-09-05T15: 18: 48.556 + 0800 [clientcursormon] connections: 1
2014-09-05T15: 18: 54.357 + 0800 [replslave] repl: checkpoint applied 15 operations
2014-09-05T15: 18: 54.358 + 0800 [replslave] repl: syncedTo: Sep 5 15:18:44 540963d4: 1

Disable MongoDB:

Method 1:

[Bkjia @ bkjia04 mongodb-linux-x86_64-2.6.4] $ mongod -- shutdown -- dbpath/home/bkjia/mongodb-linux-x86_64-2.6.4/data
Killingprocess with pid: 22745

Method 2:

[Bkjia @ bkjia04 mongodb-linux-x86_64-2.6.4] $ mongo localhost: 10000
MongoDB shell version: 2.6.4
Connecting to: localhost: 10001/test
> Use admin;
Switched to db admin
> Db. shutdownServer ();
2014-09-05T15: 23: 59.910 + 0800 DBClientCursor: init call () failed
Server shocould be down...
2014-09-05T15: 23: 59.912 + 0800 trying reconnect to localhost: 10000 (127.0.0.1) failed
2014-09-05T15: 23: 59.915 + 0800 warning: Failed to connect to 127.0.0.1: 10000, reason: errno: 111 Connection refused
2014-09-05T15: 23: 59.915 + 0800 reconnect localhost: 10000 (127.0.0.1) failed couldn't connect to server localhost: 10000 (127.0.0.1), connection attempt failed
> Exit;
[Bkjia @ bkjia04 ~] $

For more details, please continue to read the highlights on the next page:

  • 1
  • 2
  • Next Page

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.