Centos7系统服务管理

systemd是RH7系列操作系统开始启用新的系统和服务管理器。

systemd中引入了system units的概念,在units其中封装有关系统服务(service),侦听套接字(socket),以及与init系统启动相关信息

systemd unit 类型

unit类型      |   文件后缀名   |   描述
Service unit    |   .service    |   服务类
Target unit     |   .target     |   一个unit服务组,用于模拟实现运行级别
Automount unit  |  .automount   |   文件系统自动挂载点
Device unit     |   .device     |   内核识别的设备文件
Mount unit      |   .mount      |   文件系统挂载点
Path unit       |   .path       |   文件或目录
Scope unit      |   .scope      |   外部创建的进程
Slice unit      |   .slice      |   A group of hierarchically organized units that manage system processes.
Snapshot unit   |   .snapshot   |   系统快照
Socket unit     |   .socket     |   套接字
Swap unit       |   .swap       |   标识swap设备
Timer unit      |   .timer      |   systemd的计时器

unit文件保存位置

/usr/lib/systemd/system/    |   RPM包安装时分发的unit文件
/run/systemd/system/        |   systemd运行时创建的文件
/etc/systemd/system/        |   systemctl enable创建的unit文件

 

service和systemctl

service                         |   systemctl                                   |   
service name start              |   systemctl start name.service                |   启动服务
service name stop               |   systemctl stop name.service                 |   停止服务
service name restart            |   systemctl restart name.service              |   重启服务(没启动的服务会启动)
service name condrestart        |   systemctl try-restart name.service          |   只重启正在运行的服务
service name reload             |   systemctl reload name.service               |   重载配置文件
service name status             |   systemctl status name.service               |   检查服务状态
service name status             |   systemctl is-active name.service            |   检查服务是否启动
service --status-all            |   systemctl list-units --type service --all   |   显示所有的服务状态

chkconfig和systemctl

chkconfig               |   systemctl                                   |   
chkconfig name on       |   systemctl enable name.service               |   启用开机自启服务
chkconfig name off      |   systemctl disable name.service              |   停用自启服务
chkconfig --list name   |   systemctl status name.service               |   检查服务状态
chkconfig --list name   |   systemctl is-enabled name.service           |   查看服务是否自启
chkconfig --list        |   systemctl list-unit-files --type service    |   查看所有服务
chkconfig --list        |   systemctl list-dependencies --after         |   列出在指定服务之前启动的服务.(依赖)
chkconfig --list        |   systemctl list-dependencies --before        |   列出在指定服务之后启动的服务.(被依赖)

2, 服务状态信息

Loaded      |   关于服务是否已经加载的信息,文件的绝对路径以及是否被启用的注释。
Active      |   服务是否正在运行,然后是启动时间信息
Main PID    |   服务主进程pid
Docs        |   服务的帮助文档(man)
Status      |   系统服务的额外信息
Process     |   进程额外信息
CGroup      |   Control Groups额外信息

3, 常用命令(start,stop,这些常用命令就不说明了)

     列出所有当前激活服务

systemctl list-units --type service

   列出所有服务,不管是否激活(LOAD为notfound应该是还没有安装)

systemctl list-units --type service --all

   列出可开机自启的服务

systemctl list-unit-files --type service

  重新加载服务: 一个服务设置为开机启动使用enable会将/usr/lib/systemd/system/name.service软链接到/etc/systemd/system/.但是enable命令不会重写已经存在的链接,所以当我们修改了服务文件就需要重新加载

systemctl reenable name.service

   禁用服务 mask会将 /etc/systemd/system/name.service软链接到/dev/null.从而禁止服务启用.反操作unmask

systemctl mask name.service

   显示服务属性信息

systemctl show auditd

   服务的依赖关系

systemctl list-dependencies chronyd.service

   结束服务

systemctl kill name.service
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值