CentOS6.4x64 compile and install MongoDB
I. Environment
Minimal installation of CentOS6.4x64
IP 192.168.3.33
Ii. Installation
[root@mongodb-2~]
#curl-Ohttps://fastdl.mongodb.org/linux/mongodb-linux-x86_64-3.0.5.tgz
[root@mongodb-2~]
#tarxfmongodb-linux-x86_64-3.0.5.tgz
[root@mongodb-2~]
#ln-s/usr/local/mongodb-linux-x86_64-3.0.5//usr/local/mongodb
Set Environment Variables
[root@mongodb-2~]
#tail-3/etc/profile
#setformongodb
export
MONGODB_HOME=
/usr/local/mongodb
export
PATH=$MONGODB_HOME
/bin
:$PATH
# Reload Environment Variables
[root@mongodb-2~]
#source/etc/profile
[root@mongodb-2~]
#echo$PATH
/usr/local/mongodb/bin
:
/usr/local/sbin
:
/usr/local/bin
:
/sbin
:
/bin
:
/usr/sbin
:
/usr/bin
:
/root/bin
# Verification Result
[root@mongodb-2~]
#mongod--version
dbversionv3.0.5
gitversion:8bc4ae20708dbb493cb09338d9e7be6698e4a3a3
Create directory
[root@mongodb-2~]
#mkdir-p/usr/local/mongodb/data
[root@mongodb-2~]
#mkdir-p/usr/local/mongodb/log
[root@mongodb-2~]
#mkdir-p/usr/local/mongodb/conf
Create a configuration file
[root@mongodb-2~]
#cat/usr/local/mongodb/conf/mongodb.conf
#bind_ip=0.0.0.0
port=27017
dbpath=
/usr/local/mongodb/data
logpath=
/usr/local/mongodb/log/mongodb
.log
pidfilepath=
/usr/local/mongodb/log/mongodb
.pid
directoryperdb=
true
logappend=
true
oplogSize=1000
fork=
true
#noprealloc=true
master=
true
Add mongodb users and Set permissions
[root@mongodb-2~]
#useraddmongodb-M-s/sbin/nologin
[root@mongodb-2~]
#chown-Rmongodb.mongodb/usr/local/mongodb-linux-x86_64-3.0.5
Start the service
[root@mongodb-2~]
#mongod-f/usr/local/mongodb/conf/mongodb.conf
abouttoforkchildprocess,waiting
until
serverisready
for
connections.
forkedprocess:1545
childprocessstartedsuccessfully,parentexiting
# Test
[root@mongodb-2~]
#mongoadmin
Write server startup script
[root@mongodb-2~]
#cat/etc/init.d/mongod
#!/bin/sh
#
#mongodbinitfileforstartinguptheMongoDBserver
#
#chkconfig:-2080
#description:StartsandstopstheMongDBdaemonthathandlesall\
#databaserequests.
#Sourcefunctionlibrary.
.
/etc/rc
.d
/init
.d
/functions
exec
=
"/usr/local/mongodb/bin/mongod"
prog=
"mongod"
logfile=
"/usr/local/mongodb/log/mongodb.log"
options=
"-f/usr/local/mongodb/conf/mongodb.conf"
[-e
/etc/sysconfig/
$prog]&&.
/etc/sysconfig/
$prog
lockfile=
"/var/lock/subsys/mongod"
start(){
[-x$
exec
]||
exit
5
echo
-n$
"Starting$prog:"
daemon--usermongodb
"$exec--quiet$optionsrun>>$logfile2>&1&"
retval=$?
echo
[$retval-
eq
0]&&
touch
$lockfile
return
$retval
}
stop(){
echo
-n$
"Stopping$prog:"
killproc$prog
retval=$?
echo
[$retval-
eq
0]&&
rm
-f$lockfile
return
$retval
}
restart(){
stop
start
}
reload(){
restart
}
force_reload(){
restart
}
rh_status(){
#runcheckstodetermineiftheserviceisrunningorusegenericstatus
status$prog
}
rh_status_q(){
rh_status>
/dev/null
2>&1
}
case
"$1"
in
start)
rh_status_q&&
exit
0
$1
;;
stop)
rh_status_q||
exit
0
$1
;;
restart)
$1
;;
reload)
rh_status_q||
exit
7
$1
;;
force-reload)
force_reload
;;
status)
rh_status
;;
condrestart|try-restart)
rh_status_q||
exit
0
restart
;;
*)
echo
$
"Usage:$0{start|stop|status|restart|condrestart|try-restart|reload|force-reload}"
exit
2
esac
exit
$?
# Grant the script execution permission
[root@mongodb-2~]
#chmod+x/etc/init.d/mongod
# Restart the service
[root@mongodb-2~]
#/etc/init.d/mongodrestart
Stoppingmongod:[OK]
Startingmongod:[OK]
[root@mongodb-2~]
#netstat-tunlp|grepmong
tcp000.0.0.0:270170.0.0.0:*LISTEN1759
/mongod
# Add to auto-start upon startup
[root@mongodb-2~]
#chkconfig--addmongod
[root@mongodb-2~]
#chkconfigmongodon
Mongodb configuration file Parameters
Mongodb parameter description:
-- Dbpath database path (data file)
-- Logpath: Log File Path
-- Master is specified as the master machine.
-- Slave is specified as the slave machine
--
source
Host IP Address
-- PologSize: the size of the specified log file cannot exceed 64 MB. because resync is very large and time-consuming, it is best to set a large enough oplogSize to avoid resync (the default oplog size is 5% of the idle disk size ).
-- Add at the end of the logappend Log File
-- Port enables the port number
-- Fork runs in the background
-- Only specifies which database to copy
-- Slavedelay indicates the interval between slave replication detection.
-- Does auth need to verify the permission to log on (user name and password)