Useful Commands/Service Management: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
|||
| (One intermediate revision by the same user not shown) | |||
| Line 4: | Line 4: | ||
|- | |- | ||
| 列舉系統服務 || | | 列舉系統服務 || | ||
< | <syntaxhighlight lang="bash"> | ||
systemctl -t service # 省略式 | systemctl -t service # 省略式 | ||
systemctl list-units -t service # 完整式 | systemctl list-units -t service # 完整式 | ||
</ | </syntaxhighlight> | ||
|- | |- | ||
| 服務操作 || | | 服務操作 || | ||
< | <syntaxhighlight lang="bash"> | ||
systemctl status nginx | systemctl status nginx | ||
systemctl start nginx | systemctl start nginx | ||
| Line 16: | Line 16: | ||
systemctl reload nginx | systemctl reload nginx | ||
systemctl disable mysql.service | systemctl disable mysql.service | ||
</ | systemctl reload systemd-networkd | ||
</syntaxhighlight> | |||
|} | |} | ||
| Line 23: | Line 24: | ||
! 情境 || 指令 | ! 情境 || 指令 | ||
|- | |- | ||
| 管理系統服務 || < | | 管理系統服務 || <syntaxhighlight lang="bash">sudo service start/stop/reload/restart {服務名稱}</syntaxhighlight> | ||
|- | |- | ||
| 顯示服務狀態 || < | | 顯示服務狀態 || <syntaxhighlight lang="bash">service --status-all</syntaxhighlight> | ||
|- | |- | ||
| 顯示服務 (啟動/關閉) 時機 (runlevel 0~6) || < | | 顯示服務 (啟動/關閉) 時機 (runlevel 0~6) || <syntaxhighlight lang="bash">chkconfig --list</syntaxhighlight> | ||
|- | |- | ||
| 設定服務在開機後自動啟動 || < | | 設定服務在開機後自動啟動 || <syntaxhighlight lang="bash">sudo chkconfig --level 2345 {服務名稱} on</syntaxhighlight> | ||
|} | |} | ||
Latest revision as of 20:21, 3 April 2025
CentOS 7.x / Ubuntu 16.04
| 情境 | 指令 |
|---|---|
| 列舉系統服務 |
systemctl -t service # 省略式
systemctl list-units -t service # 完整式
|
| 服務操作 |
systemctl status nginx
systemctl start nginx
systemctl stop nginx
systemctl reload nginx
systemctl disable mysql.service
systemctl reload systemd-networkd
|
Linux 傳統
| 情境 | 指令 |
|---|---|
| 管理系統服務 | sudo service start/stop/reload/restart {服務名稱}
|
| 顯示服務狀態 | service --status-all
|
| 顯示服務 (啟動/關閉) 時機 (runlevel 0~6) | chkconfig --list
|
| 設定服務在開機後自動啟動 | sudo chkconfig --level 2345 {服務名稱} on
|
Run Level 說明
| runlevel | 英文說明 | 中文說明 |
|---|---|---|
| 0 | halt | 系統關機 |
| 1 | single user mode | 單人模式,用在系統出問題時的維護 |
| 2 | Multi-user, without NFS | 類似 runlevel 3,但無 NFS 服務 |
| 3 | Full multi-user mode | 完整含有網路功能的純文字模式 |
| 4 | unused | 保留 |
| 5 | X11 | 類似 runlevel 3,有使用 X Window |
| 6 | reboot | 重新開機 |