CentOS6.4x64编译安装MongoDB
时间:2015-08-06 11:53 来源:linux.it.net.cn 作者:IT
[root@mongodb-2 ~]
# curl -O https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-3.0.5.tgz
[root@mongodb-2 ~]
# tar xf mongodb-linux-x86_64-3.0.5.tgz
[root@mongodb-2 ~]
# ln -s /usr/local/mongodb-linux-x86_64-3.0.5/ /usr/local/mongodb
[root@mongodb-2 ~]
# tail -3 /etc/profile
#set for mongodb
export
MONGODB_HOME=
/usr/local/mongodb
export
PATH=$MONGODB_HOME
/bin
:$PATH
#重新加载环境变量
[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
#验证结果
[root@mongodb-2 ~]
# mongod --version
db version v3.0.5
git version: 8bc4ae20708dbb493cb09338d9e7be6698e4a3a3
[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
[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
[root@mongodb-2 ~]
# useradd mongodb -M -s /sbin/nologin
[root@mongodb-2 ~]
# chown -R mongodb.mongodb /usr/local/mongodb-linux-x86_64-3.0.5
[root@mongodb-2 ~]
# mongod -f /usr/local/mongodb/conf/mongodb.conf
about to fork child process, waiting
until
server is ready
for
connections.
forked process: 1545
child process started successfully, parent exiting
#测试
[root@mongodb-2 ~]
# mongo admin
[root@mongodb-2 ~]
# cat /etc/init.d/mongod
#!/bin/sh
#
# mongodb init file for starting up the MongoDB server
#
# chkconfig: - 20 80
# description: Starts and stops the MongDB daemon that handles all \
# database requests.
# Source function library.
.
/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 --user mongodb
"$exec --quiet $options run >> $logfile 2>&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() {
# run checks to determine if the service is running or use generic status
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
$?
#赋予脚本执行权限
[root@mongodb-2 ~]
# chmod +x /etc/init.d/mongod
#重启服务
[root@mongodb-2 ~]
# /etc/init.d/mongod restart
Stopping mongod: [ OK ]
Starting mongod: [ OK ]
[root@mongodb-2 ~]
# netstat -tunlp |grep mong
tcp 0 0 0.0.0.0:27017 0.0.0.0:* LISTEN 1759
/mongod
#添加到开机自启动
[root@mongodb-2 ~]
# chkconfig --add mongod
[root@mongodb-2 ~]
# chkconfig mongod on
mongodb的参数说明:
--dbpath 数据库路径(数据文件)
--logpath 日志文件路径
--master 指定为主机器
--slave 指定为从机器
--
source
指定主机器的IP地址
--pologSize 指定日志文件大小不超过64M.因为resync是非常操作量大且耗时,最好通过设置一个足够大的oplogSize来避免resync(默认的 oplog大小是空闲磁盘大小的5%)。
--logappend 日志文件末尾添加
--port 启用端口号
--fork 在后台运行
--only 指定只复制哪一个数据库
--slavedelay 指从复制检测的时间间隔
--auth 是否需要验证权限登录(用户名和密码)
(责任编辑:IT)
(责任编辑:IT) |