Linux systemctl 的使用方法和作用

这里写自定义目录标题

1.确定是否安装systemd及其版本

systemctl –version

2.确定systemd和systemctl的二进制文件和库文件的安装位置

whereis systemd

whereis systemctl

3.确定systemd是否运行

ps -eaf | grep [s]ystemd

4.分析systemd启动进程

systemd-analyze

5.分析启动时各个进程花费的时间

systemd-analyze blame

  1. 分析启动时的关键链

systemd-analyze critical-chain

7.列出所有可用单元

systemctl list-unit-files

8.列出所有运行中单元

systemctl list-units

9.列出所有失败单元

systemctl --failed

  1. 确定某个单元(如 nfs.service)是否启用

systemctl is-enabled nfs.service

11.确定某个单元或服务是否运行

systemctl status nfs.service

  1. 列出所有服务(包括启用的和禁用的)

systemctl list-unit-files --type=service

13.启动、重启、停止、重载服务及确定服务(如 nfs.service)状态

systemctl start nfs.service

systemctl restart nfs.service

systemctl stop nfs.service

systemctl reload nfs.service

systemctl status nfs.service

–注:

1)Systemctl的start,restart,stop和reload命令,终端并不输出任何相关信息,但可以通过status命令获取。

14.激活并配置服务自启和禁用服务

systemctl is-active nfs.service

systemctl enable nfs.service

systemctl disable nfs.service

15.屏蔽(禁止任何方式启动服务,其比disabled作用更强)或解除屏蔽服务

systemctl mask nfs.service

systemctl unmask nfs.service

16.杀死服务

systemctl kill nfs

systemctl status nfs

17.列出所有系统挂载点

systemctl list-unit-files --type=mount

18.挂载、卸载、重新挂载、重载系统挂载点和确定系统挂载点状态

systemctl start tmp.mount

systemctl stop tmp.mount

systemctl restart tmp.mount

systemctl reload tmp.mount

systemctl status tmp.mount

  1. 启动时激活、启用(自动挂载)或禁用挂载点

systemctl is-active tmp.mount

systemctl enable tmp.mount

systemctl disable tmp.mount

20.屏蔽(使其不能启用)或解屏蔽挂载点

systemctl mask tmp.mount

systemctl unmask tmp.mount

  1. 列出所有可用套接字

systemctl list-unit-files --type=socket

  1. 启动、重启、停止、重载套接字并确认其状态

systemctl start cups.socket

systemctl restart cups.socket

systemctl stop cups.socket

systemctl reload cups.socket

systemctl status cups.socket

23.系统启动时激活套接口,并启用(自启)或禁用该套接字

systemctl is-active cups.socket

systemctl enable cups.socket

systemctl disable cups.socket

24.屏蔽(使其不能启动)或解屏蔽套接字

systemctl mask cups.socket

systemctl unmask cups.socket

25.获取某个服务的CPU配额

systemctl show -p CPUShares nfs.service

26.限制某个服务的CPU配额为2000

systemctl set-property nfs.service CPUShares=2000

systemctl show -p CPUShares nfs.service

–注:

1)当为某个服务设置CPU配额时,系统会以服务名为名字创建一个目录(如 nfs.service),其中包含一个名为90-CPUShares.conf的文件,该文件包含CPUShare限制的相关信息,可以用如下方式查看该文件。

vi /etc/systemd/system/nfs.service.d/90-CPUShares.conf

  1. 确定某个服务的所有配置信息

systemctl show nfs

  1. 分析某个服务的关键链

systemd-analyze critical-chain nfs.service

29.获取某个服务的依赖性关系

systemctl list-dependencies nfs.service

30.按等级列出控制组

systemd-cgls

31.按CPU、内存、输入和输出列出控制组

systemd-cgtop

32.进入系统救援模式

systemctl rescue

33.进入紧急模式

systemctl emergency

  1. 确认当前的运行等级

systemctl get-default

35.进入相应运行等级

–图形模式(5)

systemctl isolate runlevel5.target

systemctl isolate graphical.target

–多用户模式(3)

systemctl isolate runlevel3.target

systemctl isolate multiuser.target

36.设置默认运行等级

systemctl set-default runlevel3.target

systemctl set-default runlevel5.target

37.使系统重启、停止、挂起、休眠或进入混合睡眠

systemctl reboot

systemctl halt

systemctl suspend

systemctl hibernate

systemctl hybrid-sleep

–注:

1)Runlevel 0 : 关闭系统。

2)Runlevel 1 : 救援维护模式。

3)Runlevel 3 : 多用户,无图形模式。

4)Runlevel 4 : 系统未使用,保留。

5)Runlevel 5 : 多用户,图形化模式。

6)Runlevel 6 : 关闭并重启系统。

  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值