当前位置 主页 > 服务器问题 > Linux/apache问题 >

    Linux系统中systemctl命令详解

    栏目:Linux/apache问题 时间:2019-11-10 14:22

    Linux Systemctl是一个系统管理守护进程、工具和库的集合,用于取代System V、service和chkconfig命令,初始进程主要负责控制systemd系统和服务管理器。通过Systemctl –help可以看到该命令主要分为:查询或发送控制命令给systemd服务,管理单元服务的命令,服务文件的相关命令,任务、环境、快照相关命令,systemd服务的配置重载,系统开机关机相关的命令。

    1. 列出所有可用单元

    # systemctl list-unit-files

    2. 列出所有运行中单元

    # systemctl list-units

    3. 列出所有失败单元

    # systemctl –failed

    4. 检查某个单元(如 crond.service)是否启用

    # systemctl is-enabled crond.service

    5. 列出所有服务

    # systemctl list-unit-files –type=service

    6. Linux中如何启动、重启、停止、重载服务以及检查服务(如 httpd.service)状态

    # 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. 如何激活服务并在开机时启用或禁用服务(即系统启动时自动启动mysql.service服务)

    # systemctl is-active mysql.service
    # systemctl enable mysql.service
    # systemctl disable mysql.service

    8. 如何屏蔽(让它不能启动)或显示服务(如ntpdate.service)

    # systemctl mask ntpdate.service
    ln -s ‘/dev/null”/etc/systemd/system/ntpdate.service'
    # systemctl unmask ntpdate.service
    rm ‘/etc/systemd/system/ntpdate.service'
    

    9. 使用systemctl命令杀死服务

    # systemctl kill crond

    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'

    14. 列出所有可用系统套接口

    # systemctl list-unit-files –type=socket

    15. 检查某个服务的所有配置细节