systemd

1. 背景

首先,我们先看一下/etc/init.d/README内容:

You are looking for the traditional init scripts in /etc/rc.d/init.d,
and they are gone?

Here's an explanation on what's going on:

You are running a systemd-based OS where traditional init scripts have
been replaced by native systemd services files. Service files provide
very similar functionality to init scripts. To make use of service
files simply invoke "systemctl", which will output a list of all
currently running services (and other units). Use "systemctl
list-unit-files" to get a listing of all known unit files, including
stopped, disabled and masked ones. Use "systemctl start
foobar.service" and "systemctl stop foobar.service" to start or stop a
service, respectively. For further details, please refer to
systemctl(1).

Note that traditional init scripts continue to function on a systemd
system. An init script /etc/rc.d/init.d/foobar is implicitly mapped
into a service unit foobar.service during system initialization.

根据上面的解释,目前RED HAT 7, Centos 7等都采用systemd方式来作为系统初始化工具.

2. 为何替换使用systemd

  • systemd通过并行启动服务来加速系统启动时间;
  • systemd使用Cgroup可以更好的管理程序,同时也能控制执行环境;
  • systemd通过结合journald达到更好的日志机制,这种日志方式在Red Hat Enterprise Linux 7中引入;
  • systemd可以处理系统配置动态调整;

3. systemd深入

systemd管理服务,这些服务的定义通过unit files

unit file

Unit file存放在如下几个目录里面,systemd以如下的顺序来读取unit files
/etc/systemd/system
/run/systemd/system
/usr/lib/systemd/system

同样,systemd可以针对用户上下文下设置unit files,路径如下:
/etc/systemd/user
/run/systemd/user
/usr/lib/systemd/user

查看系统所有的unit files
systemd list-unit-files

unit files 分为servicetarget两类

systemctl list-unit-files --type service
systemctl list-unit-files --type target

1. 启动或暂时停用

systemctl start serviceX
systemctl stop serviceX

2. 设置服务自启动或者剔除自启动

systemctl enable serviceX
systemctl disable serviceX

3. 查看服务的依赖

systemctl list-dependencies serviceX

4. 终极停用或者撤销终极停用

systemctl mask serviceX
systemctl unmask serviceX

你可能感兴趣的:(Linux)