The command chkconfig
is no longer available in Ubuntu.The equivalent command to chkconfig
is update-rc.d
.This command nearly supports all the new versions of ubuntu.
The similar commands are
update-rc.d <service> defaults update-rc.d <service> start 20 3 4 5 update-rc.d -f <service> remove
sysv-rc-conf is an alternate option for Ubuntu.
sudo apt-get install sysv-rc-conf sysv-rc-conf --list xxxx
In Ubuntu /etc/init.d has been replaced by /usr/lib/systemd. Scripts can still be started and stoped by 'service'. But the primary command is now 'systemctl'. The chkconfig command was left behind, and now you do this with systemctl.
So instead of:
chkconfig enable apache2
You should look for the service name, and then enable it
systemctl status apache2
systemctl enable apache2.service
Systemd has become more friendly about figuring out if you have a systemd script, or an /etc/init.d script, and doing the right thing.
//----------------------------------------------------------------------------------------------------------------------------------------------------------------
chkconfig命令主要用來更新(啟動或停止)和查詢系統服務的運行級信息。謹記chkconfig不是立即自動禁止或激活一個服務,它只是簡單的改變了符號連接。
一、chkconfig 的使用語法
1、chkconfig [--add][--del][--list][系統服務] 或 chkconfig [--level <levels等級代號>][系統服務][on/off/reset]
2、參數用法:
--add 增加所指定的系統服務,讓chkconfig指令得以管理它,並同時在系統啟動的敘述文件內增加相關數據。
--del 刪除所指定的系統服務,不再由chkconfig指令管理,並同時在系統啟動的敘述文件內刪除相關數據。
--level<等級代號> 指定讀系統服務要在哪一個執行等級中開啟或關畢。
等級0表示:表示關機
等級1表示:單用戶模式
等級2表示:無網絡連接的多用戶命令行模式
等級3表示:有網絡連接的多用戶命令行模式
等級4表示:系統保留
等級5表示:帶圖形界面的多用戶模式
等級6表示:重新啟動
3、需要說明的是,level選項可以指定要查看的運行級而不一定是當前運行級。對於每個運行級,只能有一個啟動腳本或者停止腳本。當切換運行級時,init不會重新啟動已經啟動的服務,也不會再次去停止已經停止的服務。
4、chkconfig --list [name]:顯示所有運行級系統服務的運行狀態信息(on或off)。如果指定了name,那么只顯示指定的服務在不同運行級的狀態。
5、chkconfig --add name:增加一項新的服務。chkconfig確保每個運行級有一項啟動(S)或者殺死(K)入口。如有缺少,則會從缺省的init腳本自動建立。
chkconfig --del name:刪除服務,並把相關符號連接從/etc/rc[0-6].d刪除。
chkconfig [--level levels] name:設置某一服務在指定的運行級是被啟動,停止還是重置。
6、運行級文件:
每個被chkconfig管理的服務需要在對應的init.d下的腳本加上兩行或者更多行的注釋。第一行告訴chkconfig缺省啟動的運行級以及啟動和停止的優先級。如果某服務缺省不在任何運行級啟動,那么使用 - 代替運行級。第二行對服務進行描述,可以用\ 跨行注釋。
例如,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 2345 httpd 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等級
7、如何增加一個服務:以mysqld 為例
(1)、服務腳本必須存放在/etc/init.d/目錄下;
(2)、chkconfig --add mysqld #添加服務,在chkconfig工具服務列表中增加此服務,此時服務會被在/etc/rc.d/rcN.d中賦予K/S入口;
(3)、chkconfig --level 35 mysqld on # 修改服務的默認啟動等級。
二、服務的啟動/關閉
1、系統服務:一直在內存中,而且一直在運行,並提供服務的被稱為服務;
2、而服務也是一個運行的程序,則這個運行的程序則被稱為daemons;
3、這些服務的啟動腳本一般放置在: /etc/init.d
4、在CentOS中服務啟動腳本放置在:/etc/rc.d/init.d而/etc/init.d這個目錄為公認的目錄,在centos中/etc/init.d就是一個鏈接檔案
5、/etc/sysconfig 服務初始化環境變量配置都在這個檔案中。
6、/var/lib 各個服務產生的數據庫都在這個目錄下,最簡單的在這里找到 mysql 使用 vim 打開就可以看到,你建立的數據庫以及系統默認產生的數據庫名稱都在這里面!
7、啟動/停止/重啟服務 : /etc/init.d/ serverName start/stop /restart/status
8、啟動/停止/重啟服務: service serverName start/stop/restart 為什么可以這樣寫?
9、service 是一個script 他可以分析你后面下達的參數,然后根據你的參數在到/etc/init.d 下去取得正確的服務來 stop start restart