1.设置开机自启动脚本
root# vi /etc/rc.local
//================rc.local内容=============================
#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
/root/mstartd #开机执行此脚本,自动开启mongo server
exit 0
//============================================================
2. vim /root/mstartd 主脚本
//====================/root/mstartd内容=======================
#!/bin/sh
/Apps/mongo_report/bin/mstartd //mongo服务子脚本
//============================================================
3.vi /Apps/mongo_report/bin/mstartd
//====================/Apps/mongo_report/bin/mstartd内容======
#!/bin/sh
# chkconfig: 2345 99 99
# description: start mongod
# limit memory 32G
#ulimit -m 32998166 #设置可以使用的常驻内存的最大值.单位:kbytes
# limit count of open files (system default value is 1024, too small)
ulimit -n 20000 #设置内核可以同时打开的文件描述符的最大值.单位:n
# limit stack size 1M
ulimit -s 1024 #设置堆栈的最大值.单位:kbytes
# start mongod 27019
/Apps/mongo_report/bin/mongod --config /Apps/mongo_report/bin/conf/mongodb7019.conf #按脚本启动mongo
//============================================================
4.vi /Apps/mongo_report/bin/conf/mongodb7019.conf
//===============mongodb7019.conf内容===========================
port = 27019 #端口
dbpath = /Apps/mongo_report/bin/data/d7019 #数据存放位置
logpath = /Apps/mongo_report/bin/data/log/7019.log #日志
logappend = true #设置后,系统不会会清除原来的日志记录,也不会把已有的文件进行覆盖。日志以追加的方式进行记录
fork = true 指定以守护进程的方式来启动MongoDB,如果不指定,在启动mongod命令是加“&”也是可以的。
#bind_ip = 192.168.30.8,127.0.0.1 #指定对外服务的绑定ip,这里指定内网的ip方式,如果外网无特殊的处理方式是无法进行连接。
quiet = true #安静输出 ?????????
pidfilepath = /Apps/mongo_report/bin/data/d7019.pid # PID File 的完整路径,如果没有设置,则没有PID文件
nohttpinterface = true #关闭http接口,默认关闭27018端口访问??????
nounixsocket = true # 禁用Unix套接字监听 ?????
//=========================================
参考:http://www.blogjava.net/dongbule/archive/2011/07/30/355409.html
http://blog.csdn.net/zhengshqing/article/details/8686847
http://itindex.net/detail/49978-mongodb-%E7%AE%A1%E7%90%86