Linux_systemctl命令

systemctl 命令有两大类功能:
1.控制 systemd 系统
2.管理系统上运行的服务
$ systemctl --version 检查systemd的版本
$ whereis systemd 查看systemd程序相关的目录
$ whereis systemctl 查看systemctl程序相关的目录
$systemctl mask prometheus.service 注销某个服务,注销之后无法再启动这个服务。
$systemctl unmask prometheus.service 反注销某个服务,注销的反操作
$systemctl list-unit-files 查看系统上一共装了多少个unit,包含所有的状态
$systemctl list-unit 查看系统上一共装了多少个unit,只包括active的
$ systemctl list-units --type=service --all 查看指定类型的服务用参数–type
$ systemctl list-units --type=mount --all
$ systemctl --failed 查看是否有unit加载失败

操作环境
$ systemctl list-units --type=service --all 通过指定 --type=target 就可以用 命令查看系统中默认有多少种操作环境(target unit)
$ systemctl get-default 查看启动时默认的操作环境(比如查出来的为图形界面)
graphical.target
$ systemctl isolate multi-user.target 修改默认启动操作环境,这个下次登陆系统时就是命令行界面

关机和开机
$ sudo systemctl poweroff # 系统关机
$ sudo systemctl reboot # 重新开机
$ sudo systemctl suspend # 进入暂停模式
$ sudo systemctl hibernate # 进入休眠模式
$ sudo systemctl rescue # 强制进入救援模式
$ sudo systemctl emergency # 强制进入紧急救援模式

检查 unit 之间的依赖性
systemctl list-dependencies [unit] [–reverse] 选项 --reverse 会反向追踪是谁在使用这个 unit。
eg:systemctl list-dependencies default.target

# systemctl start nginx #启动nginx
# systemctl stop nginx #停止nginx
# systemctl restart nginx #重启nginx
# systemctl reload nginx #重新加载nginx配置
# systemctl status nginx #输出nginx运行状态
# systemctl is-enabled nginx #检查nginx是否配置为自动启动
# systemctl enable nginx #开机自动启动nginx
# systemctl disable nginx #取消开机自动启动nginx

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值