美文网首页
linux命令大全之——系统服务管理systemctl

linux命令大全之——系统服务管理systemctl

作者: yichen_china | 来源:发表于2018-12-22 12:05 被阅读14次

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

    命令 说明
    systemctl list-unit-files 列出所有可用单元
    systemctl list-units 列出所有运行中单元
    systemctl –failed 列出所有失败单元
    systemctl is-enabledcrond.service 检查某个单元(如 crond.service)是否启用
    systemctl list-unit-files –type=service 列出所有服务

    服务状态控制

    命令 说明
    systemctl status httpd.service 检测服务状态
    systemctl start httpd.service 启动
    systemctl restart httpd.service 重启
    systemctl stop httpd.service 停止
    systemctl reload httpd.service 重载

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

    激活服务——开机时自动启动服务

    命令 说明
    systemctl is-active mysql.service 激活服务
    systemctl enable mysql.service 启用开机时自动启动
    systemctl disable mysql.service 禁用开机自动启动
    1. 如何屏蔽(让它不能启动)或显示服务(如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’
    

    杀死服务——挂载服务

    命令 说明
    systemctl killcrond 使用systemctl命令杀死服务
    systemctl list-unit-files –type=mount 列出所有系统挂载点
    # systemctl start tmp.mount 挂载
    # systemctl stop tmp.mount 卸载
    # systemctl restart tmp.mount 重新挂载
    # systemctl reload tmp.mount 重载系统挂载点
    # systemctl status tmp.mount 检查系统中挂载点状态

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

    命令 说明
    systemctl is-active tmp.mount 启动时激活挂载点
    systemctl enable tmp.mount 启用
    systemctl disable tmp.mount 禁用挂载点

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

    systemctl mask tmp.mount
    ln -s ‘/dev/null”/etc/systemd/system/tmp.mount’
    
    systemctl unmask tmp.mount
    rm ‘/etc/systemd/system/tmp.mount’
    
    命令 说明
    systemctl list-unit-files –type=socket 列出所有可用系统套接口
    systemctl showmysql 检查某个服务的所有配置细节
    systemctl list-dependencies httpd.service 获取某个服务(httpd)的依赖性列表
    systemctl rescue 启动救援模式
    systemctl emergency 进入紧急模式
    systemctl get-default 列出当前使用的运行等级
    systemctl isolate runlevel5.target 启动运行等级5,即图形模式 或 systemctl isolate graphical.target
    systemctl isolate runlevel3.target 启动运行等级3,即多用户模式(命令行)或systemctl isolate multiuser.target
    systemctl set-default runlevel3.target 设置多用户模式或图形模式为默认运行等级
    systemctl set-default runlevel5.target 设置多用户模式或图形模式为默认运行等级
    systemctl reboot 系统重启
    systemctl halt 系统停止
    systemctl suspend 系统挂起
    systemctl hibernate 系统休眠
    systemctl hybrid-sleep 系统混合休眠

    对于不知运行等级为何物的人,说明如下。

    级别 说明
    Runlevel 0 关闭系统
    Runlevel 1 救援,维护模式
    Runlevel 3 多用户,无图形系统
    Runlevel 4 多用户,无图形系统
    Runlevel 5 多用户,图形化系统
    Runlevel 6 关闭并重启机器

    相关文章

      网友评论

          本文标题:linux命令大全之——系统服务管理systemctl

          本文链接:https://www.haomeiwen.com/subject/azrikqtx.html