分享

systemctl用法及其语法

 用勿龍潛 2020-01-02

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

6. 分析启动时的关键链

# systemd-analyze critical-chain

7.列出所有可用单元

# systemctl list-unit-files

8.列出所有运行中单元

# systemctl list-units

9.列出所有失败单元

# systemctl --failed

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

# systemctl is-enabled nfs.service

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

# systemctl status nfs.service

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

# 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

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

# systemctl is-active tmp.mount

# systemctl enable tmp.mount

# systemctl disable tmp.mount

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

# systemctl mask tmp.mount

# systemctl unmask tmp.mount

21. 列出所有可用套接字

# systemctl list-unit-files --type=socket

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

# 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

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

# systemctl show nfs

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

# 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

34. 确认当前的运行等级

# 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 : 关闭并重启系统。

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多