新建 MongoDB 程序目录
mkdir /home/data/mongodb
mkdir /home/data/mongodb/bin
下载
在 https://www.mongodb.com/download-center 找到红帽版本下载地址,并解压到 bin
目录下
cd /home/data/mongodb/bin
wget https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel62-4.0.0.tgz
tar -zxvf mongodb-linux-*-4.0.0.tgz
配置 Mango 启动参数
vi /usr/lib/mongodb/bin/mongo.conf
port=27017
dbpath=/home/data/mongodb
logpath=/home/data/mongodb.log
logappend=true
fork=true
# auth=true
配置系统变量
编辑文件
vi /etc/profile
在最末尾添加
export PATH=/home/data/mongodb/bin:$PATH
配置 Service
编辑文件
vi /etc/init.d/mongodb
填入一下信息,变量自己更改
#!/bin/sh
#
#mongod - Startup script for mongod
#
# chkconfig: - 85 15
# description: Mongodb database.
# processname: mongod
# Source function library
. /etc/rc.d/init.d/functions
# things from mongod.conf get there by mongod reading it
# OPTIONS
OPTIONS=" -f /usr/lib/mongodb/bin/mongo.conf &"
#mongod
mongod="/usr/lib/mongodb/bin/mongod"
lockfile=/usr/lib/mongodb/mongod.pid
start () {
echo -n $"Starting mongod: "
daemon $mongod $OPTIONS
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && touch $lockfile
}
stop () {
echo -n $"Stopping mongod: "
killproc $mongod -QUIT
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && rm -f $lockfile
}
restart () {
stop
start
}
ulimit -n 12000
RETVAL=0
case "$1" in
start)
start
;;
stop)
stop
;;
restart|reload|force-reload)
restart
;;
condrestart)
[ -f $lockfile ] && restart || :
;;
status)
status $mongod
RETVAL=$?
;;
*)
echo "Usage: $0 {start|stop|status|restart|reload|force-reload|condrestart}"
RETVAL=1
esac
exit $RETVAL
修改权限
chmod +x /etc/init.d/mongodb
测试启动
service mongodb start
mongo --host 127.0.0.1:27017