systemctl

systemctl

systemctl主要是用来监视和控制systemd,可用于查看系统状态和管理系统及服务。

分析系统状态的常用的命令如下:

systemctl status 显示系统状态

systemctl list-units 输出激活的单元

systemctl –-failed 输出运行失败的单元

systemctl list-unit-files查看所有已经安装的服务

 

单元配置文件

一个单元配置文件可以描述如下内容之一:

系统服务(.service)

挂载点(.mount)

Sockets(.sockets)

系统设备(.device)

交换分区(.swap)

文件路径(.path)

启动目标(.target)

由systemd管理的定时器(.timer)

使用systemctl控制单元时,通常需要使用单元文件的全名,包括扩展名(如ssh.service)。

如果无扩展名,systemctl默认把扩展名当作.service.(network 《==》 network.serivce)

挂载点会自动转化为相应的.mount单元.(如/home 《==》 home.mount)

设备会自动转化为相应的.device单元.(如/devv/sda2 《==》 dev-sda2.device)

 

systemctl控制单元的常用命令如下:

systemctl start <unit> 启动单元

systemctl stop <unit> 停止单元

systemctl stop <unit> 重启单元

systemctl reload <unit> 重新加载单元

Systemcrl status <unit> 输出单元状态

systemctl is-enabled <unit> 检查单元是否为开机自启动

Systenctl enable <unit> 设置单元为开机自启动

systemctl enable –now <unit> 设置单元为开机自启动并立即启动单元

systemctl disable <unit> 取消单元的开机自启动

 

使用示例:

systemctl restart network.service 重启网络服务

systemctl enable sshd.service 设置sshd服务开机自动启动

原文地址:https://www.cnblogs.com/tongyishu/p/12053480.html