MongoDB replica set building and adding/Removing Machines

Source: Internet
Author: User
Tags install mongodb mongo shell

MongoDB replica set building and adding/Removing Machines

1. replica set

You must set the replica set name for each replica set.

This parameter is specified when MongoDB is started.

2. Setup steps

2.1 start

Start MongoDB first

Set to replica set mode and name at startup.

You can use either the configuration file or the command line mode.

Configuration file:

01. # mongodb. conf
02.
03. replSet = replsetname

Command Line Mode:

Mongod -- replSet "replsetname"

2.2 mongo shell

Open mongo shell

$./Bin/mongo

2.3 Initialization

Use rs. initiate () in mongo shell: initializes the replica set.

> Rs. initiate ():

2.4 Verification

Verify whether the initialization is successful.

> Rs. conf ();

The following result is returned.

01 .{
02. "_ id": "replsetname ",
03. "version": 1,
04. "members ":[
05 .{
06. "_ id": 1,
07. "host": "Maid: 27017"
08 .}
09.]
10 .}

2.5 add an instance

Use rs. add to add an instance

> Rs. add ("mongodb1.example.net ")

3. View replica set status

Run the following command to view

> Rs. status ()

Return the following information.

01 .{
02. "set": "replisetname ",
03. "date": ISODate ("2014-08-23T07: 43: 51Z "),
04. "myState": 2,
05. "members ":[
06 .{
07. "_ id": 0,
08. "name": "mongodb0.example.net: 2701 ",
09. "health": 1,
10. "state": 2,
11. "stateStr": "SECONDARY ",
12. "uptime": 3816405,
13. "optime": Timestamp (1408335342, 1 ),
14. "optimeDate": ISODate ("2014-08-18T04: 15: 42Z "),
15. "lastHeartbeat": ISODate ("2014-08-23T07: 43: 51Z "),
16. "lastHeartbeatRecv": ISODate ("2014-08-23T07: 43: 50Z "),
17. "pingMs": 1,
18 .},

4. delete a node

Delete use remove

Rs. remove ("mongod3.example.net: 27017 ")

-------------------------------------- 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 --------------------------------------

MongoDB details: click here
MongoDB: click here

This article permanently updates the link address:

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.