一、編寫腳本
touch mongodb.sh
vi mongodb.sh
mongodb.sh腳本文本內(nèi)容
#!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下為啟動(dòng)某服務(wù)的命令,例如:
/mongodb/bin/mongod --dbpath=/mongodb/data --logpath=/mongodb/log/logs --logappend --port=27017 --fork
編寫文件方法
1.按insert鍵輸入
2.輸入內(nèi)容
3.輸入完畢后按esc鍵
4.“shirt” 鍵 + “:” 鍵
5.輸入wq回車
二、設(shè)置開啟自啟
1.移動(dòng)到/etc/rc.d/init.d/目錄下
mv mongodb.sh /etc/rc.d/init.d/
2.給腳本賦執(zhí)行權(quán)限
cd /etc/rc.d/init.d/
chmod +x mongodb.sh
3.添加腳本到開啟自啟項(xiàng)目中
chkconfig --add mongodb.sh
chkconfig mongodb.sh on
三、驗(yàn)證
重啟服務(wù)器進(jìn)行驗(yàn)證
shutdown -r now