Jump to content

Mongo DB Doc Prepared @ AIRTEL for DT Project

From TetraWiki
MongoDB installation and configuration guide


Note:- Make sure that when u do any configuration on mongo database server. Stop the server before working on it.


1.Use below command to download the mongo database.

curl -O http://downloads.mongodb.org/linux/mongodb-linux-x86_64-2.4.9.tgz


2. Extract the downloded file to specified location


[root@DTdb opt]# tar -zxvf mongodb-linux-x86_64-2.4.9.tgz


3. Rename the extracted file. PFB

[root@DTdb opt]#mv mongodb-linux-i686-2.4.9 mongodb


4. Create directory inside the mongodb folder


[root@DTdb mongodb]# mkdir conf
[root@DTdb mongodb]#mkdir data


5. Create a file under the conf directory


[root@DTdb mongodb]# vim soptree.conf
##insert the below entries on that file.##
verbose = true
vvvv = true
port = 27017
#bind_ip = 127.0.0.1
logpath = /opt/mongodb/db.log
logappend = true
fork = true
auth = true
dbpath = /opt/mongodb/data/


6. Create Rc script for the mongodb


[root@DTdb conf]# vim /etc/init.d/mongodb
#!/bin/bash
#
# mongodb Startup script for the mongodb server
#
# chkconfig: - 64 36
# description: MongoDB Database Server
#
# processname: mongodb
#
# Source function library
. /etc/rc.d/init.d/functions
if [ -f /etc/sysconfig/mongodb ]; then
. /etc/sysconfig/mongodb
fi
prog="mongod"
mongod="/opt/mongodb/bin/mongod -config /opt/mongodb/conf/soptree.conf"
#mongod="/opt/mongodb/bin/mongod"
RETVAL=0
start() {
echo -n $"Starting $prog: "
#daemon $mongod "--fork --logpath /var/log/mongodb.log --logappend 2>&1 >>/var/log/mongodb.log"
daemon $mongod "--fork --logpath /opt/mongodb/db.log --logappend 2>&1 >>/opt/mongodb/db.log"
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && touch /var/lock/subsys/$prog
return $RETVAL
}
stop() {
echo -n $"Stopping $prog: "
killproc $prog
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/$prog
return $RETVAL
}
reload() {
echo -n $"Reloading $prog: "
killproc $prog -HUP
RETVAL=$?
echo
return $RETVAL
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
stop
start
;;
condrestart)
if [ -f /var/lock/subsys/$prog ]; then
stop
start
fi
;;
reload)
reload
;;
status)
status $mongod
RETVAL=$?
;;
*)
echo $"Usage: $0 {start|stop|restart|condrestart|reload|status}"
RETVAL=1
esac
exit $RETVAL

Then save and quit the file.


7. Copy the database from remote location to this server.

Then do following steps.


  1. Shutdown the MongoDB server
    1. cd /opt/mongodb/bin
    2. ./mongo
    3. db.shutdownServer()
    4. exit
  1. copy existing copy of backup folder into “backup”
    1. cd /opt/mongodb/bin
    2. mkdir backup
    3. <copy backup files from source machine to ../bin/backup folder>
    4. ./mongorestore –dbpath /opt/mongodb/data/ -o /opt/mongodb/bin/backup
  1. Restart MongoDb server
    1. /etc/init.d/mongodb start

8. Create the user for database. Do following steps.

  1. cd /opt/mongodb/bin
  2. ./mongo
  3. use soptree
  4. db.addUser(“admin”,”@irTel#321”)

How to configure Master-Slave for MongoDB:-


Reference:-


https://library.linode.com/databases/mongodb/clusters#sph_configure-master-slave-replication


On Master Node:-


Go to RootDirectory and edit below file.

RootDirectory:- /home/mongodb

vim /home/mongodb/conf/soptree.conf
dbpath = /home/mongodb/data ( define data location where all data will be alien) 
logpath = /home/mongodb/db.log(define log location and log file name)
logappend = true
bind_ip = 10.56.139.68(master server ip)
port = 27017
fork = true
auth = true
# noauth = true
master = true( cluster status)


On Slave Node:-


dbpath = /home/mongodb/data( define data location where all data will be alien)
logpath = /home/mongodb/db.log(define log location and log file name)
logappend = true
bind_ip = 10.56.139.69(Slave node ip)
port = 27017
fork = true
auth = true
# noauth = true
slave = true(Cluster status)
autoresync = true
source = 10.56.139.68:27017(Master’s node ip and port number)


Now Restart service on both nodes