日期:2014-05-16  浏览次数:20409 次

mongodb 安装 启动 停止脚本
安装mongodb
cd /tmp/soft/
wget http://fastdl.mongodb.org/linux/mongodb-linux-x86_64-1.8.2.tgz
tar zxvf mongodb-linux-x86_64-1.8.2.tgz
sudo mkdir -p /data/mongodb/
sudo chown `id -u` /data/mongodb
sudo mv /tmp/soft/mongodb-linux-x86_64-1.8.2/* /opt/mongodb


启动mongodb脚本,mongodb_start.sh
#!/bin/bash
if [ $# != 0 ];then
    port=$1;
else
    port=27017
fi
mkdir -p /opt/mongodb/data_$port
/opt/mongodb/bin/mongod --dbpath=/opt/mongodb/data_$port --logpath=/opt/mongodb/mongodb_$port.log --logappend --port=$port > /dev/null 2>&1 &
echo "start mongodb port:$port"

调用:/opt/mongodb/mongodb_start.sh

停止mongodb脚本,mongodb_stop.sh
#!/bin/bash
if [ $# != 0 ];then
    port=$1;
else
    port=27017
fi
pid=`ps -o pid,command ax | grep mongod | grep $port | awk '!/awk/ && !/grep/ {print $1}'`;
if [ "${pid}" != "" ]; then
        kill -2 ${pid};
fi
echo "stop mongodb port:$port"

调用:/opt/mongodb/mongodb_stop.sh