Linux服務開機自啟動設定,linux服務開機

來源:互聯網
上載者:User

Linux服務開機自啟動設定,linux服務開機

Linux中也有類似於Window中的開機自啟動服務,主要是通過chkconfig命令來設定。它主要用來更新(啟動或停止)和查詢系統服務的運行級資訊。謹記chkconfig不是立即自動禁止或啟用一個服務,它只是簡單的改變了符號串連。

參數說明:

[root@DB-Server rc2.d]# chkconfig --help
chkconfig version 1.3.30.2 - Copyright (C) 1997-2000 Red Hat, Inc.
This may be freely redistributed under the terms of the GNU Public License.
 
usage:   chkconfig --list [name]
         chkconfig --add <name>
         chkconfig --del <name>
         chkconfig [--level <levels>] <name> <on|off|reset|resetpriorities>
[root@DB-Server rc2.d]# chkconfig
chkconfig version 1.3.30.2 - Copyright (C) 1997-2000 Red Hat, Inc.
This may be freely redistributed under the terms of the GNU Public License.
 
usage:   chkconfig --list [name]
         chkconfig --add <name>
         chkconfig --del <name>
         chkconfig [--level <levels>] <name> <on|off|reset|resetpriorities>

 

 

--list 顯示開機可以自動啟動的服務

--add 新增所指定的開機自啟動系統服務

--del 刪除所指定的系統服務

--level 指定該系統服務要在那個執行等級中開啟或關閉。

on/off/reset 在指定的執行登記,開啟/關閉/重設該系統服務

 

使用案例:

chkconfig --list      #顯示開機可以自動啟動的服務
 
chkconfig --add ***   #增加開機自動啟動的***服務
 
chkconfig --del ***   #刪除開機自動啟動的***服務
 
chkconfig --level mysql 2345 on #設定mysql在運行層級為2、3、4、5的情況下都是on(開啟)的狀態

 

[root@DB-Server ~]# chkconfig --list | grep mysql
mysql           0:off   1:off   2:on    3:on    4:on    5:on    6:off
[root@DB-Server ~]# 

--level<等級代號> 指定系統服務要在哪一個執行等級中開啟或關閉

等級0表示:表示關機

等級1表示:單一使用者模式

等級2表示:無網路連接的多使用者命令列模式

等級3表示:有網路連接的多使用者命令列模式

等級4表示:未定義

等級5表示:帶圖形介面的多使用者模式

等級6表示:重新啟動

 

[root@DB-Server ~]# chkconfig --list mysql
mysql           0:off   1:off   2:on    3:on    4:on    5:on    6:off
[root@DB-Server ~]# chkconfig --del mysql
[root@DB-Server ~]# chkconfig --list | grep mysql
[root@DB-Server ~]# chkconfig --add mysql
You have new mail in /var/spool/mail/root
[root@DB-Server ~]# chkconfig --list | grep mysql
mysql           0:off   1:off   2:on    3:on    4:on    5:on    6:off
[root@DB-Server ~]# 

 

如果我們要在運行層級3上開機自啟動mysql服務,在其它運行層級關閉,可以通過下面命令來設定。

[root@DB-Server ~]# chkconfig --list | grep mysql
mysql           0:off   1:off   2:on    3:on    4:on    5:on    6:off
[root@DB-Server ~]#  chkconfig --level 3 mysql on
[root@DB-Server ~]# chkconfig --list | grep mysql
mysql           0:off   1:off   2:on    3:on    4:on    5:on    6:off
[root@DB-Server ~]#  chkconfig --level 2 mysql off
[root@DB-Server ~]#  chkconfig --level 4 mysql off
[root@DB-Server ~]# chkconfig --list | grep mysql
mysql           0:off   1:off   2:off   3:on    4:off   5:on    6:off
[root@DB-Server ~]# 

當然也可以用下面命令來開啟,關閉服務的開啟自啟動.

chkconfig service_name on
chkconfig service_name on --level runlevels
chkconfig service_name off --level runlevels

[root@DB-Server ~]# chkconfig mysql on --level 3
[root@DB-Server ~]# chkconfig mysql off --level 45
[root@DB-Server ~]# 

新增開機自啟動MySQL服務,我們會在/etc/rc.d/rcn.d下看到產生了一個對應的檔案,例如/etc/rc.d/rc3.d

我們刪除開機自動啟動的mysql服務,就會看到對應的檔案也被刪除。

[root@DB-Server rc3.d]# chkconfig --del mysql
 
[root@DB-Server rc3.d]# ls *mysql*
 
ls: *mysql*: No such file or directory
 
[root@DB-Server rc3.d]# 

chkcofig後的三個參數: 第一個參數,它告訴chkconf這個服務以什麼樣的運行層級開始。第二個參數,它指定的了啟動的優先等級。最後一個參數,它指定了停止服務時,它擁有的優先順序別。上面的這個執行個體中,它表示這個服務以2、3、4和5的層級開始,它的啟動優先順序為64,它的停止優先順序是36。

[root@DB-Server rc3.d]# chkconfig --add mysql

 

參考資料:

http://www.cnblogs.com/panjun-Donet/archive/2010/08/10/1796873.html

http://network810.blog.51cto.com/2212549/1137972

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.