ReplicaSet – Deployment

1. Become the Sudo user


[[email protected] ~]$ sudo su [sudo] password for tom:



2. Create separate database directories for each Mongod process


[[email protected] ~]$ sudo su [sudo] password for tom:

[[email protected] tom]# cd /var/lib/mongo [[email protected] mongo]# mkdir replicaset0 [[email protected] mongo]# mkdir replicaset1 [[email protected] mongo]# mkdir replicaset2



3. Start the first Mongod process on port 27017


[[email protected] mongo]# mongod --port 27017 -dbpath /var/lib/mongo/replicaset0 --logpath /var/lib/mongo/replicaset0/log --replSet myreplicaset --fork --smallfiles --nojournal


about to fork child process, waiting until server is ready for connections. forked process: 2984

child process started successfully, parent exiting



4. Start the second Mongod process on port 27018


[[email protected] mongo]# mongod --port 27018 -dbpath /var/lib/mongo/replicaset1 --logpath /var/lib/mongo/replicaset1/log --replSet myreplicaset --fork --smallfiles --nojournal


about to fork child process, waiting until server is ready for connections. forked process: 3036

child process started successfully, parent exiting

5. Start the third Mongod process on port 27019


[[email protected] mongo]# mongod --port 27019 -dbpath /var/lib/mongo/replicaset2 --logpath /var/lib/mongo/replicaset2/log --replSet myreplicaset --fork --smallfiles --nojournal


about to fork child process, waiting until server is ready for connections. forked process: 3082
child process started successfully, parent exiting



6. Log into the Console of the first Mongod Process on port 27017


[[email protected] ~]$ mongo --port 27017


MongoDB shell version: 2.6.3 connecting to: 127.0.0.1:27017/test

>



7.	Initiate the Replica Set 


>	rs.initiate() 


{

"info2" : "no configuration explicitly specified -- making one", "me" : "localhost.localdomain:27017",

"info" : "Config now saved locally. Should come online in about a minute.",
"ok" : 1

}



8. Press enter after a second or so and you must see this


myreplicaset:PRIMARY>
9. Add members to the Replica set


Syntax: myreplicaset:PRIMARY> rs.add("<hostname>:<port>")


myreplicaset:PRIMARY> rs.add("localhost.localdomain:27018")


{ "ok" : 1 } 



10.	Do the same for the Mongod process on port 27019 


myreplicaset:PRIMARY> rs.add("localhost.localdomain:27019") 


{ "ok" : 1 } 

Leave a Reply

Your email address will not be published.