linux服務、程序開機自啟
阿新 • • 發佈:2018-12-12
一、/etc/rc.local 在檔案最後一行新增要執行程式的全路徑。
如mongodb
numactl --interleave=all /data/app/mongodb/bin/mongod -f /data/work/mongodb/conf/mongod.yaml sleep 3 numactl --interleave=all /data/app/mongodb/bin/mongod -f /data/work/mongodb/conf/shard1.yaml numactl --interleave=all /data/app/mongodb/bin/mongod -f /data/work/mongodb/conf/shard2.yaml numactl --interleave=all /data/app/mongodb/bin/mongod -f /data/work/mongodb/conf/shard3.yaml numactl --interleave=all /data/app/mongodb/bin/mongod -f /data/work/mongodb/conf/shard4.yaml numactl --interleave=all /data/app/mongodb/bin/mongod -f /data/work/mongodb/conf/shard5.yaml numactl --interleave=all /data/app/mongodb/bin/mongod -f /data/work/mongodb/conf/shard6.yaml sleep 3 numactl --interleave=all /data/app/mongodb/bin/mongos -f /data/work/mongodb/conf/mongos.yaml
二、註冊系統服務
chkconfig --add 服務名
chkconfig -leve 啟動級別 服務名 on (說明,3級別代表在命令列模式啟動,5級別代表在圖形介面啟動,on表示開啟)
chkconfig -leve 啟動級別 服務名 off (說明,off表示關閉自啟動)
等級代號列表:
-
等級0表示:表示關機
-
等級1表示:單使用者模式
-
等級2表示:無網路連線的多使用者命令列模式
-
等級3表示:有網路連線的多使用者命令列模式
-
等級4表示:不可用
-
等級5表示:帶圖形介面的多使用者模式
-
等級6表示:重新啟動
如何增加一個服務:
- 服務指令碼必須存放在
/etc/ini.d/
目錄下; chkconfig --add servicename
在chkconfig工具服務列表中增加此服務,此時服務會被在/etc/rc.d/rcN.d
中賦予K/S入口了;chkconfig --level 35 mysqld on
修改服務的預設啟動等級。
如mysql
[[email protected] init.d]# chkconfig --add mysql
[[email protected] init.d]# chkconfig mysql on