MongoDB replica set build and increase or decrease machine

Source: Internet
Author: User
Tags mongo shell

1. Replica set
Each replica set needs to set the replica set name. Specified when the Mongod is started.
2. Build Step 2.1 Start
First start Mongod set to replica set mode when startup, and set the name. Two ways, either through configuration files, or command-line mode. Configuration file:
# Mongodb.confreplset = Replsetname
Command-line mode:
Mongod--replset "Replsetname"

2.2 MONGO Shell
Open MONGO Shell
$./bin/mongo

2.3 Initialization
Use Rs.initiate (): Initialize the replica set in the MONGO shell.
> Rs.initiate ():

2.4 Verification
Verify that initialization is successful.
> rs.conf ();
Returns the following results.
{   "_id": "Replsetname",   "version": 1,   "members": [      {         "_id": 1,         "host": " mongodb0.example.net:27017 "      }   ]}


2.5 Adding an instance
adding instances using Rs.add
> Rs.add ("mongodb1.example.net")

3. View replica set status
Use the following command to view
Returns the following information.
{        "set": "Replisetname",        "date": Isodate ("2014-08-23t07:43:51z"),        "MyState": 2,        "members": [                {                        "_id": 0,                        "name": "mongodb0.example.net:2701",                        "health": 1,                        "state": 2,                        "STATESTR": "Secondary ",                        " uptime ": 3816405,                        " Optime ": Timestamp (1408335342, 1),                        " Optimedate ": Isodate (" 2014-08-18t04 : 15:42z "),                        " Lastheartbeat ": Isodate (" 2014-08-23t07:43:51z "),                        " Lastheartbeatrecv ": Isodate (" 2014-08-23t07:43:50z "),                        " Pingms ": 1,                },

4. Delete a node
Delete using remove
Rs.remove ("mongod3.example.net:27017")

Address: http://blog.csdn.net/yonggang7/article/details/38778729

MongoDB replica set build and increase or decrease machine

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.