== 安装步骤 ==
1. 下载MongoDB,[http://downloads.mongodb.org/linux/mongodb-linux-x86_64-2.2.2.tgz MongoDB官方下载]
2. 解压MongoDB路径:/indoor/mongodb
3. 创建MongoDB数据库路径:/indoor/mongodb/dbdata 命令:mkdir -p /indoor/mongodb/dbdata
4. 创建log文件路径:/indoor/mongodb/logs 命令:touch /indoor/mongodb/logs
5. 创建配置文件夹:mkdir /indoor/mongodb/config/
6. 创建配置文件:/indoor/mongodb/config/mongodb 增加可写权限:chmod +w /indoor/mongodb/config/mongodb
dbpath = /indoor/mongodb/dbdata
logpath = /indoor/mongodb/logs
logappend = true
bind_ip = 127.0.0.1
port = 27017
fork = true
#auth = true
# noauth = true
7. 创建启动文件:/indoor/mongodb/mongodb-start 增加可执行权限:chmod +x /indoor/mongodb/mongodb-start
!/bin/sh
/indoor/mongodb/bin/mongod --config /indoor/mongodb/config/mongodb \
8. 创建结束文件:/indoor/mongodb/mongodb-stop 增加可执行权限:chmod +x /indoor/mongodb/mongodb-stop
#!/bin/bash
pid=`ps -o pid,command ax | grep mongod | awk '!/awk/ && !/grep/ {print $1}'`;
if [ "${pid}" != "" ]; then
kill -2 ${pid};
fi
9. 创建服务器启动文件:/etc/init.d/mongodb ,增加可执行权限:chmod +x /etc/init.d/mongodb
#! /bin/sh
PATH=/opt/mongodb/bin:/sbin:/bin:/usr/sbin:/usr/bin
NAME=mongodb
test -x $DAEMON || exit 0
set -e
case "$1" in
start)
echo -n "Starting MongoDB... "
su - mongodb -c "/indoor/mongodb/mongodb-start"
;;
stop)
echo -n "Stopping MongoDB"
/indoor/mongodb/mongodb-stop
;;
*)
N=/etc/init.d/$NAME
echo "Usage: $N {start|stop}" >&2
exit 1
;;
esac
exit 0
10. 添加服务:chkconfig --add mongodb 设置开机启动:chkconfig mongodb on
11. 服务启动:service mongodb start 服务停止:service mongodb stop
== 注意事项 ==
*MongoDB服务启动时,数据库文件夹必须有3379M以上的硬盘空间
== 资源路径 ==
*[http://www.mongodb.org MongoDB官网]
*[http://downloads.mongodb.org/linux/mongodb-linux-x86_64-2.2.2.tgz MongoDB官方下载]
*[http://library.linode.com/databases/mongodb/centos-5 MongoDB安装Service参考]
http://www.server110.com/mongodb/201310/2730.html