chkconfig 新增指令碼開機自啟動
1./etc/rc.local 自啟動
2.通過chkconfig管理
如何讓一個指令碼被chkconfig管理
[[email protected] ~]# vim /etc/init.d/oldgirld
# chkconfig: 2345 99 99 ##這步必須的 vim /etc/init.d/crond 配置中可見
# description:[XM1] Saves and restores system entropy pool for \
echo 1
~
[[email protected] ~]# chkconfig --add oldgirld ##新增自啟動
[[email protected] ~]# chkconfig |grep old
oldgirld 0:off 1:off 2:on 3:on 4:on 5:on6:off
翻譯
RUNLEVEL FILES
Each service which should be manageable by chk-
config needs two or more commented lines added
to its init.d script. The first line tells chk-
config what runlevels the service should be
started in by default, as well as the start and
stop priority levels. If the service should
not, by default, be started in any runlevels, a
- should be used in place of the runlevels
list. The second line contains a description
for the service, and may be extended across
multiple lines with backslash continuation.
For example, random.init has these three lines:
# chkconfig: 2345 20 80
# description: Saves and restores system entropy pool for \
# higher quality random number generation.
This says that the random script should be
started in levels 2, 3, 4, and 5, that its
start priority should be 20, and that its stop
priority should be 80. You should be able to
figure out what the description says; the \
causes the line to be continued. The extra
space in front of the line is ignored.
譯:
RUNLEVEL檔案每個服務應該由chkconfig管理,chkconfig需要新增到init.d指令碼中的兩個或更多註釋行。第一行告訴chkconfig預設應該在什麼執行級別啟動服務,以及啟動和停止優先順序級別。在任何執行級別中,都應該使用a-來代替runlevel列表。通過反斜槓的延續。例如,Rand.init有以下三行:#chkconfig:2345 20 80#Description:儲存和恢復系統熵池以提高質量\#隨機數生成。這意味著隨機指令碼應該在級別2、3、4和5中啟動,它的開始優先順序應該是20,它的停止優先順序應該是80。你應該能夠弄清楚描述中寫了什麼;\導致行被繼續。該行前面的額外空間被忽略了。
# chkconfig: 2345 20 80
# description: Saves and restores system entropy pool for \
# higher quality random number generation.
使用範例:
chkconfig --list #列出所有的系統服務
chkconfig --add httpd #增加httpd服務
chkconfig --del httpd #刪除httpd服務
chkconfig --level httpd 2345 on #設定httpd在執行級別為2、3、4、5的情況下都是on(開啟)的狀態
chkconfig --list #列出系統所有的服務啟動情況
chkconfig --list mysqld #列出mysqld服務設定情況
chkconfig --level 35 mysqld on #設定mysqld在等級3和5為開機執行服務,--level 35表示操作只在等級3和5執行,on表示啟動,off表示關閉
chkconfig mysqld on #設定mysqld在各等級為on,“各等級”包括2、3、4、5等級
如何增加一個服務:
1.服務指令碼必須存放在/etc/ini.d/目錄下;
2.chkconfig --add servicename
在chkconfig工具服務列表中增加此服務,此時服務會被在/etc/rc.d/rcN.d中賦予K/S入口了; 3.chkconfig --level 35 mysqld on
修改服務的預設啟動等級。
[XM1]說明,註釋