systemctl详解[root@hadoop01 hadoop]# systemctl --help
systemctl [] {COMMAND} ...
Query or nd control commands to the systemd manager.
-h --help Show this help
--version Show package version
--system Connect to system manager
-H --host=[USER@]HOST
Operate on remote host
-M --machine=CONTAINER
Operate on local container
-t --type=TYPE List units of a particular type
-
-state=STATE List 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, u
the 'list-unit-files' command instead.
-l --full Don't ellipsize unit names on output
-r --recursive Show unit list of host and local containers
--rever Show rever dependencies with 'list-dependencies'
--job-mode=MODE Specify how to deal with already queued jobs, when
queueing a new job
--show-types When showing sockets, explicitly show their type
-
i --ignore-inhibitors
When shutting down or sleeping, ignore inhibitors
--kill-who=WHO Who to nd signal to
-s --signal=SIGNAL Which signal to nd
--now Start or stop unit in addition to enabling or disabling it
-q --quiet Suppress output
--no-block Do not wait until operation finished
--no-wall Don't nd wall message before halt/power-off/reboot
--no-reload Don't reload daemon after en-/dis-abling unit files
--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
--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
--pret-mode= Apply only enable, only disable, or all prets
--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-iso,
short-preci, short-monotonic, verbo,
export, json, json-pretty, json-s, 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
list-timers [] List loaded timers ordered by next elap
Start (activate) one or more units
Stop (deactivate) one or more units
Reload one or more units
Start or restart one or more units
Restart one or more units if active
Reload one or more units if possible,
otherwi start or restart
Reload one or more units if possible,
otherwi restart if active
isolate NAME Start one unit and stop all others
Send signal to process of a unit
Check whether units are active
Check whether units are failed
status [] Show runtime status of one or more units
show [] Show properties of one or more
units/jobs or the manager
Show files and drop-ins of one or more units
t-property Sets one or more properties of a unit
Show manual for one or more units
ret-failed [] Ret failed state for all, one, or more
units
list-dependencies [NAME] Recursively show units which are required
or wanted by this unit or by which this
unit is required or wanted
systemctl [] {COMMAND} ...
Query or nd control commands to the systemd manager.
-h --help Show this help
-
-version Show package version
systemctl [] {COMMAND} ...
systemctl [] {COMMAND} ...
Query or nd control commands to the systemd manager.
-h --help Show this help
--version Show package version
--system Connect to system manager
-H --host=[USER@]HOST
Operate on remote host
-M --machine=CONTAINER
Operate on local container
-
t --type=TYPE List units of a particular type
--state=STATE List 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, u
the 'list-unit-files' command instead.
-l --full Don't ellipsize unit names on output
-r --recursive Show unit list of host and local containers
--rever Show rever dependencies with 'list-dependencies'
--job-mode=MODE Specify how to deal with already queued jobs, when queueing a new job
--show-types When showing sockets, explicitly show their type
-i --ignore-inhibitors
When shutting down or sleeping, ignore inhibitors
--kill-who=WHO Who to nd signal to
-s --signal=SIGNAL Which signal to nd
--now Start or stop unit in addition to enabling or disabling it
-q --quiet Suppress output
--no-block Do not wait until operation finished
--no-wall Don't nd wall message before halt/power-off/reboot
--no-reload Don't reload daemon after en-/dis-abling unit files
--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
--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
--pret-mode= Apply only enable, only disable, or all prets
--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-iso,
short-preci, short-monotonic, verbo,
export, json, json-pretty, json-s, 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
list-timers [] List loaded timers ordered by next elap
Start (activate) one or more units
Stop (deactivate) one or more units
Reload one or more units
Start or restart one or more units
Restart one or more units if active
筒骨莲藕汤 Reload one or more units if possible,
otherwi start or restart
车辆管理台账 Reload one or more units if possible,
otherwi restart if active
isolate NAME Start one unit and stop all others
Send signal to process of a unit
Check whether units are active
Check whether units are failed
status [] Show runtime status of one or more units show [] Show properties of one or more
units/jobs or the manager
Show files and drop-ins of one or more units t-property Sets one or more properties of a unit Show manual for one or more units
ret-failed [] Ret failed state for all, one, or more
units
list-dependencies [NAME] Recursively show units which are required or wanted by this unit or by which this
unit is required or wanted
Unit File Commands:
list-unit-files [] List installed unit files
Enable one or more unit files
Disable one or more unit files
Reenable one or more unit files
Enable/disable one or more unit files
bad on pret configuration
pret-all Enable/disable all unit files bad on
pret configuration
Check whether unit files are enabled
Mask one or more units
Unmask one or more units
Link one or more units files into
the arch path
add-wants Add 'Wants' dependency for the target
on specified one or more units
add-requires Add 'Requires' dependency for the target
on specified one or more units
Edit one or more unit files
get-default Get the name of the default target
t-default NAME Set the default target
Machine Commands:
list-machines [] List local containers and host
Job Commands:
list-jobs [] List jobs
形容人性格的成语
cancel [] Cancel all, one, or more jobs
现代企业管理论文Snapshot Commands:
snapshot [NAME] Create a snapshot
Remove one or more snapshots
Environment Commands:
show-environment Dump environment
t-environment Set one or more environment variables
Unt one or more environment variables
import-environment [] Import all or some environment variables
Manager Lifecycle Commands:
daemon-reload Reload systemd manager configuration
daemon-reexec Reexecute systemd manager
System Commands:
is-system-running Check whether system is fully running
default Enter system default mode
弃婴岛rescue Enter system rescue mode
emergency Enter system emergency mode
halt Shut down and halt the system
poweroff Shut down and power-off the system
reboot [ARG] Shut down and reboot the system
kexec Shut down and reboot the system with kexec
exit Request ur instance exit
switch-root ROOT [INIT] Change to a different root file system
suspend Suspend the system
hibernate Hibernate the system
hybrid-sleep Hibernate and suspend the system
⼀、Systemd简介
Systemd是由红帽公司的⼀名叫做Lennart Poettering的员⼯开发,systemd是Linux系统中最新的初始化系统(init),它主要的设计⽬的是克服Sys V 固有的缺点,提⾼系统的启动速度。
systemd和upstart是竞争对⼿,ubantu上使⽤的是upstart的启动⽅式,centos7上使⽤systemd替换了Sys V,Systemd⽬录是要取代Unix时代依赖⼀直在使⽤的init系统,兼容SysV和LSB的启动脚本,
⽽且能够在进程启动中更有效地引导加载服务。
system:系统启动和服务器守护进程管理器,负责在系统启动或运⾏时,激活系统资源,服务器进程和其他进程,根据管理,字母d是守护进程(daemon)的缩写,systemd这个名字的含义就是它要守护整个系统。
⼆、Systemd新特性
系统引导时实现服务并⾏启动
按需启动守护进程
⾃动化的服务依赖关系管理
同时采⽤socket式与D-Bus总线式激活服务
系统状态快照和恢复
利⽤Linux的cgroups监视进程
维护挂载点和⾃动挂载点
各服务间基于依赖关系进⾏精密控制
三、Systemd核⼼概念
Unit
表⽰不同类型的sytemd对象,通过配置⽂件进⾏标识和配置,⽂件中主要包含了系统服务,监听socket、保存的系统快照以及其他与init相关的信息
配置⽂件:
/usr/lib/systemd/system:每个服务最主要的启动脚本设置,类似于之前的/etc/initd.d
/run/system/system:系统执⾏过程中所产⽣的服务脚本,⽐上⾯的⽬录优先运⾏
/etc/system/system:管理员建⽴的执⾏脚本,类似于/etc/rc.d/rcN.d/Sxx类的功能,⽐上⾯⽬录优先运⾏,在三者之中,此⽬录优先级最⾼
四、Unit类型
systemctl -t help :查看unit类型
rvice unit:⽂件扩展名为.rvice,⽤于定义系统服务
target unit:⽂件扩展名为.target,⽤于模拟实现“运⾏级别”
device unit: .device,⽤于定义内核识别的设备
mount unit :.mount,定义⽂件系统挂载点
socket unit :.socket,⽤于标识进程间通信⽤的socket⽂件,也可以在系统启动时,延迟启动服务,实现按需启动
snapshot unit:.snapshot,关系系统快照
swap unit:.swap,⽤于表⽰swap设备
automount unit:.automount,⽂件系统的⾃动挂载点如:/misc⽬录
path unit:.path,⽤于定义⽂件系统中的⼀个⽂件或⽬录使⽤,常⽤于当⽂件系统变化时,延迟激活服务,如spool⽬录
time:.timer由systemd管理的计时器
注:使⽤systemctl控制单元时,通常需要使⽤单元⽂件的全名,包括扩展名,但是有些单元可以在systemctl中使⽤简写⽅式,如果⽆扩展名,systemctl默认把扩展名当做.rvice。例如netcfg和netcfg.rvice是等同的挂载点会⾃动转化为相应的.mount单元,例如/home等价于unt设备会⾃动转化为相应的.device单元,所以/dev/sd2等价于dev-sda2.device
五、关键特性
基于socket的激活机制:socket与服务进程分离
基于D-Bus的激活机制
基于device的激活机制
基于path的激活机制
系统快照:保存各unit的当前状态信息于持久存储设备中想后兼容sysv init脚本
六、不兼容
systemctl命令固定不变,不可扩展
⾮由systemd启动的服务,systemctl⽆语与之通信和控制,如:使⽤之前sys v风格管理的进程就⽆法收systemd控制
七、Systemd基本⼯具
监视和控制systemd的主要命令是systemctl。该命令可⽤于查看系统状态和管理系统及服务。
管理服务
命令:systemctl command name.rvice
启动:rvice name start –>systemctl start name.rvice
停⽌:rvice name stop –>systemctl stop name.rvice
重启:rvice name restart–>systemctl restart name.rvice
状态:rvice name status–>systemctl status name.rvice
条件式重启(已启动才重启,否则不做任何操作)
systemctl try-restart name.rvice
重载或重启服务(先加载,然后再启动)
青春梦systemctl reload-or-try-restart name.rvice
禁⽌⾃动和⼿动启动
systemctl mask name.rvice
执⾏此条命令实则创建了⼀个链接 ln -s '/dev/null' '/etc/systemd/system/sshd.rvice'
取消禁⽌
systemctl unmask name.rvice
删除此前创建的链接
服务查看(查看某服务当前激活与否的状态)
systemctl is-active name.rvice
如果启动会显⽰active,否则会显⽰unknown
查看所有已经激活的服务
systemctl list-units –t|–type rvice
[root@hadoop01 hadoop]# systemctl --helpsystemctl [] {COMMAND} ...
Query or nd control commands to the systemd manager.
-
h --help Show this help --version Show package version --system Connect to system manager -H --host=
[USER@]HOST Operate on remote host -M --machine=CONTAINER Operate on local container -t --type=TYPE List units of a particular type --state=STATE List 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, u the 'list-unit-files' command instead. -l --full Don't ellipsize unit names on output -r --recursive Show unit list of host and local containers --rever Show rever dependencies with 'list-dependencies' --job-mode=MODE Specify how to deal with already queued jobs, when queueing a new job --show-types When showing sockets, explicitly show their type -i --ignore-inhibitors When shutting down or sleeping, ignore inhibitors --kill-who=WHO Who to nd signal to -s --signal=SIGNAL Which signal to nd --now Start or stop unit in addition to enabling or disabling it -q --quiet Suppress output --no-block Do not wait until operation finished --no-wall Don't nd wall message before halt/power-off/reboot --no-reload Don't reload daemon after en-/dis-abling unit files --no-legend Do not print a legend (column headers and hints) --no-pager Do not p
ipe output into a pager --no-ask-password Do not ask for system passwords --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 --pret-mode= Apply only enable, only disable, or all prets --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-iso, short-preci, short-monotonic, verbo, export, json, json-pretty, json-s, 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 list-timers [] List loaded timers ordered by next elap Start (activate) one or more units Stop (deactivate) one or more units Reload one or more units Start or restart one or more units Restart one or more units if active Reload one or more units if possible, otherwi start or restart Reload one or more units if possible, otherwi restart if active isolate NAME Start one unit and stop all others kill
< Send signal to process of a unit Check whether units are active Check whether units are failed status [] Show runtime status of one or more units show [] Show properties of one or more units/jobs or the manager Show files and drop-ins of one or more units t-property Sets one or more properties of a unit Show manual for one or more units ret-failed [] Ret failed state for all, one, or more units list-dependencies [NAME] Recursively show units which are required or wanted by this unit or by which this unit is required or wanted
systemctl [] {COMMAND} ...
Query or nd control commands to the systemd manager.
-h --help Show this help --version Show package versionsystemctl [] {COMMAND} ...
systemctl [] {COMMAND} ...
Query or nd control commands to the systemd manager.
-h --help Show this help --version Show package version --system Connect to system manager -H --host=
[USER@]HOST Operate on remote host -M --machine=CONTAINER Operate on local container -t --type=TYPE List units of a particular type --state=STATE List 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, u the 'list-unit-files' command instead. -l --full Don't ellipsize unit names on output -r --recursive Show unit list of host and local containers --rever Show rever dependencies with 'list-dependencies' --job-mode=MODE Specify how to deal with already queued jobs, when queueing a new job --show-types When showing sockets, explicitly show their type -i --ignore-inhibitors When shutting down or sleeping, ignore inhibitors --kill-who=WHO Who to nd signal to -s --signal=SIGNAL Which signal to nd --now Start or stop unit in addition to enabling or disabling it -q --quiet Suppress output --no-block Do not wait until operation finished --no-wall Don't nd wall message before halt/power-off/reboot --no-reload Don't reload daemon after en-/dis-abling unit files --no-legend Do not print a legend (column headers and hints) --no-pager Do not p
ipe output into a pager --no-ask-password Do not ask for system passwords --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 --pret-mode= Apply only enable, only disable, or all prets --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-iso, short-preci, short-monotonic, verbo, export, json, json-pretty, json-s, 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 list-timers [] List loaded timers ordered by next elap Start (activate) one or more units Stop (deactivate) one or more units Reload one or more units Start or restart one or more units Restart one or more units if active Reload one or more units if possible, otherwi start or restart Reload one or more units if possible, otherwi restart if active isolate NAME Start one unit and stop all others kill
< Send signal to process of a unit Check whether units are active Check whether units are failed status [] Show runtime status of one or more units show [] Show properties of one or more units/jobs or the manager Show files and drop-ins of one or more units t-property Sets one or more properties of a unit Show manual for one or more units ret-failed