Linux —— systemctl命令

Linux —— systemctl命令

Systemctl是一个系统管理守护进程、工具和库的集合,取代

systemctl -help

[root@localhost ~]# systemctl -help
systemctl [OPTIONS...] {COMMAND} ...

Query or send control commands to the systemd manager.

  -h --help           Show this help
     --version        Show package version
     --system         Connect to system manager
  -H --host=[USER@]HOST
                      Operate on remote host
  -M --machine=CONTAINER
                      Operate on local container
  -t --type=TYPE      List units of a particular type
     --state=STATE    List units with particular LOAD or SUB or ACTIVE state
  -p --property=NAME  Show only properties by this name
  -a --all            Show all loaded units/properties, including dead/empty
                      ones. To list all units installed on the system, use
                      the 'list-unit-files' command instead.
  -l --full           Don't ellipsize unit names on output
  -r --recursive      Show unit list of host and local containers
     --reverse        Show reverse dependencies with 'list-dependencies'
     --job-mode=MODE  Specify how to deal with already queued jobs, when
                      queueing a new job
     --show-types     When showing sockets, explicitly show their type
  -i --ignore-inhibitors
                      When shutting down or sleeping, ignore inhibitors
     --kill-who=WHO   Who to send signal to
  -s --signal=SIGNAL  Which signal to send
     --now            Start or stop unit in addition to enabling or disabling it
  -q --quiet          Suppress output
     --no-block       Do not wait until operation finished
     --no-wall        Don't send wall message before halt/power-off/reboot
     --no-reload      Don't reload daemon after en-/dis-abling unit files

 

1、systemctl list-unit-files:列出所有可用单元

UNIT FILE 和 STATE两列,state:[static, disabled, enabled]

 

2、systemctl list-units:列出所有运行中单元

3、systemctl --failed:列出所有失败单元

4、systemctl is-enabled firewalld.service:检查某个单元是否启用(如firewalld.service)

启用返回enabled,禁用返回disabled

5、列出所有服务

  • systemctl list-unit-files --type=service

筛选包含“free”的服务

  • systemctl list-unit-files --type=service|grep free

列出所有系统挂载点:

  • systemctl list-unit-files --type=mount

6、启动、重启、停止、重载服务以及检查服务状态

  • # systemctl start httpd.service
  • # systemctl restart httpd.service
  • # systemctl stop httpd.service
  • # systemctl reload httpd.service
  • # systemctl status httpd.service

注意:当我们使用systemctl的start,restart,stop和reload命令时,终端不会输出任何内容,只有status命令可以打印输出。

7、激活服务并在开机时启用或禁用服务(即系统启动时自动启动postgresql.service服务)

  • systemctl is-active postgresql.service
  • systemctl enable postgresql.service(打印输出:Created symlink from /etc/systemd/system/multi-user.target.wants/postgresql.service to /usr/lib/systemd/system/postgresql.service.)
  • systemctl disable postgresql.service(打印输出:Removed symlink /etc/systemd/system/multi-user.target.wants/postgresql.service.)

8、屏蔽或显示服务

  • systemctl mask postgresql.service(终端输出:Created symlink from /etc/systemd/system/postgresql.service to /dev/null.)
  • systemctl start postgresql.service(终端输出:Failed to start postgresql.service: Unit is masked.)
  • systemctl unmask postgresql.service(终端输出:Removed symlink /etc/systemd/system/postgresql.service.)

9、杀死服务

  • systemctl kill postgresql
  • systemctl status postgresql(状态为failed,区别于stop服务的状态为inactive,---start启动)

10、挂载

  • 列出所有系统挂载点:systemctl list-unit-files --type=mount

11. 挂载、卸载、重新挂载、重载系统挂载点并检查系统中挂载点状态 

# systemctl start tmp.mount

# systemctl stop tmp.mount

# systemctl restart tmp.mount

# systemctl reload tmp.mount

# systemctl status tmp.mount

12. 在启动时激活、启用或禁用挂载点(系统启动时自动挂载) 

# systemctl is-active tmp.mount

# systemctl enable tmp.mount

# systemctl disable tmp.mount

13. 在Linux中屏蔽(让它不能启用)或可见挂载点 

# systemctl mask tmp.mount

ln -s ‘/dev/null”/etc/systemd/system/tmp.mount’

# systemctl unmask tmp.mount

rm ‘/etc/systemd/system/tmp.mount’

 

 

参考:https://www.cnblogs.com/zhming26/p/6155201.html

 

查看某个服务是否

[root@localhost /]# systemctl status postgresql

posted @ 2020-10-12 10:09  乖巧Clare  阅读(563)  评论(0编辑  收藏  举报