zl程序教程

您现在的位置是:首页 >  系统

当前栏目

CentOS7 从查看、启动、停止服务说起systemctl

centos7服务 查看 启动 停止 systemctl 说起
2023-09-14 09:02:30 时间

执行命令“systemctl status 服务名.service”可查看服务的运行状态,其中服务名后的.service 可以省略,这是CenOS7以后采用systemd作为初始化进程后产生的变化。

Systemctl是一个systemd工具,主要负责控制systemd系统和服务管理器。

Systemd是一个系统管理守护进程、工具和库的集合,用于取代System V初始进程。Systemd的功能是用于集中管理和配置Linux系统。

以网络服务network.service为例:

1、查看服务状态

systemctl status network.service

2、控制服务

启动服务
systemctl start network.service
重启服务 systemctl restart network.service
停止服务 systemctl stop network.service

开机启动服务
systemctl enable network.servic

停止开机启动
systemctl disable network.servic

3、查找所有或者某个服务

systemctl list-units --type=service | grep network

4、Systemctl接受服务(.service),挂载点(.mount),套接口(.socket)和设备(.device)作为单元。

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

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

列出所有失败单元
systemctl --failed

5、使用systemctl命令杀死服务

systemctl kill network.service

6、列出所有系统挂载点

systemctl list-unit-files --type=mount

    UNIT FILE                     STATE   
    dev-hugepages.mount           static  
    dev-mqueue.mount              static  
    proc-sys-fs-binfmt_misc.mount static  
    sys-fs-fuse-connections.mount static  
    sys-kernel-config.mount       static  
    sys-kernel-debug.mount        static  
    tmp.mount                     disabled

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

systemctl start tmp.mount
systemctl stop tmp.mount
systemctl restart tmp.mount
systemctl reload tmp.mount
systemctl status tmp.mount