RHEL7 -- systemd
2015-07-15 22:09 abce 阅读(825) 评论(0) 编辑 收藏 举报systemd 在RHEL7中,进程ID 1属于systemd这个新的进程。(代替之前版本中的init)
systemd提供了以下新功能:
·并行化功能,可以提高系统的启动速度
·按需启动守护进程,而不需要单独的服务
·自动服务依赖关系管理,可以防止长时间超时,例如在网络不可用时不启动网络服务
·利用linux控制组一起追踪相关进程
有了systmed以后,基于shell的服务脚本基本仅用于几个传统服务。因此,带有shell变量的配置文件将被取代,如/etc/sysconfig中可以找到的配置文件。 仍然在使用的配置文件作为systemd环境文件被纳入,并作为NAME=VALUE对进行读取。他们不再以shell脚本的形式提供。
systemctl和systemd单元
systemctl命令管理各种类型systemd对象,他们称为单元。可以通过systemctl -t help命令显示可用单元类型的列表
# systemctl -t help
Available unit types:
service
socket
target
device
mount
automount
snapshot
timer
swap
path
slice
scope
-服务单元具有.service扩展名,代表系统服务
-套接字单元具有.socket扩展名,代表进程间通信套接字
-路径单元具有.path扩展名,用于将服务的激活推迟到特定文件系统更改发生之后。
查看服务状态:
使用systemctl status name.type查看服务状态(取代了旧版中的service NAME status命令 )
[root@rhce7 ~]# systemctl status network.service network.service - LSB: Bring up/down networking Loaded: loaded (/etc/rc.d/init.d/network) Active: active (exited) since Thu 2015-07-16 11:24:20 CST; 1h 22min ago Process: 932 ExecStart=/etc/rc.d/init.d/network start (code=exited, status=0/SUCCESS) Jul 16 11:24:17 rhce7.example.com systemd[1]: Starting LSB: Bring up/down networking... Jul 16 11:24:18 rhce7.example.com network[932]: Bringing up loopback interface: Could not load file '/etc/sysconfig/networ...fg-lo' Jul 16 11:24:18 rhce7.example.com network[932]: Could not load file '/etc/sysconfig/network-scripts/ifcfg-lo' Jul 16 11:24:19 rhce7.example.com network[932]: Could not load file '/etc/sysconfig/network-scripts/ifcfg-lo' Jul 16 11:24:19 rhce7.example.com network[932]: Could not load file '/etc/sysconfig/network-scripts/ifcfg-lo' Jul 16 11:24:19 rhce7.example.com network[932]: [ OK ] Jul 16 11:24:19 rhce7.example.com network[932]: Bringing up interface Profile_1: [ OK ] Jul 16 11:24:19 rhce7.example.com network[932]: Bringing up interface enp0s17: [ OK ] Jul 16 11:24:20 rhce7.example.com network[932]: Bringing up interface enp0s8: [ OK ] Jul 16 11:24:20 rhce7.example.com systemd[1]: Started LSB: Bring up/down networking. Hint: Some lines were ellipsized, use -l to show in full. [root@rhce7 ~]#
如果没有指定type,即未提供单元类型,则systemctl将显示服务单元的状态(如果存在)
[root@rhce7 ~]# systemctl status session-3 session-3.service Loaded: not-found (Reason: No such file or directory) Active: inactive (dead) [root@rhce7 ~]# systemctl status session-3.scope session-3.scope - Session 3 of user root Loaded: loaded (/run/systemd/system/session-3.scope; static) Drop-In: /run/systemd/system/session-3.scope.d └─90-After-systemd-logind\x2eservice.conf, 90-After-systemd-user-sessions\x2eservice.conf, 90-Description.conf, 90-SendSIGHUP.conf, 90-Slice.conf Active: active (running) since Thu 2015-07-16 11:44:05 CST; 1h 5min ago CGroup: /user.slice/user-0.slice/session-3.scope ├─3002 sshd: root@pts/0 ├─3009 -bash └─4057 systemctl status session-3.scope Jul 16 11:44:05 rhce7.example.com systemd[1]: Starting Session 3 of user root. Jul 16 11:44:05 rhce7.example.com systemd[1]: Started Session 3 of user root. Jul 16 11:44:05 rhce7.example.com sshd[3002]: pam_unix(sshd:session): session opened for user root by (uid=0) [root@rhce7 ~]# systemctl status network network.service - LSB: Bring up/down networking Loaded: loaded (/etc/rc.d/init.d/network) Active: active (exited) since Thu 2015-07-16 11:24:20 CST; 1h 25min ago Process: 932 ExecStart=/etc/rc.d/init.d/network start (code=exited, status=0/SUCCESS) Jul 16 11:24:17 rhce7.example.com systemd[1]: Starting LSB: Bring up/down networking... Jul 16 11:24:18 rhce7.example.com network[932]: Bringing up loopback interface: Could not load file '/etc/sysconfig/networ...fg-lo' Jul 16 11:24:18 rhce7.example.com network[932]: Could not load file '/etc/sysconfig/network-scripts/ifcfg-lo' Jul 16 11:24:19 rhce7.example.com network[932]: Could not load file '/etc/sysconfig/network-scripts/ifcfg-lo' Jul 16 11:24:19 rhce7.example.com network[932]: Could not load file '/etc/sysconfig/network-scripts/ifcfg-lo' Jul 16 11:24:19 rhce7.example.com network[932]: [ OK ] Jul 16 11:24:19 rhce7.example.com network[932]: Bringing up interface Profile_1: [ OK ] Jul 16 11:24:19 rhce7.example.com network[932]: Bringing up interface enp0s17: [ OK ] Jul 16 11:24:20 rhce7.example.com network[932]: Bringing up interface enp0s8: [ OK ] Jul 16 11:24:20 rhce7.example.com systemd[1]: Started LSB: Bring up/down networking. Hint: Some lines were ellipsized, use -l to show in full. [root@rhce7 ~]#
服务状态表示的关键字说明
关键字 | 说明 |
loaded | 单元配置文件已经处理 |
active(running) | 正在通过一个或多个持续进程运行 |
active(exited) | 已成功文成一次性配置 |
active(waiting) | 运行中,正在等待事件 |
inactive | 不在运行 |
enabled | 开机自启动 |
disabled | 开机不会自启动 |
static | 无法启用,但可以由某一启动的单元自动启动 |