Deploying a MongoDB Cluster in Replset mode on CentOS6.6

Source: Internet
Author: User

Deployment method
Deploy mongodb3.0.2 clusters on 3 centos6.6 systems in replica set mode.

Official reference:

http://docs.mongodb.org/manual/tutorial/deploy-replica-set/

http://docs.mongodb.org/manual/tutorial/install-mongodb-on-red-hat/

IP address assignment for the cluster
# node01:192.168.35.173 (PRIMARY node)
# node02:192.168.35.96 (Secondary node)
# node03:192.168.35.174 (Secondary node)

# Add MongoDB's yum source (all nodes)

echo "[mongodb-org-3.0]" >/etc/yum.repos.d/mongodb-org-3.0.repo
echo "Name=mongodb Repository" >>/etc/yum.repos.d/mongodb-org-3.0.repo
echo "baseurl=http://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/3.0/x86_64/" >>/etc/yum.repos.d/ Mongodb-org-3.0.repo
echo "Gpgcheck=0" >>/etc/yum.repos.d/mongodb-org-3.0.repo
echo "Enabled=1" >>/etc/yum.repos.d/mongodb-org-3.0.repo

# Yum installs MongoDB (all nodes)

Yum install-y mongodb-org-3.0.2 mongodb-org-server-3.0.2 mongodb-org-shell-3.0.2 mongodb-org-mongos-3.0.2 mongodb-org-tools-3.0.2
Mkdir-p/data/db && chown-r mongod.mongod/data/

# Modify host name and Hosts file (all nodes)

# vim/etc/sysconfig/network
# sysctl Kernel.hostname=node0001.nemongo.com
# sysctl Kernel.hostname=node0002.nemongo.com
# sysctl Kernel.hostname=node0003.nemongo.com

echo "192.168.35.173 node0001.nemongo.com" >>/etc/hosts
echo "192.168.35.96 node0002.nemongo.com" >>/etc/hosts
echo "192.168.35.174 node0003.nemongo.com" >>/etc/hosts

# Modify the MongoDB configuration file (all nodes)

sed-i ' s/ bind_ip=127.0.0.1 / #bind_ip =127.0.0.1 /g '/etc/mongod.conf
Sed-i ' s/#replSet =setname/replset=ne_aws_01/g '/etc/mongod.conf


# start MongoDB (all nodes)

Service Mongod Start

# Configure the cluster on the MongoDB master node (PRIMARY node)

Mongo
> rs.initiate () # only node0001 above need to execute rs.initiate ()
> rs.conf ()
> rs.add ("node0002.nemongo.com") # node0002 do not perform rs.initiate () above, otherwise you cannot add
> rs.add ("node0003.nemongo.com") # node0003 do not perform rs.initiate () above, otherwise you cannot add
> rs.status () # can view cluster status on each node

> Rs.initiate ()

{

"Info2": "No configuration explicitly specified-making one",

"Me": "node0001.nemongo.com:27017",

"OK": 0,

"ErrMsg": "No host described in new configuration 1 for replica set ne_aws_01 maps to this node",

"Code": 93

}

Ne_aws_01:primary> Rs.add ("node0002.nemongo.com:27017")

{"OK": 1}

Ne_aws_01:primary> Rs.add ("node0003.nemongo.com")

{"OK": 1}

Ne_aws_01:primary> Rs.status ()

{

"Set": "Ne_aws_01",

"Date": Isodate ("2015-05-08t04:49:30.768z"),

"MyState": 1,

"Members": [

{

"_id": 0,

"Name": "node0001.nemongo.com:27017",

"Health": 1,

"State": 1,

"Statestr": "PRIMARY",

"Uptime": 1471,

"Optime": Timestamp (1431060383, 1),

"Optimedate": Isodate ("2015-05-08t04:46:23z"),

"Electiontime": Timestamp (1431059099, 1),

"Electiondate": Isodate ("2015-05-08t04:24:59z"),

"ConfigVersion": 3,

"Self": true

},

{

"_id": 1,

"Name": "node0002.nemongo.com:27017",

"Health": 1,

"State": 2,

"Statestr": "Secondary",

"Uptime": 192,

"Optime": Timestamp (1431060383, 1),

"Optimedate": Isodate ("2015-05-08t04:46:23z"),

"Lastheartbeat": Isodate ("2015-05-08t04:49:29.756z"),

"Lastheartbeatrecv": Isodate ("2015-05-08t04:49:30.263z"),

"Pingms": 1,

"ConfigVersion": 3

},

{

"_id": 2,

"Name": "node0003.nemongo.com:27017",

"Health": 1,

"State": 2,

"Statestr": "Secondary",

"Uptime": 187,

"Optime": Timestamp (1431060383, 1),

"Optimedate": Isodate ("2015-05-08t04:46:23z"),

"Lastheartbeat": Isodate ("2015-05-08t04:49:29.756z"),

"Lastheartbeatrecv": Isodate ("2015-05-08t04:49:29.795z"),

"Pingms": 1,

"Lastheartbeatmessage": "Could not find member-sync from",

"ConfigVersion": 3

}

],

"OK": 1

}

Stop the MongoDB Master node: Service Mongod Stop, when the MongoDB cluster will re-elect to generate a new primary node and view the cluster status on node0002:

Ne_aws_01:primary> Rs.status ()

{

"Set": "Ne_aws_01",

"Date": Isodate ("2015-05-08t04:51:13.359z"),

"MyState": 1,

"Members": [

{

"_id": 0,

"Name": "node0001.nemongo.com:27017",

"Health": 0,

"State": 8,

" statestr": "(not Reachable/healthy)",

"Uptime": 0,

"Optime": Timestamp (0, 0),

"Optimedate": Isodate ("1970-01-01t00:00:00z"),

"Lastheartbeat": Isodate ("2015-05-08t04:51:11.361z"),

"Lastheartbeatrecv": Isodate ("2015-05-08t04:51:11.951z"),

"Pingms": 1,

" lastheartbeatmessage": "Failed attempt to connect to node0001.nemongo.com:27017; Couldn ' t connect to server node0001.nemongo.com:27017 (192.168.35.173), connection attempt failed ",

"ConfigVersion":-1

},

{

"_id": 1,

"Name": "node0002.nemongo.com:27017",

"Health": 1,

"State": 1,

"Statestr": "PRIMARY",

"Uptime": 364,

"Optime": Timestamp (1431060383, 1),

"Optimedate": Isodate ("2015-05-08t04:46:23z"),

"Electiontime": Timestamp (1431060617, 1),

"Electiondate": Isodate ("2015-05-08t04:50:17z"),

"ConfigVersion": 3,

"Self": true

},

{

"_id": 2,

"Name": "node0003.nemongo.com:27017",

"Health": 1,

"State": 2,

"Statestr": "Secondary",

"Uptime": 284,

"Optime": Timestamp (1431060383, 1),

"Optimedate": Isodate ("2015-05-08t04:46:23z"),

"Lastheartbeat": Isodate ("2015-05-08t04:51:13.159z"),

"Lastheartbeatrecv": Isodate ("2015-05-08t04:51:12.703z"),

"Pingms": 1,

"ConfigVersion": 3

}

],

"OK": 1

}

Restart node0001: Service Mongod start, looking at the status of the MongoDB cluster again, you will find that node0001 becomes the secondary node:

Ne_aws_01:secondary> Rs.status ()

{

"Set": "Ne_aws_01",

"Date": Isodate ("2015-05-08t04:53:54.550z"),

"MyState": 2,

"Members": [

{

"_id": 0,

"Name": "node0001.nemongo.com:27017",

"Health": 1,

"State": 2,

"Statestr": "Secondary",

"Uptime": 168,

"Optime": Timestamp (1431060383, 1),

"Optimedate": Isodate ("2015-05-08t04:46:23z"),

"ConfigVersion": 3,

"Self": true

},

{

"_id": 1,

"Name": "node0002.nemongo.com:27017",

"Health": 1,

"State": 1,

"Statestr": "PRIMARY",

"Uptime": 167,

"Optime": Timestamp (1431060383, 1),

"Optimedate": Isodate ("2015-05-08t04:46:23z"),

"Lastheartbeat": Isodate ("2015-05-08t04:53:53.474z"),

"Lastheartbeatrecv": Isodate ("2015-05-08t04:53:52.881z"),

"Pingms": 1,

"Electiontime": Timestamp (1431060617, 1),

"Electiondate": Isodate ("2015-05-08t04:50:17z"),

"ConfigVersion": 3

},

{

"_id": 2,

"Name": "node0003.nemongo.com:27017",

"Health": 1,

"State": 2,

"Statestr": "Secondary",

"Uptime": 167,

"Optime": Timestamp (1431060383, 1),

"Optimedate": Isodate ("2015-05-08t04:46:23z"),

"Lastheartbeat": Isodate ("2015-05-08t04:53:53.474z"),

"Lastheartbeatrecv": Isodate ("2015-05-08t04:53:54.382z"),

"Pingms": 1,

"ConfigVersion": 3

}

],

"OK": 1

}




This article is from the "fireworks easy to cool" blog, please be sure to keep this source http://yuanhuan.blog.51cto.com/3367116/1649374

Deploying a MongoDB Cluster in Replset mode on CentOS6.6

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.