Wednesday, December 5, 2018

MongoDB Replica set Configuration

cd /u02/mongodb/data

[mongodb@sainath mongodb]$ cd data
[mongodb@sainath data]$ mkdir dbrep_r1
[mongodb@sainath data]$ mkdir dbrep_r2
[mongodb@sainath data]$ mkdir dbrep_r3
[mongodb@sainath data]$ ls -lrtt
total 12
drwxrwxr-x. 2 mongodb mongodb 4096 Nov 28 00:00 dbrep_1
drwxrwxr-x. 2 mongodb mongodb 4096 Nov 28 00:00 dbrep_2
drwxrwxr-x. 2 mongodb mongodb 4096 Nov 28 00:00 dbrep_3
[mongodb@sainath data]$

[mongodb@sainath var]$ mkdir dbrep_r1
[mongodb@sainath var]$ mkdir dbrep_r2
[mongodb@sainath var]$ mkdir dbrep_r3
[mongodb@sainath var]$

/u02/mongodb/var/mongodb/mongod.pid

port : 
37017
37018
37019

vi /u02/mongodb/config/dbrep_r1/dbrep_r1.conf
# mongod.conf
# where to write logging data.
systemLog:
  destination: file
  logAppend: true
  path: /u02/mongodb/var/dbrep_r1/mongod.log

# Where and how to store data.
storage:
  dbPath: /u02/mongodb/data/dbrep_r1
  journal:
    enabled: true
  directoryPerDB: true
#  engine:
#  wiredTiger:

# how the process runs
processManagement:
  fork: true  # fork and run in background
  pidFilePath: /u02/mongodb/var/mongodb/mongod.pid  # location of pidfile

# network interfaces
net:
  port: 37017
  bindIp: 127.0.0.1  # Enter 0.0.0.0,:: to bind to all IPv4 and IPv6 addresses or, alternatively, use the net.bindIpAll setting.
replication:
   replSetName: dbrep_r1
  
vi /u02/mongodb/config/dbrep_r2/dbrep_r2.conf
# mongod.conf
# where to write logging data.
systemLog:
  destination: file
  logAppend: true
  path: /u02/mongodb/var/dbrep_r2/mongod.log

# Where and how to store data.
storage:
  dbPath: /u02/mongodb/data/dbrep_r2
  journal:
    enabled: true
  directoryPerDB: true
# how the process runs
processManagement:
  fork: true  # fork and run in background
  pidFilePath: /u02/mongodb/var/mongodb/mongod.pid  # location of pidfile
# network interfaces
net:
  port: 37018
  bindIp: 127.0.0.1  # Enter 0.0.0.0,:: to bind to all IPv4 and IPv6 addresses or, alternatively, use the net.bindIpAll setting.
replication:
   replSetName: dbrep_r1
  
  
  
vi /u02/mongodb/config/dbrep_r3/dbrep_r3.conf
# mongod.conf
# where to write logging data.
systemLog:
  destination: file
  logAppend: true
  path: /u02/mongodb/var/dbrep_r3/mongod.log

# Where and how to store data.
storage:
  dbPath: /u02/mongodb/data/dbrep_r3
  journal:
    enabled: true
  directoryPerDB: true
# how the process runs
processManagement:
  fork: true  # fork and run in background
  pidFilePath: /u02/mongodb/var/mongodb/mongod.pid  # location of pidfile
# network interfaces
net:
  port: 37019
  bindIp: 127.0.0.1  # Enter 0.0.0.0,:: to bind to all IPv4 and IPv6 addresses or, alternatively, use the net.bindIpAll setting.
replication:
   replSetName: dbrep_r1
   
mongod --config /u02/mongodb/config/dbrep_r1/dbrep_r1.conf   
mongod --config /u02/mongodb/config/dbrep_r2/dbrep_r2.conf   
mongod --config /u02/mongodb/config/dbrep_r3/dbrep_r3.conf   
   



[mongodb@sainath dbrep_r1]$ ps -ef|grep  mongo|grep config
mongodb  12224     1  3 00:41 ?        00:00:14 mongod --config /u02/mongodb/config/dbrep_r1/dbrep_r1.conf
mongodb  13117     1  2 00:47 ?        00:00:02 mongod --config /u02/mongodb/config/dbrep_r2/dbrep_r2.conf
mongodb  13389     1  2 00:48 ?        00:00:00 mongod --config /u02/mongodb/config/dbrep_r3/dbrep_r3.conf
mongodb  13477  4268  0 00:48 pts/1    00:00:00 grep config
[mongodb@sainath dbrep_r1]$

   
mongo --port 37017
mongo --port 37018
mongo --port 37019
   

rs.add( { host: "127.0.0.1:37018", priority: 0 } )
rs.add( { host: "127.0.0.1:37019", priority: 0 } )   


or

rs.add("127.0.0.1:37018");
rs.add("127.0.0.1:37019");

Changing the Priority
======================

cfg=rs.conf()
cfg.members[0].priority=3
cfg.members[1].priority=4
cfg.members[2].priority=3
rs.reconfig(cfg)   
   

No comments:

Post a Comment