MongoDB Replica set deployment

Source: Internet
Author: User

Deploying Replication Sets

A replica set consisting of three nodes provides sufficient redundancy for network failure or other system failures. The replica set also has the ability to have sufficient distributed read operations. The replica set should maintain an odd number of nodes, which will ensure that the election will proceed normally.

Deploy a three-node replica set with 3 existing Mongod instances

192.168.1.3 hadoop1.abc.com HADOOP1
192.168.1.4 hadoop2.abc.com HADOOP2
192.168.1.5 hadoop3.abc.com HADOOP3

Considerations for deploying replication sets schema

In a production environment, we should deploy each node on a separate machine and use the standard MongoDB port 27017 . Use the bind_ip parameter to restrict the address of the application that accesses MongoDB.

If you are using a replicated set of geo-distributed schemas, make sure that most mongod instance nodes are in the primary data center.

Connectivity of

Ensure that each node communicates properly, and that each client is in a secure, trusted network environment. Here are some things to consider:

    • Establish a virtual private network. Ensure that the traffic between the nodes is routed within the local network scope. (Establish a virtual private network.) Ensure that your network topology routes all traffic between members within a single site over the local area network.)

    • Configure connection limits to prevent unknown clients from connecting to the replica set.

    • Configure the network settings and firewall rules to open the MongoDB port to the application only, so that the application sends the incoming and outgoing packets that can communicate with MongoDB normally.

Finally, make sure that each node of the replica set can be resolved by DNS or hostname. We need to configure the DNS domain name or set the /etc/hosts file to configure.

The experiment here is to turn off the firewall and set the SELinux to Setenforce 0

Detailed steps

1, establish each node to establish the data directory

[Email protected] ~]# mkidr-pv/mongodb/data/

[Email protected] ~]# chown mongod.mongod/mongodb/data/

2 start each node in the replication set with the appropriate configuration parameters.

Start mongod on each node and specify its replica set name by developing the Replset parameter, and you can specify other required parameters

[Email protected] ~]# vim/etc/mongod.conf

Add the following

#Replica Set
Replset = Testrs0

Or

[Email protected] ~]# mongod--replset "Testrs0"

Ensure that each node has the same replica set name

[Email protected] ~]# scp/etc/mongod.conf [email protected]:/etc/;scp/etc/mongod.conf [email protected] :/etc/;

Note If the addr already in usage error occurs when you resolve the startup Mongod, the reason the boot port is occupied

[Email protected] data]# Mongod
2015-07-29t19:15:51.728+0800 E NETWORK [Initandlisten] Listen (): Bind () failed errno:98 Address already in use for socket : 0.0.0.0:27017
2015-07-29t19:15:51.728+0800 E NETWORK [Initandlisten] addr already in use
2015-07-29t19:15:51.729+0800 I STORAGE [Initandlisten] exception in initandlisten:29 Data directory/data/db not found., Terminating
2015-07-29t19:15:51.729+0800 I CONTROL [Initandlisten] dbexit:rc:100

Find the port, kill it.

[Email protected] ~]# Netstat-anp|more

UNIX 2 [ACC] STREAM LISTENING 15588 2174/mongod/tmp/mongodb-27017.sock

[[email protected] ~]# kill 2174

[[email protected] ~]#/etc/init.d/mongod start
Starting mongod: [OK]

3. OpenMONGOinterface and connect to a node of the replica set.

[Email protected] ~]# MONGO

4. Initialize the replica set.

Using the Rs.initiate () command, MongoDB Initializes a copy set that is composed of the current node and has a default configuration.

> Rs.initiate ()
{
"Info2": "No configuration explicitly specified-making one",
"Me": "hadoop1.abc.com:27017",
"Info": "Try querying local.system.replset to see current Configuration",
"OK": 0,
"ErrMsg": "Already initialized",
"Code": 23
}

> Rs.status ()
{
"State": 10,
"Statestr": "Removed",
"Uptime": 38,
"Optime": Timestamp (1438168698, 1),
"Optimedate": Isodate ("2015-07-29t11:18:18z"),
"OK": 0,
"ErrMsg": "Our replica set config was invalid or we are not a member of it",
"Code": 93
}

viewing log files

2015-07-29t20:00:45.433+0800 W NETWORK [Replicationexecutor] Failed to connect to 192.168.1.3:27017, reason:errno:111 Co Nnection refused
2015-07-29t20:00:45.433+0800 W REPL [replicationexecutor] locally stored replica set configuration does not has a Val ID entry for the current node; Waiting for reconfig or remote heartbeat; Got "Nodenotfound No host described in new configuration 1 for replica set TESTRS0 maps to this node" while validating {_ ID: "Testrs0", Version:1, Members: [{_id:0, Host: "hadoop1.abc.com:27017", Arbiteronly:false, Buildindexes:true, HID Den:false, priority:1.0, tags: {}, slavedelay:0, votes:1}], settings: {chainingallowed:true, Heartbeattimeoutsecs: Ten, Getlasterrormodes: {}, Getlasterrordefaults: {w:1, wtimeout:0}}}
2015-07-29t20:00:45.433+0800 I REPL [replicationexecutor] New replica set config in use: {_id: "Testrs0", Version:1, Members: [{_id:0, Host: "hadoop1.abc.com:27017", Arbiteronly:false, Buildindexes:true, Hidden:false, priority:1.0, Tags: {}, slavedelay:0, votes:1}], settings: {chainingallowed:true, heartbeattimeoutsecs:10, getlasterrormodes: {} , Getlasterrordefaults: {w:1, wtimeout:0}}}
2015-07-29t20:00:45.433+0800 I REPL [Replicationexecutor] This node was not a member of the Config
2015-07-29t20:00:45.433+0800 I REPL [replicationexecutor] transition to removed
2015-07-29t20:00:45.433+0800 I REPL [replicationexecutor] Starting replication applier threads
2015-07-29t20:00:49.067+0800 I NETWORK [Initandlisten] connection accepted from 127.0.0.1:58852 #1 (1 connection now OPEN )
2015-07-29t20:01:17.436+0800 I COMMAND [conn1] Replset info initiate:no configuration specified. Using a default configuration for the set
2015-07-29t20:01:17.436+0800 I COMMAND [conn1] Replset created this configuration for initiation: {_id: "Testrs0", vers Ion:1, Members: [{_id:0, Host: ' hadoop1.abc.com:27017 '}]}
2015-07-29t20:01:17.436+0800 I REPL [conn1] replsetinitiate Admin command received from client

[[Email protected] ~]# service Mongod stop
stopping mongod: [OK]
You have new mail in/var/spool/mail/root
[Email protected] ~]# vim/etc/mongod.conf

Opens the

Bind 127.0.0.1 restricts local access to the

#bind 127.0.0.1

[[Email protected] data]# service Mongod start
Starting mongod: [OK]

> Rs.initiate ()
{
"Info2": "No configuration explicitly specified-making one",
"Me": "hadoop1.abc.com:27017",
"Info": "Try querying local.system.replset to see current Configuration",
"OK": 0,
"ErrMsg": "Already initialized",
"Code": 23

Testrs0:primary> Rs.status ()
{
"Set": "Testrs0",
"Date": Isodate ("2015-07-29t12:13:27.839z"),
"MyState": 1,
"Members": [
{
"_id": 0,
"Name": "hadoop1.abc.com:27017",
"Health": 1,
"State": 1,
"Statestr": "PRIMARY",
"Uptime": 232,
"Optime": Timestamp (1438168698, 1),
"Optimedate": Isodate ("2015-07-29t11:18:18z"),
"Electiontime": Timestamp (1438171776, 1),
"Electiondate": Isodate ("2015-07-29t12:09:36z"),
"ConfigVersion": 1,
"Self": true
}
],
"OK": 1
}

5. Add other nodes to the replica set.

Add the remaining nodes to the replica set by Rs.add () .

MongoDB Replica set deployment

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.