Last active
December 19, 2015 04:09
-
-
Save williamchang73/5895519 to your computer and use it in GitHub Desktop.
mongo replica set setting
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Replica set : | |
P1 : ( Primary ) | |
S1 : ( Sec 1 ) | |
A2 : ( Arbiter ) | |
1. start mongo with replica in all instance | |
stop iptables | |
service iptables stop for all instances | |
check if process exist run with replica | |
ps -ef | grep mongo | |
mongod 964 1 0 05:06 ? 00:00:01 /usr/bin/mongod -f /etc/mongod.conf | |
stop the mongo | |
service mongod stop | |
restart with replica | |
mkdir /srv/mongodb/rs0-0 | |
/usr/bin/mongod --port 27017 --dbpath /srv/mongodb/rs0-0 --replSet rs0 --smallfiles --oplogSize 128 | |
--smallfiles --oplogSize 128 ( for testing ) | |
waiting for a while | |
into mongo shell - the primary one | |
check replica set status | |
> rs.status() | |
if running with replSet, it should show info with need to initiate | |
initiate set | |
> cfg = {"_id" : "rs0","members" : [{"_id" : 0,"host" : "ec2-54-245-53-45.us-west-2.compute.amazonaws.com:27017"}]} | |
> rs.initiate(cfg) | |
verify | |
> rs.conf() | |
rs0:PRIMARY> | |
> db.isMaster() | |
2. add members | |
in other node | |
service iptables stop | |
mkdir /srv/mongodb/rs0-1 | |
> /usr/bin/mongod --port 27017 --dbpath /srv/mongodb/rs0-1 --replSet rs0 --smallfiles --oplogSize 128 | |
in Primary | |
> rs.add( "<node's public ip>:27017" ) | |
> rs.conf() | |
3. add arbiter | |
in arbiter node | |
service iptables stop | |
mkdir /srv/mongodb/arb | |
> mongod --port 30000 --dbpath /srv/mongodb/arb --replSet rs0 --smallfiles --oplogSize 128 | |
in Primary | |
> rs.addArb("<node's public ip>:30000") | |
> rs.conf() | |
Done | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment