systemd, systemctl basic, command
Contents
查看配置文件位置
systemctl status service0
配置文件主要放在/usr/lib/systemd/system目录,也可能在/etc/systemd/system目录
配置文件
[Unit] 区块:启动顺序与依赖关系。
After字段:表示如果network.target或sshd-keygen.service需要启动,那么sshd.service应该在它们之后启动。
相应地,还有一个Before字段,定义sshd.service应该在哪些服务之前启动。
注意,After和Before字段只涉及启动顺序,不涉及依赖关系。
systemd-analyze
查看启动耗时
$ systemd-analyze
# 查看每个服务的启动耗时
systemd-analyze blame
# 显示瀑布状的启动过程流
$ systemd-analyze critical-chain
# 显示指定服务的启动流
$ systemd-analyze critical-chain atd.service
systemctl --version
# 生成一张启动详细信息矢量图, .svg可以用chrome打开
sudo systemd-analyze plot > /home/wiloon/tmp/boot3.svg
hostnamectl
# 显示当前主机的信息
$ hostnamectl
# 设置主机名。
$ sudo hostnamectl set-hostname rhel7
timedatectl
# 查看当前时区设置
$ timedatectl
# 显示所有可用的时区
$ timedatectl list-timezones
# 设置当前时区
$ sudo timedatectl set-timezone America/New_York
$ sudo timedatectl set-time YYYY-MM-DD
$ sudo timedatectl set-time HH:MM:SS
loginctl
# 列出当前session
$ loginctl list-sessions
# 列出当前登录用户
$ loginctl list-users
# 列出显示指定用户的信息
$ loginctl show-user ruanyf
cat
systemctl cat bluetooth|grep Condition
unmask
|
|
check the boot performance
|
|
|
|
systemctl status
Loaded行:配置文件的位置,是否设为开机启动
Active行:表示正在运行
Main PID行:主进程ID
Status行:由应用本身(这里是 httpd )提供的软件当前状态
CGroup块:应用的所有子进程
日志块:应用的日志
http://www.ruanyifeng.com/blog/2016/03/systemd-tutorial-commands.html
Unit
Systemd 可以管理所有系统资源。不同的资源统称为 Unit(单位)。 Unit 一共分成12种。
Service unit:系统服务
Target unit:多个 Unit 构成的一个组
Device Unit:硬件设备
Mount Unit:文件系统的挂载点
Automount Unit:自动挂载点
Path Unit:文件或路径
Scope Unit:不是由 Systemd 启动的外部进程
Slice Unit:进程组
Snapshot Unit:Systemd 快照,可以切回某个快照
Socket Unit:进程间通信的 socket
Swap Unit:swap 文件
Timer Unit:定时器
systemctl list-units
# 列出正在运行的 Unit
$ systemctl list-units
# 列出所有Unit,包括没有找到配置文件的或者启动失败的
$ systemctl list-units --all
# 列出所有没有运行的 Unit
$ systemctl list-units --all --state=inactive
# 列出所有加载失败的 Unit
$ systemctl list-units --failed
# 列出所有正在运行的、类型为 service 的 Unit
$ systemctl list-units --type=service
Unit 管理
# 立即启动一个服务
$ sudo systemctl start apache.service
# 立即停止一个服务
$ sudo systemctl stop apache.service
# 重启一个服务
$ sudo systemctl restart apache.service
# 杀死一个服务的所有子进程
$ sudo systemctl kill apache.service
# 重新加载一个服务的配置文件
$ sudo systemctl reload apache.service
# 重载所有修改过的配置文件
$ sudo systemctl daemon-reload
# 显示某个 Unit 的所有底层参数
$ systemctl show httpd.service
# 显示某个 Unit 的指定属性的值
$ systemctl show -p CPUShares httpd.service
# 设置某个 Unit 的指定属性
$ sudo systemctl set-property httpd.service CPUShares=500
依赖关系
systemctl list-dependencies nginx.service systemctl list-dependencies –all nginx.service
/etc/systemd/system/ /usr/lib/systemd/system/ /etc/systemd/system/multi-user.target.wants/v2ray.service
https://www.ruanyifeng.com/blog/2016/03/systemd-tutorial-part-two.html https://www.cnblogs.com/xingmuxin/p/11413784.html
Author w1100n
LastMod 2015-05-04