systemctl 指令

版主: stnet253

回覆文章
tony
文章: 585
註冊時間: 2012-02-26, 07:04
聯繫:

systemctl 指令

未閱讀文章 tony »

之前使用 CentOS 時,安裝伺服器套件後,大部分都是使用 chkconfig 來啟動預設要啟動的服務,或是直接到 /etc/init.d 目錄之下,去啟動要使用的服務,可是安裝 CentOS 7 之後,發現 /etc/init.d 目錄下的檔案非常的少,似乎新版本的 CentOS 服務,都不是使用這樣的啟動方式。

代碼: 選擇全部

# ls /etc/init.d
functions iprdump iprinit iprupdate netconsole network README

後來在網路搜尋了一下,才發現好像是改用 systemctl 指令來做控制。
systemctl 指令參數

代碼: 選擇全部

# systemctl --help
systemctl [OPTIONS...] {COMMAND} ...

Query or send control commands to the systemd manager.

-h --help Show this help
--version Show package version
-t --type=TYPE List only units of a particular type
--state=STATE List only units with particular LOAD or SUB or ACTIVE state
-p --property=NAME Show only properties by this name
-a --all Show all loaded units/properties, including dead/empty
ones. To list all units installed on the system, use
the 'list-unit-files' command instead.
--reverse Show reverse dependencies with 'list-dependencies'
-l --full Don't ellipsize unit names on output
--fail When queueing a new job, fail if conflicting jobs are
pending
--irreversible When queueing a new job, make sure it cannot be implicitly
cancelled
--ignore-dependencies
When queueing a new job, ignore all its dependencies
--show-types When showing sockets, explicitly show their type
-i --ignore-inhibitors
When shutting down or sleeping, ignore inhibitors
--kill-who=WHO Who to send signal to
-s --signal=SIGNAL Which signal to send
-H --host=[USER@]HOST
Show information for remote host
-P --privileged Acquire privileges before execution
-q --quiet Suppress output
--no-block Do not wait until operation finished
--no-wall Don't send wall message before halt/power-off/reboot
--no-reload When enabling/disabling unit files, don't reload daemon
configuration
--no-legend Do not print a legend (column headers and hints)
--no-pager Do not pipe output into a pager
--no-ask-password
Do not ask for system passwords
--system Connect to system manager
--user Connect to user service manager
--global Enable/disable unit files globally
--runtime Enable unit files only temporarily until next reboot
-f --force When enabling unit files, override existing symlinks
When shutting down, execute action immediately
--root=PATH Enable unit files in the specified root directory
-n --lines=INTEGER Number of journal entries to show
-o --output=STRING Change journal output mode (short, short-monotonic,
verbose, export, json, json-pretty, json-sse, cat)
--plain Print unit dependencies as a list instead of a tree

Unit Commands:
list-units List loaded units
list-sockets List loaded sockets ordered by address
start [NAME...] Start (activate) one or more units
stop [NAME...] Stop (deactivate) one or more units
reload [NAME...] Reload one or more units
restart [NAME...] Start or restart one or more units
try-restart [NAME...] Restart one or more units if active
reload-or-restart [NAME...] Reload one or more units if possible,
otherwise start or restart
reload-or-try-restart [NAME...] Reload one or more units if possible,

啟動 vsftpd FTP Server
# systemctl start vsftpd

顯示 vsftpd FTP Server 狀態
# systemctl status vsftpd
vsftpd.service - Vsftpd ftp daemon
Loaded: loaded (/usr/lib/systemd/system/vsftpd.service; disabled)
Active: active (running) since 四 2014-07-10 20:34:41 CST; 41s ago
Process: 34160 ExecStart=/usr/sbin/vsftpd /etc/vsftpd/vsftpd.conf (code=exited, status=0/SUCCESS)
Main PID: 34161 (vsftpd)
CGroup: /system.slice/vsftpd.service
└─34161 /usr/sbin/vsftpd /etc/vsftpd/vsftpd.conf

7月 10 20:34:41 localhost.localdomain systemd[1]: Starting Vsftpd ftp daemon...
7月 10 20:34:41 localhost.localdomain systemd[1]: Started Vsftpd ftp daemon.

關閉 vsftpd FTP Server

代碼: 選擇全部

# systemctl stop vsftpd
列出 vsftpd FTP Server 啟動狀態

代碼: 選擇全部

# systemctl list-unit-files | grep vsftpd
vsftpd.service disabled
[email protected] disabled
vsftpd.target disabled

開機時啟動 vsftpd FTP Serve

代碼: 選擇全部

# systemctl enable vsftpd
ln -s '/usr/lib/systemd/system/vsftpd.service' '/etc/systemd/system/multi-user.target.wants/vsftpd.service

檢查是否有設定成功

代碼: 選擇全部

# systemctl list-unit-files | grep vsftpd
vsftpd.service enabled
[email protected] disabled
vsftpd.target disabled

代碼: 選擇全部

# systemctl is-active vsftpd
inactive

開機時關閉 vsftpd FTP Serve

代碼: 選擇全部

# systemctl disable vsftpd
rm '/etc/systemd/system/multi-user.target.wants/vsftpd.service'

檢查是否有設定成功

代碼: 選擇全部

# systemctl list-unit-files | grep vsftpd
vsftpd.service disabled
[email protected] disabled
vsftpd.target disabled
回覆文章

誰在線上

正在瀏覽這個版面的使用者:沒有註冊會員 和 1 位訪客