一、简介
systemd是linux系统中的一个系统和服务管理工具,它被设计为向后兼容 SysV init scripts。该机制全部只有一个systemd服务和一个systemctl管理工具,定义每一个服务为一个服务单位(unit),并将该unit归属到不同的服务类型(type)。
二、 Systemd Unit 类型简介
Unit Type | File Extension | Description |
---|---|---|
Service unit | .service | A system service . |
Target unit | .target | A group of systemd units . |
Automount unit | .automount | A file system automount point . |
Device unit | .device | A device file recognized by the kernel . |
Mount unit | .mount | A file system mount point . |
Path unit | .path | A file or directory in a file system . |
Scope unit | .scope | An externally created process . |
Slice unit | .slice | A group of hierarchically organized units that manage system processes . |
Snapshot unit | .snapshot | A saved state of the systemd manager . |
Socket unit | .socket | An inter-process communication socket . |
Swap unit | .swap | A swap device or a swap file . |
Timer unit | .timer | A systemd timer . |
也可以使用命令 systemctl -t help 查看
[root@master01 ~]# systemctl -t help
Available unit types:
service
socket
busname
target
snapshot
device
mount
automount
swap
timer
path
slice
scope
[root@master01 ~]#
三、Systemd Unit 文件位置
Directory | Description |
---|---|
/usr/lib/systemd/system/ | Systemd unit files distributed with installed RPM packages. |
/run/systemd/system/ | Systemd unit files created at run time. This directory takes precedence over the directory with installed service unit files. |
/etc/systemd/system/ | Systemd unit files created by systemctl enable as well as unit files added for extending a service. This directory takes precedence over the directory with runtime unit files. |
- 1、/usr/lib/systemd/system/,在使用CentOS官方提供的软件安装后,默认的启动脚本配置文件都会存放在这里,这里的文件一般不要修改,如果需要修改,请到 /etc/systemd/system/ 目录下复制一份新的并修改。比如我要修改httpd service,步骤如下:
1、复制 httpd unit 文件到/etc/systemd/system/ 目录下
cp /usr/lib/systemd/system/httpd.service /etc/systemd/system/httpd.service
2、打开/etc/systemd/system/httpd.service文件,并修改对应的配置项
3、重载配置文件,使其生效,并查看
systemctl daemon-reload
systemctl show httpd -p TimeoutStartUSec
- 2、/run/systemd/system/ 系统运行的过程中产生的脚本名,这些脚本的优先级要比/usr/lib/systemd/system/高
- 3、/etc/systemd/system/ 对于原有的unit 文件的扩展以及修改会存放在这个路径下,执行优先级又比/run/systemd/system/高
四、systemd服务本身的配置文件
systemd服务本身的默认配置文件在/etc/systemd/system.conf,在这个文件中可以设置一些默认的属性值。