The list of activities for MongoDB replica set config for MongoDB DBA. config MongoDB replica set task in this article.
1. Overview of MongoDB Replica Set config
Before thinking about config replica set MongoDB, let us think about security enable or not. How to enable authentication and authorization in MongoDB is a little bit tricky. There are different options available, and when different options, then you have to choose one of them is a little bit tricky. So, choose one of them, either plain config file or YAML supported file or any other one. However, by default, you find a YAML config file.
How to add keyfile security mechanism on running replica set of MongoDB for enabling auth on MongoDB replica set config.
2. command to spawn child process of mongod
There are two different options here , first is to write command one by one on your terminal to spawn child process of mongod. second, is you can write a Linux shell script to spawn a child process of mongod on different port. And Configure mongod replica set. For linux shell shript you can visit our previous post i.e.
Linux shell script to instantiate different mongod process
3. Run Replica set mongoDB servers
In this section you learn about MongoDB replica set config. I run three different mongod service on three
ranjeetjha@jha:~/mongodb-security/hw-mongo-310/m310-hw-1.2$ ./setup-hw-1.2.sh about to fork child process, waiting until server is ready for connections. forked process: 2889 child process started successfully, parent exiting about to fork child process, waiting until server is ready for connections. forked process: 2903 child process started successfully, parent exiting about to fork child process, waiting until server is ready for connections. forked process: 2927 child process started successfully, parent exiting MongoDB shell version: 3.2.10 connecting to: 127.0.0.1:31120/test { "ok" : 1 }
4. Check Replica set mongod process
Following is the complete output of terminal during the config replica set mongodb.
ranjeetjha@jha:~/mongodb-security/hw-mongo-310/m310-hw-1.2$ ps -ef | grep mongod mongodb 1043 1 0 18:34 ? 00:00:05 /usr/bin/mongod --config /etc/mongod.conf ranjeet+ 2889 1607 0 18:59 ? 00:00:00 mongod --dbpath /home/ranjeetjha/M310-HW-1.2/r0 --logpath /home/ranjeetjha/M310-HW-1.2/r0/mongo.log.log --port 31120 --replSet TO_BE_SECURED --fork ranjeet+ 2903 1607 0 18:59 ? 00:00:00 mongod --dbpath /home/ranjeetjha/M310-HW-1.2/r1 --logpath /home/ranjeetjha/M310-HW-1.2/r1/mongo.log.log --port 31121 --replSet TO_BE_SECURED --fork ranjeet+ 2927 1607 0 18:59 ? 00:00:00 mongod --dbpath /home/ranjeetjha/M310-HW-1.2/r2 --logpath /home/ranjeetjha/M310-HW-1.2/r2/mongo.log.log --port 31122 --replSet TO_BE_SECURED --fork ranjeet+ 3485 2544 0 18:59 pts/1 00:00:00 grep --color=auto mongod ranjeetjha@jha:~/mongodb-security/hw-mongo-310/m310-hw-1.2$ ranjeetjha@jha:~/mongodb-security/hw-mongo-310/m310-hw-1.2$ mongod --dbpath /home/ranjeetjha/M310-HW-1.2/r2 --logpath /home/ranjeetjha/M310-HW-1.2/r2/mongo.log.log --port 31122 --replSet TO_BE_SECURED --fork --auth --keyFile /home/ranjeetjha/M M310-HW-1.2/ Music/ ranjeetjha@jha:~/mongodb-security/hw-mongo-310/m310-hw-1.2$ mongod --dbpath /home/ranjeetjha/M310-HW-1.2/r2 --logpath /home/ranjeetjha/M310-HW-1.2/r2/mongo.log.log --port 31122 --replSet TO_BE_SECURED --fork --auth --keyFile /home/ranjeetjha/M310-HW-1.2/r r0/ r1/ r2/ ranjeetjha@jha:~/mongodb-security/hw-mongo-310/m310-hw-1.2$ mongod --dbpath /home/ranjeetjha/M310-HW-1.2/r2 --logpath /home/ranjeetjha/M310-HW-1.2/r2/mongo.log.log --port 31122 --replSet TO_BE_SECURED --fork --auth --keyFile /home/ranjeetjha/mongodb-security/ chapter_1_authentication.3c02c0a07aa2.zip m310-vagrant-env/ hw-mongo-310/ m310-vagrant-env.04dce7bfaaf1.zip ranjeetjha@jha:~/mongodb-security/hw-mongo-310/m310-hw-1.2$ mongod --dbpath /home/ranjeetjha/M310-HW-1.2/r2 --logpath /home/ranjeetjha/M310-HW-1.2/r2/mongo.log.log --port 31122 --replSet TO_BE_SECURED --fork --auth --keyFile /home/ranjeetjha/mongodb-security/hw-mongo-310/m310-hw-1.2/ mongodb-keyfile setup-hw-1.2.sh validate-hw-1.2.sh ranjeetjha@jha:~/mongodb-security/hw-mongo-310/m310-hw-1.2$ kill -9 2927 ranjeetjha@jha:~/mongodb-security/hw-mongo-310/m310-hw-1.2$ ps -ef | grep mongod mongodb 1043 1 0 18:34 ? 00:00:05 /usr/bin/mongod --config /etc/mongod.conf ranjeet+ 2889 1607 0 18:59 ? 00:00:01 mongod --dbpath /home/ranjeetjha/M310-HW-1.2/r0 --logpath /home/ranjeetjha/M310-HW-1.2/r0/mongo.log.log --port 31120 --replSet TO_BE_SECURED --fork ranjeet+ 2903 1607 0 18:59 ? 00:00:01 mongod --dbpath /home/ranjeetjha/M310-HW-1.2/r1 --logpath /home/ranjeetjha/M310-HW-1.2/r1/mongo.log.log --port 31121 --replSet TO_BE_SECURED --fork ranjeet+ 3654 2544 0 19:03 pts/1 00:00:00 grep --color=auto mongod ranjeetjha@jha:~/mongodb-security/hw-mongo-310/m310-hw-1.2$ ranjeetjha@jha:~/mongodb-security/hw-mongo-310/m310-hw-1.2$ ranjeetjha@jha:~/mongodb-security/hw-mongo-310/m310-hw-1.2$ ranjeetjha@jha:~/mongodb-security/hw-mongo-310/m310-hw-1.2$ ranjeetjha@jha:~/mongodb-security/hw-mongo-310/m310-hw-1.2$ mongod --dbpath /home/ranjeetjha/M310-HW-1.2/r2 --logpath /home/ranjeetjha/M310-HW-1.2/r2/mongo.log.log --port 31122 --replSet TO_BE_SECURED --fork --auth --keyFile /home/ranjeetjha/mongodb-security/hw-mongo-310/m310-hw-1.2/mongodb-keyfile about to fork child process, waiting until server is ready for connections. forked process: 3657 ERROR: child process failed, exited with error number 1 ranjeetjha@jha:~/mongodb-security/hw-mongo-310/m310-hw-1.2$ tail -100f /home/ranjeetjha/M M310-HW-1.2/ Music/ ranjeetjha@jha:~/mongodb-security/hw-mongo-310/m310-hw-1.2$ tail -100f /home/ranjeetjha/M310-HW-1.2/r2/mongo mongod.lock mongo.log.log mongo.log.log.2016-11-14T13-29-31 mongo.log.log.2016-11-14T13-33-35 ranjeetjha@jha:~/mongodb-security/hw-mongo-310/m310-hw-1.2$ tail -100f /home/ranjeetjha/M310-HW-1.2/r2/mongo.log.log 2016-11-14T19:03:35.879+0530 I ACCESS [main] permissions on /home/ranjeetjha/mongodb-security/hw-mongo-310/m310-hw-1.2/mongodb-keyfile are too open ^C ranjeetjha@jha:~/mongodb-security/hw-mongo-310/m310-hw-1.2$ chmod 600 /home/ranjeetjha/mongodb-security/hw-mongo-310/m310-hw-1.2/mongodb-keyfile chmod: changing permissions of ‘/home/ranjeetjha/mongodb-security/hw-mongo-310/m310-hw-1.2/mongodb-keyfile’: Operation not permitted ranjeetjha@jha:~/mongodb-security/hw-mongo-310/m310-hw-1.2$ sudo chmod 600 /home/ranjeetjha/mongodb-security/hw-mongo-310/m310-hw-1.2/mongodb-keyfile [sudo] password for ranjeetjha: ranjeetjha@jha:~/mongodb-security/hw-mongo-310/m310-hw-1.2$ ll /home/ranjeetjha/mongodb-security/hw-mongo-310/m310-hw-1.2/mongodb-keyfile-rw------- 1 root root 1024 Nov 13 22:33 /home/ranjeetjha/mongodb-security/hw-mongo-310/m310-hw-1.2/mongodb-keyfile ranjeetjha@jha:~/mongodb-security/hw-mongo-310/m310-hw-1.2$ mongod --dbpath /home/ranjeetjha/M310-HW-1.2/r2 --logpath /home/ranjeetjha/M310-HW-1.2/r2/mongo.log.log --port 31122 --replSet TO_BE_SECURED --fork --auth --keyFile /home/ranjeetjha/mongodb-security/hw-mongo-310/m310-hw-1.2/mongodb-keyfile about to fork child process, waiting until server is ready for connections. forked process: 3782 ERROR: child process failed, exited with error number 1 ranjeetjha@jha:~/mongodb-security/hw-mongo-310/m310-hw-1.2$ ranjeetjha@jha:~/mongodb-security/hw-mongo-310/m310-hw-1.2$ ranjeetjha@jha:~/mongodb-security/hw-mongo-310/m310-hw-1.2$ openssl rand -base64 756 > /home/ranjeetjha/mongodb-security/mongodbKeyfile ranjeetjha@jha:~/mongodb-security/hw-mongo-310/m310-hw-1.2$ chmod 400 /home/ranjeetjha/mongodb-security/mongodbKeyfile ranjeetjha@jha:~/mongodb-security/hw-mongo-310/m310-hw-1.2$ mongod --dbpath /home/ranjeetjha/M310-HW-1.2/r2 --logpath /home/ranjeetjha/M310-HW-1.2/r2/mongo.log.log --port 31122 --replSet TO_BE_SECURED --fork about to fork child process, waiting until server is ready for connections. forked process: 3854 child process started successfully, parent exiting ranjeetjha@jha:~/mongodb-security/hw-mongo-310/m310-hw-1.2$ mongo --port 31122 MongoDB shell version: 3.2.10 connecting to: 127.0.0.1:31122/test Server has startup warnings: 2016-11-14T19:20:02.199+0530 I CONTROL [initandlisten] 2016-11-14T19:20:02.199+0530 I CONTROL [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/enabled is 'always'. 2016-11-14T19:20:02.199+0530 I CONTROL [initandlisten] ** We suggest setting it to 'never' 2016-11-14T19:20:02.199+0530 I CONTROL [initandlisten] 2016-11-14T19:20:02.199+0530 I CONTROL [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/defrag is 'always'. 2016-11-14T19:20:02.199+0530 I CONTROL [initandlisten] ** We suggest setting it to 'never' 2016-11-14T19:20:02.199+0530 I CONTROL [initandlisten] MongoDB Enterprise TO_BE_SECURED:SECONDARY> use admin switched to db admin MongoDB Enterprise TO_BE_SECURED:SECONDARY> db.shutdownServer() server should be down... 2016-11-14T19:29:02.382+0530 I NETWORK [thread1] trying reconnect to 127.0.0.1:31122 (127.0.0.1) failed 2016-11-14T19:29:02.382+0530 W NETWORK [thread1] Failed to connect to 127.0.0.1:31122, reason: errno:111 Connection refused 2016-11-14T19:29:02.382+0530 I NETWORK [thread1] reconnect 127.0.0.1:31122 (127.0.0.1) failed failed 2016-11-14T19:29:02.385+0530 I NETWORK [thread1] trying reconnect to 127.0.0.1:31122 (127.0.0.1) failed 2016-11-14T19:29:02.385+0530 W NETWORK [thread1] Failed to connect to 127.0.0.1:31122, reason: errno:111 Connection refused 2016-11-14T19:29:02.385+0530 I NETWORK [thread1] reconnect 127.0.0.1:31122 (127.0.0.1) failed failed MongoDB Enterprise > ^C bye ranjeetjha@jha:~/mongodb-security/hw-mongo-310/m310-hw-1.2$ mongod --dbpath /home/ranjeetjha/M310-HW-1.2/r2 --logpath /home/ranjeetjha/M310-HW-1.2/r2/mongo.log.log --port 31122 --replSet TO_BE_SECURED --fork --auth --keyFile /home/ranjeetjha/mongodb-security/mongodbKeyfile about to fork child process, waiting until server is ready for connections. forked process: 3952 child process started successfully, parent exiting ranjeetjha@jha:~/mongodb-security/hw-mongo-310/m310-hw-1.2$ ps -ef | grep mongod mongodb 1043 1 0 18:34 ? 00:00:10 /usr/bin/mongod --config /etc/mongod.conf ranjeet+ 2889 1607 0 18:59 ? 00:00:11 mongod --dbpath /home/ranjeetjha/M310-HW-1.2/r0 --logpath /home/ranjeetjha/M310-HW-1.2/r0/mongo.log.log --port 31120 --replSet TO_BE_SECURED --fork ranjeet+ 2903 1607 0 18:59 ? 00:00:11 mongod --dbpath /home/ranjeetjha/M310-HW-1.2/r1 --logpath /home/ranjeetjha/M310-HW-1.2/r1/mongo.log.log --port 31121 --replSet TO_BE_SECURED --fork ranjeet+ 3952 1607 1 19:29 ? 00:00:00 mongod --dbpath /home/ranjeetjha/M310-HW-1.2/r2 --logpath /home/ranjeetjha/M310-HW-1.2/r2/mongo.log.log --port 31122 --replSet TO_BE_SECURED --fork --auth --keyFile /home/ranjeetjha/mongodb-security/mongodbKeyfile ranjeet+ 4047 2544 0 19:30 pts/1 00:00:00 grep --color=auto mongod ranjeetjha@jha:~/mongodb-security/hw-mongo-310/m310-hw-1.2$ mongo --port 31121 MongoDB shell version: 3.2.10 connecting to: 127.0.0.1:31121/test Server has startup warnings: 2016-11-14T18:59:31.836+0530 I CONTROL [initandlisten] 2016-11-14T18:59:31.836+0530 I CONTROL [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/enabled is 'always'. 2016-11-14T18:59:31.836+0530 I CONTROL [initandlisten] ** We suggest setting it to 'never' 2016-11-14T18:59:31.836+0530 I CONTROL [initandlisten] 2016-11-14T18:59:31.836+0530 I CONTROL [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/defrag is 'always'. 2016-11-14T18:59:31.836+0530 I CONTROL [initandlisten] ** We suggest setting it to 'never' 2016-11-14T18:59:31.836+0530 I CONTROL [initandlisten] MongoDB Enterprise TO_BE_SECURED:SECONDARY> use admin switched to db admin MongoDB Enterprise TO_BE_SECURED:SECONDARY> db.shutdownServer(); server should be down... 2016-11-14T19:31:25.720+0530 I NETWORK [thread1] trying reconnect to 127.0.0.1:31121 (127.0.0.1) failed 2016-11-14T19:31:25.720+0530 W NETWORK [thread1] Failed to connect to 127.0.0.1:31121, reason: errno:111 Connection refused 2016-11-14T19:31:25.720+0530 I NETWORK [thread1] reconnect 127.0.0.1:31121 (127.0.0.1) failed failed 2016-11-14T19:31:25.723+0530 I NETWORK [thread1] trying reconnect to 127.0.0.1:31121 (127.0.0.1) failed 2016-11-14T19:31:25.723+0530 W NETWORK [thread1] Failed to connect to 127.0.0.1:31121, reason: errno:111 Connection refused 2016-11-14T19:31:25.723+0530 I NETWORK [thread1] reconnect 127.0.0.1:31121 (127.0.0.1) failed failed MongoDB Enterprise > ^C bye ranjeetjha@jha:~/mongodb-security/hw-mongo-310/m310-hw-1.2$ mongod --dbpath /home/ranjeetjha/M310-HW-1.2/r1 --logpath /home/ranjeetjha/M310-HW-1.2/r1/mongo.log.log --port 31121 --replSet TO_BE_SECURED --fork --auth --keyFile /home/ranjeetjha/mongodb-security/mongodbKeyfile about to fork child process, waiting until server is ready for connections. forked process: 4090 child process started successfully, parent exiting ranjeetjha@jha:~/mongodb-security/hw-mongo-310/m310-hw-1.2$ mongo --port 31120 MongoDB shell version: 3.2.10 connecting to: 127.0.0.1:31120/test Server has startup warnings: 2016-11-14T18:59:31.012+0530 I CONTROL [initandlisten] 2016-11-14T18:59:31.012+0530 I CONTROL [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/enabled is 'always'. 2016-11-14T18:59:31.012+0530 I CONTROL [initandlisten] ** We suggest setting it to 'never' 2016-11-14T18:59:31.012+0530 I CONTROL [initandlisten] 2016-11-14T18:59:31.012+0530 I CONTROL [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/defrag is 'always'. 2016-11-14T18:59:31.012+0530 I CONTROL [initandlisten] ** We suggest setting it to 'never' 2016-11-14T18:59:31.012+0530 I CONTROL [initandlisten] MongoDB Enterprise TO_BE_SECURED:RECOVERING> use admin switched to db admin MongoDB Enterprise TO_BE_SECURED:RECOVERING> db.^C bye ranjeetjha@jha:~/mongodb-security/hw-mongo-310/m310-hw-1.2$ ps -ef | mongod 2016-11-14T19:34:41.991+0530 I CONTROL [initandlisten] MongoDB starting : pid=4372 port=27017 dbpath=/data/db 64-bit host=jha 2016-11-14T19:34:41.991+0530 I CONTROL [initandlisten] db version v3.2.10 2016-11-14T19:34:41.991+0530 I CONTROL [initandlisten] git version: 79d9b3ab5ce20f51c272b4411202710a082d0317 2016-11-14T19:34:41.991+0530 I CONTROL [initandlisten] OpenSSL version: OpenSSL 1.0.1f 6 Jan 2014 2016-11-14T19:34:41.991+0530 I CONTROL [initandlisten] allocator: tcmalloc 2016-11-14T19:34:41.991+0530 I CONTROL [initandlisten] modules: enterprise 2016-11-14T19:34:41.991+0530 I CONTROL [initandlisten] build environment: 2016-11-14T19:34:41.991+0530 I CONTROL [initandlisten] distmod: ubuntu1404 2016-11-14T19:34:41.991+0530 I CONTROL [initandlisten] distarch: x86_64 2016-11-14T19:34:41.991+0530 I CONTROL [initandlisten] target_arch: x86_64 2016-11-14T19:34:41.991+0530 I CONTROL [initandlisten] options: {} 2016-11-14T19:34:42.013+0530 E NETWORK [initandlisten] listen(): bind() failed errno:98 Address already in use for socket: 0.0.0.0:27017 2016-11-14T19:34:42.013+0530 E NETWORK [initandlisten] addr already in use 2016-11-14T19:34:42.013+0530 E STORAGE [initandlisten] Failed to set up sockets during startup. 2016-11-14T19:34:42.013+0530 I CONTROL [initandlisten] dbexit: rc: 48 ranjeetjha@jha:~/mongodb-security/hw-mongo-310/m310-hw-1.2$ ps -ef | grep mongod mongodb 1043 1 0 18:34 ? 00:00:11 /usr/bin/mongod --config /etc/mongod.conf ranjeet+ 2889 1607 0 18:59 ? 00:00:13 mongod --dbpath /home/ranjeetjha/M310-HW-1.2/r0 --logpath /home/ranjeetjha/M310-HW-1.2/r0/mongo.log.log --port 31120 --replSet TO_BE_SECURED --fork ranjeet+ 3952 1607 0 19:29 ? 00:00:02 mongod --dbpath /home/ranjeetjha/M310-HW-1.2/r2 --logpath /home/ranjeetjha/M310-HW-1.2/r2/mongo.log.log --port 31122 --replSet TO_BE_SECURED --fork --auth --keyFile /home/ranjeetjha/mongodb-security/mongodbKeyfile ranjeet+ 4090 1607 0 19:32 ? 00:00:01 mongod --dbpath /home/ranjeetjha/M310-HW-1.2/r1 --logpath /home/ranjeetjha/M310-HW-1.2/r1/mongo.log.log --port 31121 --replSet TO_BE_SECURED --fork --auth --keyFile /home/ranjeetjha/mongodb-security/mongodbKeyfile ranjeet+ 4403 2544 0 19:35 pts/1 00:00:00 grep --color=auto mongod ranjeetjha@jha:~/mongodb-security/hw-mongo-310/m310-hw-1.2$ mongo --port 31120 MongoDB shell version: 3.2.10 connecting to: 127.0.0.1:31120/test Server has startup warnings: 2016-11-14T18:59:31.012+0530 I CONTROL [initandlisten] 2016-11-14T18:59:31.012+0530 I CONTROL [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/enabled is 'always'. 2016-11-14T18:59:31.012+0530 I CONTROL [initandlisten] ** We suggest setting it to 'never' 2016-11-14T18:59:31.012+0530 I CONTROL [initandlisten] 2016-11-14T18:59:31.012+0530 I CONTROL [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/defrag is 'always'. 2016-11-14T18:59:31.012+0530 I CONTROL [initandlisten] ** We suggest setting it to 'never' 2016-11-14T18:59:31.012+0530 I CONTROL [initandlisten] MongoDB Enterprise TO_BE_SECURED:RECOVERING> use admin switched to db admin MongoDB Enterprise TO_BE_SECURED:RECOVERING> db.shutdownServer(); server should be down... 2016-11-14T19:35:48.903+0530 I NETWORK [thread1] trying reconnect to 127.0.0.1:31120 (127.0.0.1) failed 2016-11-14T19:35:48.903+0530 W NETWORK [thread1] Failed to connect to 127.0.0.1:31120, reason: errno:111 Connection refused 2016-11-14T19:35:48.903+0530 I NETWORK [thread1] reconnect 127.0.0.1:31120 (127.0.0.1) failed failed 2016-11-14T19:35:48.905+0530 I NETWORK [thread1] trying reconnect to 127.0.0.1:31120 (127.0.0.1) failed 2016-11-14T19:35:48.905+0530 W NETWORK [thread1] Failed to connect to 127.0.0.1:31120, reason: errno:111 Connection refused 2016-11-14T19:35:48.905+0530 I NETWORK [thread1] reconnect 127.0.0.1:31120 (127.0.0.1) failed failed MongoDB Enterprise > ^C bye ranjeetjha@jha:~/mongodb-security/hw-mongo-310/m310-hw-1.2$ ps -ef | grep mongod mongodb 1043 1 0 18:34 ? 00:00:11 /usr/bin/mongod --config /etc/mongod.conf ranjeet+ 3952 1607 0 19:29 ? 00:00:02 mongod --dbpath /home/ranjeetjha/M310-HW-1.2/r2 --logpath /home/ranjeetjha/M310-HW-1.2/r2/mongo.log.log --port 31122 --replSet TO_BE_SECURED --fork --auth --keyFile /home/ranjeetjha/mongodb-security/mongodbKeyfile ranjeet+ 4090 1607 0 19:32 ? 00:00:01 mongod --dbpath /home/ranjeetjha/M310-HW-1.2/r1 --logpath /home/ranjeetjha/M310-HW-1.2/r1/mongo.log.log --port 31121 --replSet TO_BE_SECURED --fork --auth --keyFile /home/ranjeetjha/mongodb-security/mongodbKeyfile ranjeet+ 4462 2544 0 19:35 pts/1 00:00:00 grep --color=auto mongod ranjeetjha@jha:~/mongodb-security/hw-mongo-310/m310-hw-1.2$ mongod --dbpath /home/ranjeetjha/M310-HW-1.2/r0 --logpath /home/ranjeetjha/M310-HW-1.2/r0/mongo.log.log --port 31120 --replSet TO_BE_SECURED --fork --auth --keyFile /home/ranjeetjha/mongodb-security/mongodbKeyfile about to fork child process, waiting until server is ready for connections. forked process: 4471 child process started successfully, parent exiting ranjeetjha@jha:~/mongodb-security/hw-mongo-310/m310-hw-1.2$ ps -ef | grep mongod mongodb 1043 1 0 18:34 ? 00:00:11 /usr/bin/mongod --config /etc/mongod.conf ranjeet+ 3952 1607 0 19:29 ? 00:00:03 mongod --dbpath /home/ranjeetjha/M310-HW-1.2/r2 --logpath /home/ranjeetjha/M310-HW-1.2/r2/mongo.log.log --port 31122 --replSet TO_BE_SECURED --fork --auth --keyFile /home/ranjeetjha/mongodb-security/mongodbKeyfile ranjeet+ 4090 1607 0 19:32 ? 00:00:02 mongod --dbpath /home/ranjeetjha/M310-HW-1.2/r1 --logpath /home/ranjeetjha/M310-HW-1.2/r1/mongo.log.log --port 31121 --replSet TO_BE_SECURED --fork --auth --keyFile /home/ranjeetjha/mongodb-security/mongodbKeyfile ranjeet+ 4471 1607 8 19:36 ? 00:00:00 mongod --dbpath /home/ranjeetjha/M310-HW-1.2/r0 --logpath /home/ranjeetjha/M310-HW-1.2/r0/mongo.log.log --port 31120 --replSet TO_BE_SECURED --fork --auth --keyFile /home/ranjeetjha/mongodb-security/mongodbKeyfile ranjeet+ 4546 2544 0 19:36 pts/1 00:00:00 grep --color=auto mongod ranjeetjha@jha:~/mongodb-security/hw-mongo-310/m310-hw-1.2$ ranjeetjha@jha:~/mongodb-security/hw-mongo-310/m310-hw-1.2$ ranjeetjha@jha:~/mongodb-security/hw-mongo-310/m310-hw-1.2$
5. check replica set config
You can connect mongoDB database my mongo shell for configuration of mongodb replica set.
ranjeetjha@jha:~/mongodb-security/hw-mongo-310/m310-hw-1.2$ mongo --port 31120 MongoDB shell version: 3.2.10 connecting to: 127.0.0.1:31120/test MongoDB Enterprise TO_BE_SECURED:SECONDARY> rs.status(); { "set" : "TO_BE_SECURED", "date" : ISODate("2016-11-14T14:07:06.209Z"), "myState" : 2, "term" : NumberLong(2), "syncingTo" : "jha:31122", "heartbeatIntervalMillis" : NumberLong(2000), "members" : [ { "_id" : 1, "name" : "jha:31120", "health" : 1, "state" : 2, "stateStr" : "SECONDARY", "uptime" : 33, "optime" : { "ts" : Timestamp(1479132142, 1), "t" : NumberLong(2) }, "optimeDate" : ISODate("2016-11-14T14:02:22Z"), "syncingTo" : "jha:31122", "configVersion" : 1, "self" : true }, { "_id" : 2, "name" : "jha:31121", "health" : 1, "state" : 1, "stateStr" : "PRIMARY", "uptime" : 31, "optime" : { "ts" : Timestamp(1479132142, 1), "t" : NumberLong(2) }, "optimeDate" : ISODate("2016-11-14T14:02:22Z"), "lastHeartbeat" : ISODate("2016-11-14T14:07:04.690Z"), "lastHeartbeatRecv" : ISODate("2016-11-14T14:07:04.963Z"), "pingMs" : NumberLong(0), "electionTime" : Timestamp(1479132141, 1), "electionDate" : ISODate("2016-11-14T14:02:21Z"), "configVersion" : 1 }, { "_id" : 3, "name" : "jha:31122", "health" : 1, "state" : 2, "stateStr" : "SECONDARY", "uptime" : 31, "optime" : { "ts" : Timestamp(1479132142, 1), "t" : NumberLong(2) }, "optimeDate" : ISODate("2016-11-14T14:02:22Z"), "lastHeartbeat" : ISODate("2016-11-14T14:07:04.690Z"), "lastHeartbeatRecv" : ISODate("2016-11-14T14:07:04.964Z"), "pingMs" : NumberLong(0), "syncingTo" : "jha:31121", "configVersion" : 1 } ], "ok" : 1 }
6. Reference
You can visit docs.mongodb.com for more details.
Thanks for visiting this post for MongoDB replica set config. You can also visit MongoDB Tutorial Listing page for more articles on MongoDB document-oriented database.
Happy Learning 🙂 for MongoDB replica set config.