系列文章原载于自己的博客,TOPI.CO (http://topi.co) ,某天不小心就 push 错啦,懒得从头再来,上传到 Ruby-China 来,一是方便自己回顾,另外也方便跟我一样的初学者
###Ubuntu 环境下安装
Ubuntu 环境下比较容易安装,可参考:
安装好后会自动配置。
###CentOS 环境下安装
####安装 MongoDB
#####(1) 查看系统位数
getconf LONG_BIT
#####(2) 编辑 MongoDB 的安装源
vi /etc/yum.repos.d/10gen.repo
#####(3) 粘贴以下内容
64 位适用:
[10gen]
name=10gen Repository
baseurl=http://downloads-distro.mongodb.org/repo/redhat/os/x86_64
gpgcheck=0
32 位适用:
[10gen]
name=10gen Repository
baseurl=http://downloads-distro.mongodb.org/repo/redhat/os/i686
gpgcheck=0
#####(4) 安装 mongo-10gen 和 mongo-10-gen-server
yum install mongo-10gen mongo-10gen-server
#####(5) 设置 mongoDB 自动启动服务
cp /etc/init.d/mongod /etc/rc.d/init.d/mongod
ln -s /etc/init.d/mongod /etc/rc.d/rc3.d/S25mongod && ln -s /etc/init.d/mongod /etc/rc.d/rc5.d/S25mongod
chkconfig —add mongod
####自动启动脚本
#!/bin/bash
# mongod - Startup script for mongod
# chkconfig: 35 85 15
# description: Mongo is a scalable, document-oriented database.
# processname: mongod
# config: /etc/mongod.conf
# pidfile: /var/run/mongo/mongo.pid
. /etc/rc.d/init.d/functions
# things from mongod.conf get there by mongod reading it
OPTIONS=" -f /etc/mongod.conf"
SYSCONFIG="/etc/sysconfig/mongod"
mongod=${MONGOD-/usr/bin/mongod}
MONGO_USER=mongod
MONGO_GROUP=mongod
. "$SYSCONFIG" || true
start()
{
echo -n $"Starting mongod: "
daemon —user "$MONGO_USER" $mongod $OPTIONS
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && touch /var/lock/subsys/mongod
}
stop()
{
echo -n $"Stopping mongod: "
killproc -p /var/lib/mongo/mongod.lock -t30 -TERM /usr/bin/mongod
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/mongod
}
restart () {
stop
start
}
ulimit -n 12000
RETVAL=0
case "$1" in
start)
start
;;
stop)
stop
;;
restart|reload|force-reload)
restart
;;
condrestart)
[ -f /var/lock/subsys/mongod ] && restart || :
;;
status)
status $mongod
RETVAL=$?
;;
*)
echo "Usage: $0 {start|stop|status|restart|reload|force-reload|condrestart}"
RETVAL=1
esac
exit $RETVAL