標籤:程式 初學 ado pen list manager 簡單 process 總結
博主使用的作業系統是最新的CentOS 7,所以可能和網上一些老的博文有一定出入,那是因為版本更新的原因。
這裡寫圖片描述
1 service
service命令用於對系統服務進行管理,比如啟動(start)、停止(stop)、重啟(restart)、重新載入配置(reload)、查看狀態(status)等。
下面我們來看看在Centos 7上service命令的使用方式。
這裡寫圖片描述
這裡寫圖片描述
這裡寫圖片描述
相信看到這裡,大家已經發現問題了。那就是service命令的使用方式已經和以前的老版本不一樣了。(作為一個初學Linux的人,我也是通過看網上的資料,發現把網友貼出的命令執行時,發現的問題。)同樣的情況對於 chkconfig 命令也是一樣。
2 chkconfig
老版本的使用說明:
chkconfig
提供了一個維護/etc/rc[0~6] d 檔案夾的命令列工具,它減輕了系統直接管理這些檔案夾中的符號串連的負擔。chkconfig主要包括5個原始功能:為系統管理增加新的服務、為系統管理移除服務、列出單簽服務的啟動資訊、改變服務的啟動資訊和檢查特殊服務的啟動狀態。當單獨運行chkconfig命令而不加任何參數時,他將顯示服務的使用資訊。
必要參數
–add 開啟指定的服務程式
–del 關閉指定的服務程式
–list 列出chkconfig所知道的所有服務
選擇參數
–level<代號> 設定服務程式的等級代號,它是一串0~7的數字,如“-level35”代表指定運行等級3和5
–help 顯示協助資訊
–version 顯示版本資訊
我們在Centos7中試一試嘛。
這裡寫圖片描述
所以問題已經很明顯了,service和chkconfig命令的功能好像都被閹割了,而且好像已經被systemctl命令取代了。是這樣嗎?我們來看一看systemctl命令的介紹。
3 systemctl
文檔中是這麼介紹它的:
systemctl may be used to introspect and control the state of the “systemd” system and service manager.
再結合上面兩個命令的執行結果,我們已經可以大致猜出systemctl的作用了,那就是:主要負責控制systemd系統和服務管理員。
什麼是systemd系統?
CentOS 7 使用systemd替換了SysV。Systemd目的是要取代Unix時代以來一直在使用的init系統,相容SysV和LSB的啟動指令碼,而且夠在進程啟動過程中更有效地引導載入服務。
systemd的特性有:
支援並行化任務;
同時採用socket式與D-Bus匯流排式啟用服務;
按需啟動守護進程(daemon);
利用 Linux 的 cgroups 監視進程;
支援快照和系統復原;
維護掛載點和自動掛載點;
各服務間基於依賴關係進行精密控制。
我們再來看看維基百科對它的介紹:
systemd is an init system used by some Linux distributions to bootstrap the user space and manage all processes subsequently, instead of the UNIX System V or Berkeley Software Distribution (BSD) init systems. The name systemd adheres to the Unix convention of naming daemons by appending the letter d.[6] It is published as free and open-source software under the terms of the GNU Lesser General Public License (LGPL) version 2.1 or later.[5] One of systemd’s main goals is to unify basic Linux configurations and service behaviors across all distributions.[7]
As of 2015, many Linux distributions have adopted systemd as their default init system.[8] The increasing adoption of systemd has been controversial, with critics arguing the software has violated the Unix philosophy by becoming increasingly complex, and that distributions have been forced to adopt it due to the dependency of various other software upon it, including, most notably, the GNOME 3 desktop environment.
總結一下關鍵資訊:
systemd是一個取代了SysV和LSB的初始化系統;
現在的大多數Linux發行版本都進行了這個更新;
systemd不僅僅只是個初始化系統,它還包括了還包括了管理系統各種的方面的 daemon;
systemd是大勢所趨又存在爭議。
所以,我們可以把systemctl理解為systemd的一個工具。也可以認為systemctl命令將service和chkconfig命令結合在了一起。總之,需要的時候會用就行。下面我們來看一些常見用法。
查看systemctl的相關資訊
[[email protected] ~]# systemctl --version
systemd 219
+PAM +AUDIT +SELINUX +IMA -APPARMOR +SMACK +SYSVINIT +UTMP +LIBCRYPTSETUP +GCRYPT +GNUTLS +ACL +XZ -LZ4 -SECCOMP +BLKID +ELFUTILS +KMOD +IDN
[[email protected] ~]# whereis systemctl
systemctl: /usr/bin/systemctl /usr/share/man/man1/systemctl.1.gz
[[email protected] ~]#
1
2
3
4
5
6
列出所有可用單元
# systemctl list-unit-files
1
這裡寫圖片描述
列出所有運行中單元
# systemctl list-units
1
這裡寫圖片描述
列出所有失敗的單元
[[email protected] ~]# systemctl --failed
0 loaded units listed. Pass --all to see loaded but inactive units, too.
To show all installed unit files use ‘systemctl list-unit-files‘.
[[email protected] ~]#
1
2
3
4
檢查某個單元是否啟用
[[email protected] ~]# systemctl is-enabled mysqld.service
disabled
[[email protected] ~]#
1
2
3
查看某個服務(單元)的狀態
這裡寫圖片描述
[[email protected] ~]# systemctl status firewalld.service
● firewalld.service - firewalld - dynamic firewall daemon
Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled; vendor preset: enabled)
Active: inactive (dead)
1
2
3
4
*啟動、重啟、停止、重載服務
# systemctl start httpd.service
# systemctl restart httpd.service
# systemctl stop httpd.service
# systemctl reload httpd.service
# systemctl status httpd.service
1
2
3
4
5
*啟用/禁止自動啟動
# systemctl enable httpd.service
# systemctl disable httpd.service
1
2
*殺死服務
# systemctl kill httpd
1
以上就是我目前需要用的和想要和大家分享的功能,下面的只是補充,也沒有詳細的樣本,所以有興趣的朋友可以再簡單看一看說明文檔就好了。
附錄
使用Systemctl控制並管理掛載點:
systemctl list-unit-files --type=mount
# systemctl start tmp.mount
# systemctl stop tmp.mount
# systemctl restart tmp.mount
# systemctl reload tmp.mount
# systemctl status tmp.mount
# systemctl is-active tmp.mount
# systemctl enable tmp.mount
# systemctl disable tmp.mount
# systemctl mask tmp.mount
1
2
3
4
5
6
7
8
9
10
11
12
13
使用Systemctl控制並管理套介面
# systemctl list-unit-files --type=socket
# systemctl start cups.socket
# systemctl restart cups.socket
# systemctl stop cups.socket
# systemctl reload cups.socket
# systemctl status cups.socket
# systemctl is-active cups.socket
# systemctl enable cups.socket
# systemctl disable cups.socket
# systemctl mask cups.socket
1
2
3
4
5
6
7
8
9
10
11
12
13
使用Systemctl管理服務的CPU利用率
# systemctl show -p CPUShares httpd.service
# systemctl set-property httpd.service CPUShares=2000
# systemctl show -p CPUShares httpd.service
# systemctl show httpd
1
2
3
4
5
6
其他
# systemd-analyze critical-chain httpd.service
# systemctl list-dependencies httpd.service
# systemd-cgls
# systemd-cgtop
# systemctl emergency
# systemctl reboot
# systemctl halt
# systemctl suspend
# systemctl hibernate
# systemctl hybrid-sleep
---------------------
涼秋cds
來源:CSDN
原文:51165361
著作權聲明:本文為博主原創文章,轉載請附上博文連結!
Centos7下的systemctl命令與service和chkconfig