"MONGODB" Verification MONGODB master-slave replication

Source: Internet
Author: User
Tags db2 file copy mkdir mongodb dochub
1 Experiment master-slave replication and verify replication success
2 experimental replica set, and verify that the auto switch primary successful.

=======================================================================
1.1. Start Master node:
Mongod-dbpath=d:\program_file\mongo\db1-logpath=d:\program_file\mongo\log\mongodb1.log--port 18001--master-- Rest--nojournal


1.2. Start the SLAVE1 node:
Mongod-dbpath=d:\program_file\mongo\db2-logpath=d:\program_file\mongo\log\mongodb2.log--port 18002--slave--rest --nojournal--source localhost:18001

1.3. Start the Slave2 node:
Mongod-dbpath=d:\program_file\mongo\db3-logpath=d:\program_file\mongo\log\mongodb2.log--port 18003--slave--rest --nojournal--source localhost:18001



1.4. Open the main library and create a new library and table:


D:\program_file\mongo\mongodb\bin>mongo-port 18001
MongoDB Shell version:2.4.8
Connecting To:127.0.0.1:18001/test
Server has startup warnings:
Thu Mar 11:36:06.084 [Initandlisten]
Thu 11:36:06.084 [Initandlisten] * * Note:this is a bit MongoDB binary.
Thu 11:36:06.084 [Initandlisten] * * Bit builds are limited to less than 2GB of data (or less with--journa L).
Thu 11:36:06.084 [Initandlisten] * * * This journaling defaults to out for bit and are currently off.
Thu Mar 11:36:06.084 [Initandlisten] * * * http://dochub.mongodb.org/core/32bit
Thu Mar 11:36:06.084 [Initandlisten]
Thu Mar 11:36:06.192 [Initandlisten]
Thu 11:36:06.192 [Initandlisten] * * Warning:mongod started without--replset yet 1 documents are present in local. System.replset
Thu 11:36:06.192 [Initandlisten] * * Restart with--replset unless-are doing-maintenance and no other C Lients are connected.
Thu 11:36:06.192 [Initandlisten] * * * The TTL collection monitor would not start because to this.
Thu 11:36:06.192 [Initandlisten] * * For more info | http://dochub.mongodb.org/core/ttlcollections
Thu Mar 11:36:06.192 [Initandlisten]
> Show DBS;
Admin 0.0625GB
Local 0.15625GB
Maketion 0.0625GB
MyDB 0.0625GB
> Use test
Switched to DB test
> Db.test.insert ({_id:1,name: "Name_test"});
> Db.test.find ()
{"_id": 1, "name": "Name_test"}



1.5. Open from the library to see if the newly established database and table are synchronized:
D:\program_file\mongo\mongodb\bin>mongo-port 18002
MongoDB Shell version:2.4.8
Connecting To:127.0.0.1:18002/test
Server has startup warnings:
Thu Mar 11:44:17.236 [Initandlisten]
Thu 11:44:17.236 [Initandlisten] * * Note:this is a bit MongoDB binary.
Thu 11:44:17.236 [Initandlisten] * * Bit builds are limited to less than 2GB of data (or less with--journa L).
Thu 11:44:17.236 [Initandlisten] * * * This journaling defaults to out for bit and are currently off.
Thu Mar 11:44:17.236 [Initandlisten] * * * http://dochub.mongodb.org/core/32bit
Thu Mar 11:44:17.236 [Initandlisten]
Thu Mar 11:44:17.263 [Initandlisten]
Thu 11:44:17.263 [Initandlisten] * * Warning:mongod started without--replset yet 1 documents are present in local. System.replset
Thu 11:44:17.263 [Initandlisten] * * Restart with--replset unless-are doing-maintenance and no other C Lients are connected
Thu 11:44:17.263 [Initandlisten] * * * The TTL collection monitor would not start because to this.
Thu 11:44:17.263 [Initandlisten] * * For more info | http://dochub.mongodb.org/core/ttlcollections
Thu Mar 11:44:17.263 [Initandlisten]
> Show DBS;
Admin 0.0625GB
Local 0.09375GB
Maketion 0.0625GB
MyDB 0.0625GB
Test 0.0625GB
> Use test;
Switched to DB test
> Show Collections;
System.indexes
Test
> Db.test.find ();
{"_id": 1, "name": "Name_test"}
>

As you can see, a new library test is created, and the table: Test and data are synchronized.

-----------------------------------------------------------------------------------
2 experimental replica set, and verify the automatic switching primary successful, grasping the graph experiment process

The following is configured as a Replset test environment for the previous period:

2.1 Establishment of the relevant directory:
mkdir D:\Program_file\mongo\key
mkdir D:\PROGRAM_FILE\MONGO\DB1
mkdir D:\PROGRAM_FILE\MONGO\DB2
mkdir D:\PROGRAM_FILE\MONGO\DB3
mkdir D:\PROGRAM_FILE\MONGO\DB4



D:\Program_file\mongo\mongodb\bin\mongod.exe--replset rs1--keyfile d:\program_file\mongo\key\r0-dbpath=d:\ Program_file\mongo\db1-logpath=d:\program_file\mongo\log\mongodb.log--logappend--journal--port 28010


D:\Program_file\mongo\mongodb\bin\mongod.exe--replset rs1--keyfile d:\program_file\mongo\key\r1-dbpath=d:\ Program_file\mongo\db1-logpath=d:\program_file\mongo\log\mongodb1.log--logappend--journal--port 28011

D:\Program_file\mongo\mongodb\bin\mongod.exe--replset rs1--keyfile d:\program_file\mongo\key\r2-dbpath=d:\ Program_file\mongo\db2-logpath=d:\program_file\mongo\log\mongodb2.log--logappend--journal--port 28012

D:\Program_file\mongo\mongodb\bin\mongod.exe--replset rs1--keyfile d:\program_file\mongo\key\r3-dbpath=d:\ Program_file\mongo\db3-logpath=d:\program_file\mongo\log\mongodb3.log--logappend--journal--port 28013

--After file copy add--fastsync parameter to start (copy if not primary, the node before the start copy will become primary)
D:\Program_file\mongo\mongodb\bin\mongod.exe--replset rs1--keyfile d:\program_file\mongo\key\r4-dbpath=d:\ Program_file\mongo\db4-logpath=d:\program_file\mongo\log\mongodb4.log--logappend--journal--port 28014--fastsync


#share:

D:\Program_file\mongo\mongodb\bin\mongod.exe--shardsvr--port 20000-dbpath=d:\program_file\mongo\shard\shard0\db -logpath=d:\program_file\mongo\shard\shard0\log\mongo.log--logappend--journal--directoryperdb

D:\Program_file\mongo\mongodb\bin\mongod.exe--shardsvr--port 20001-dbpath=d:\program_file\mongo\shard\shard1\db -logpath=d:\program_file\mongo\shard\shard1\log\mongo.log--logappend--journal--directoryperdb

#config
D:\Program_file\mongo\mongodb\bin\mongod.exe--configsvr--port 30000-dbpath=d:\program_file\mongo\shard\config- Logpath=d:\program_file\mongo\shard\config\mongo.log--logappend--journal--directoryperdb

#route
D:\Program_file\mongo\mongodb\bin\mongos.exe--port 40000--configdb localhost:30000--logpath=d:\program_file\ Mongo\shard\config\route.log--logappend--chunksize 1

2.2 Configuration RS

config_rs1={_id: ' Rs1 ', members:[
{_id:0,host: ' localhost:28010 ', priority:1},
{_id:0,host: ' localhost:28011 '},
{_id:0,host: ' localhost:28012 '},
{_id:0,host: ' localhost:28013 '},
{_id:0,host: ' localhost:28014 '}]};
Rs.initiat (CONFIG_RS1);

2.3 Off Primary,

rs1:primary> Use admin
Rs1:primary> RunCommand ("shutdown");


2.4 #登录另一节点:

D:\program_file\mongo\mongodb\bin>mongo-port 28011
MongoDB Shell version:2.4.8
Connecting To:127.0.0.1:28011/test
Server has startup warnings:
Thu Mar 13:55:23.541 [Initandlisten]
Thu 13:55:23.541 [Initandlisten] * * Note:this is a bit MongoDB binary.
Thu 13:55:23.541 [Initandlisten] * * Bit builds are limited to less than 2GB of data (or less with--journa L).
Thu Mar 13:55:23.541 [Initandlisten] * * * http://dochub.mongodb.org/core/32bit
Thu Mar 13:55:23.541 [Initandlisten]
Rs1:primary> Rs.status ()
{
"Set": "Rs1",
"Date": Isodate ("2014-03-13t05:58:52z"),
"MyState": 1,
"Members": [
{
"_id": 0,
"Name": "localhost:28010",
"Health": 0,
"State": 8,
"Statestr": "(not Reachable/healthy)",
"Uptime": 0,
"Optime": Timestamp (0, 0),
"Optimedate": Isodate ("1970-01-01t00:00:00z"),
"Lastheartbeat": Isodate ("2014-03-13t05:58:50z"),
"Lastheartbeatrecv": Isodate ("1970-01-01t00:00:00z"),
"Pingms": 0
},
{
"_id": 1,
"Name": "localhost:28011",
"Health": 1,
"State": 1,
"Statestr": "PRIMARY",
"Uptime": 209,
"Optime": Timestamp (1389939638, 1),
"Optimedate": Isodate ("2014-01-17t06:20:38z"),
' Self ': true
},
{
"_id": 2,
"Name": "localhost:28012",
"Health": 1,
"State": 2,
"Statestr": "Secondary",
"Uptime": 197,
"Optime": Timestamp (1389939638, 1),
"Optimedate": Isodate ("2014-01-17t06:20:38z"),
"Lastheartbeat": Isodate ("2014-03-13t05:58:51z"),
"Lastheartbeatrecv": Isodate ("2014-03-13t05:58:51z"),
"Pingms": 0,
"Syncingto": "localhost:28011"
},
{
"_id": 3,
"Name": "localhost:28013",
"Health": 1,
"State": 2,
"Statestr": "Secondary",
"Uptime": 193,
"Optime": Timestamp (1389939638, 1),
"Optimedate": Isodate ("2014-01-17t06:20:38z"),
"Lastheartbeat": Isodate ("2014-03-13t05:58:51z"),
"Lastheartbeatrecv": Isodate ("2014-03-13t05:58:51z"),
"Pingms": 0,
"Syncingto": "localhost:28011"
}
],
"OK": 1
}
Rs1:primary>
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.