The construction of MongoDB cluster

Source: Internet
Author: User
Tags mongodb client mongodb server mongo shell

first, the environment preparation
1, Centos7
2, mongodb3.4.10
3. Three machine IPs are: 192.168.1.100, 192.168.1.135, 192.168.1.136

second, the installation of MONGDB database
1, respectively in three machines for mongdb installation, specific reference to the previous tutorial MongoDB installation and Configuration

2. Start MongoDB on three machines respectively, the specific command is as follows

[Email protected] mongodb]#/bin/mongod-f mongodb-config/server.conf--replset Mongotestfuben
Where –replset represents the replica cluster parameters, Mongotestfuben is the replica set name, where the name can be arbitrarily taken, and the other two machines will be the same

If you start successfully you will see a prompt similar to the following

About-to-fork child process, waiting until server was ready for connections.
Forked process:3805
Child process started successfully, parent exiting

iii. Configuring a MongoDB replica set
The first thing to do is to initialize the MongoDB replica set by simply initializing the replica set at any one of the servers.
1, connect any one, such as IP 100, into the MONGO shell operation

You can directly use the MONGO command in the bin directory, such as/bin/mongo -port 27017

Also can use the remote client, I installed the MongoDB client on the remote computer, and configured the environment variable, the operation is more convenient, so the remote computer's cmd window to connect 100 of the MongoDB server

C:\Users\zxp>mongo 192.168.220.100:27017
MongoDB shell version v3.4.9
connecting to: 192.168.220.100:27017
MongoDB server version: 3.4.10


2、进入admin库
use admin

3. MONGO Copy Configuration

Copy the following configuration directly or before you edit it in advance.

config={_id: "Mongotestfuben", Members:[{_id:1,host: "192.168.220.100:27017"},{_id:2,host: "192.168.220.135:27017" },{_id:3,host: "192.168.220.136:27017"}]}

Then execute the following command

Rs.initiate (config)

Display {"OK": 1}, which indicates success of initialization

This makes it possible to use a replica cluster.

Finally, add a few more orders.

    1. rs.add("host:port")+ = Add a node

    2. rs.remove("host:port")= Delete Member

    3. rs.config()= = View Replica set configuration

    4. rs.reconfig(config)+ = Reconfigure the replica set according to the Config configuration object

    5. rs.isMaster 查看主节点信息等

Reference: MongoDB3.4.2 cluster setup in Centos 7

MongoDB replica Set related commands

The construction of MongoDB cluster

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.