mongodb 启动脚本

来源:互联网 发布:英语翻译 知乎 编辑:程序博客网 时间:2024/06/06 06:46

分别在centos 5.4,ubuntu 14.04下编译通过:

系统最好是64位的,才能更好发挥mongodb的性能.

wget http://fastdl.mongodb.org/linux/mongodb-linux-x86_64-2.6.0.tgz
tar -zvxf mongodb-linux-x86_64-2.6.0.tgz
mv mongodb-linux-x86_64-2.6.0 /usr/local/mongodb/

建立存储数据及日志的目录:

mkdir -p /data/db/journal
mkdir  /data/log

touch /data/log/mongodb.log


vi /etc/mongodb.conf
输入以下内容:
dbpath=/data/db
logpath=/data/log/mongodb.log
logappend=true
port=27017
fork=true
noauth=true
nojournal = true
smallfiles = true
noprealloc = true 

下面加入自启动:
cd /etc/init.d/
vi mongodb
输入以下内容:

#!/bin/bash
#
#chkconfig: 2345 80 90
#description: mongodb
start() {
 /usr/local/mongodb/bin/mongod -f /etc/mongodb.conf
}

stop() {
  /usr/local/mongodb/bin/mongod -f /etc/mongodb.conf --shutdown
}

case "$1" in
  start)
 start
 ;;
  stop)
 stop
 ;;
  restart)
 stop
 start
 ;;
  *)
 echo $"Usage: $0 {start|stop|restart}"
 exit 1
esac

加入自启动:
chkconfig --add mongodb
chmod +x  mongodb
chkconfig mongodb on


如果是ubuntu;

update-rc.d mongodb defaults


reboot重启测试。
以管理员身份进入管理后台
/usr/local/mongodb/bin/mongo admin
测试一下:
show dbs;
db.test.find();

0 0
原创粉丝点击