linux 下 chkconfig安裝與使用詳解

來源:互聯網
上載者:User

chkconfig 安裝

開始的時候因為Raspbian的原因,系統是不內建chkconfig這個命令的,

root@raspberrypi:~# chkconfig
-bash: chkconfig: command not found

所以要手動安裝一下才行,

安裝很簡單apt-get install chkconfig即可,

安裝過程如下:

root@raspberrypi:~# apt-get install chkconfig
Reading package lists... Done
Building dependency tree      
Reading state information... Done
The following NEW packages will be installed:
  chkconfig
0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
Need to get 9766 B of archives.
After this operation, 59.4 kB of additional disk space will be used.
Get:1 http://mirrors.ustc.edu.cn/raspbian/raspbian/ jessie/main chkconfig all 11.4.54.60.1debian1 [9766 B]
Fetched 9766 B in 0s (20.1 kB/s)
Selecting previously unselected package chkconfig.
(Reading database ... 120673 files and directories currently installed.)
Preparing to unpack .../chkconfig_11.4.54.60.1debian1_all.deb ...
Unpacking chkconfig (11.4.54.60.1debian1) ...
Processing triggers for man-db (2.7.0.2-5) ...
Setting up chkconfig (11.4.54.60.1debian1) ...
使用chkconfig
下面是chkconfig的命令協助

使用文法:
chkconfig [–add][–del][–list][系統服務] 或 chkconfig [–level <等級代號>][系統服務][on/off/reset]

chkconfig在沒有參數運行時,顯示用法。如果加上服務名,那麼就檢查這個服務是否在當前運行級啟動。如果是,返回true,否則返回false。如果在服務名後面指定了on,off或者reset,那麼chkconfi 會改變指定服務的啟動資訊。on和off分別指服務被啟動和停止,reset指重設服務的啟動資訊,無論有問題的初始化指令碼指定了什麼。on和off開關,系統預設只對運行級3,4,5有效,但是reset可以對所有運行級有效。

參數用法:

–add 增加所指定的系統服務,讓chkconfig指令得以管理它,並同時在系統啟動的敘述檔案內增加相關資料。
–del 刪除所指定的系統服務,不再由chkconfig指令管理,並同時在系統啟動的敘述檔案內刪除相關資料。
–level <等級代號>  指定讀系統服務要在哪一個執行等級中開啟或關畢。
等級0表示:表示關機
等級1表示:單一使用者模式
等級2表示:無網路連接的多使用者命令列模式
等級3表示:有網路連接的多使用者命令列模式
等級4表示:不可用
等級5表示:帶圖形介面的多使用者模式
等級6表示:重新啟動

開機禁用某服務

再此以minidlna為例,

先看看minidlna服務現在的運行情況

root@raspberrypi:~# chkconfig -l | grep mini
minidlna   0:off  1:off  2:on   3:on   4:on   5:on   6:off
從level 2 – 5 全部禁用。
使用命令chkconfig --level 2345 minidlna off,

並且在查詢一遍服務狀態,如下:

root@raspberrypi:~# chkconfig --level 2345 minidlna off
root@raspberrypi:~# chkconfig -l | grep mini
minidlna   0:off  1:off  2:off  3:off  4:off  5:off  6:off

為了節省樹莓派2b可憐的512mb記憶體,我還順便禁用了ftp和mysql服務。

事後,重啟,查看服務狀態

因為我是用的 lnmp 一鍵安裝封裝的環境,

所以我是用lnmp status和lnmp pureftpd status來查看服務狀態。
查看下記憶體使用量,果然少用了幾十兆,嘿嘿。

例如,random.init包含三行:
# 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
    修改服務的預設啟動等級。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.