一、编写脚本
touch mongodb.sh
vi mongodb.sh
mongodb.sh脚本文本内容
#!bin/sh
#chkconfig:2345 80 90
#description:start mongodb service
#start mongodb service
/{mongodbPath}/bin/mongod --dbpath=/{mongodbDataPath} --logpath=/{mongodbServiceLogPath}/logs --logappend --port=27017 --fork
备注:#start mongodb service下为启动某服务的命令,例如:
/mongodb/bin/mongod --dbpath=/mongodb/data --logpath=/mongodb/log/logs --logappend --port=27017 --fork
编写文件方法
1.按insert键输入
2.输入内容
3.输入完毕后按esc键
4.“shirt” 键 + “:” 键
5.输入wq回车
二、设置开启自启
1.移动到/etc/rc.d/init.d/目录下
mv mongodb.sh /etc/rc.d/init.d/
2.给脚本赋执行权限
cd /etc/rc.d/init.d/
chmod +x mongodb.sh
3.添加脚本到开启自启项目中
chkconfig --add mongodb.sh
chkconfig mongodb.sh on
三、验证
重启服务器进行验证
shutdown -r now