systemctl
http://www.cnblogs.com/LiuYanYGZ/p/5458440.html
使用了 Systemd,就不需要再用init
了。Systemd 取代了initd
,成为系统的第一个进程(PID 等于 1),其他进程都是它的子进程。
$ systemctl --version
上面的命令查看 Systemd 的版本。
它与init
进程的主要差别如下。
(1)默认的 RunLevel(在
/etc/inittab
文件设置)现在被默认的 Target 取代,位置是/etc/systemd/system/default.target
,通常符号链接到graphical.target
(图形界面)或者multi-user.target
(多用户命令行)。(2)启动脚本的位置,以前是
/etc/init.d
目录,符号链接到不同的 RunLevel 目录 (比如/etc/rc3.d
、/etc/rc5.d
等),现在则存放在/lib/systemd/system
和/etc/systemd/system
目录。(3)配置文件的位置,以前
init
进程的配置文件是/etc/inittab
,各种服务的配置文件存放在/etc/sysconfig
目录。现在的配置文件主要存放在/lib/systemd
目录,在/etc/systemd
目录里面的修改可以覆盖原始设置
Systemd 的优点是功能强大,使用方便,缺点是体系庞大,非常复杂。事实上,现在还有很多人反对使用 Systemd,理由就是它过于复杂,与操作系统的其他部分强耦合,违反"keep simple, keep stupid"的Unix 哲学。
whereis systemd whereis systemctl #检查systemd和systemctl的二进制文件和库文件的安装位置
ps -aef |grep systemd #检查systemd进程信息
systemd-analyze #分析systemd启动进程
systemd-analyze blame #分析启动时各个进程花费的时间
systemd-analyze critical-chain #分析启动时的关键链
systemd-cgls #按等级列出控制组
systemd-cgtop #按CPU、内存、输入和输出列出控制组
systemctl list-unit-files --type=target|service|mount
systemctl --failed
systemctl is-enabled|is-active|is-failed|stop|start|restart|reload|status|kill|enable|disable|show|mask|unmask#如何激活服务并在启动时启用或禁用服务(即系统启动时自动启动服务
如何屏蔽(让它不能启动)或显示服务(如 httpd.service)
# systemctl mask httpd.service
ln -s '/dev/null''/etc/systemd/system/httpd.service'
# systemctl unmask httpd.service
rm '/etc/systemd/system/httpd.service'
systemctl list-dependencies httpd.service #获取某个服务(httpd)的依赖性列表
systemctl get-default #列出当前使用的运行等级
systemctl isolate runlevel3.target or systemctl isolate multiuser.target #启动运行等级3,即多用户模式
sytemctl set-default runlevel5.target or systemctl set-default graphical.target #设置多用户模式或图形模式为默认运行等级
systemctl rescue #启动系统救援模式
37. 重启、停止、挂起、休眠系统或使系统进入混合睡眠
# systemctl reboot
# systemctl halt
# systemctl suspend
# systemctl hibernate
# systemctl hybrid-sleep
对于不知运行等级为何物的人,说明如下。
- Runlevel 0 : 关闭系统
- Runlevel 1 : 救援?维护模式
- Runlevel 3 : 多用户,无图形系统
- Runlevel 4 : 多用户,无图形系统
- Runlevel 5 : 多用户,图形化系统
- Runlevel 6 : 关闭并重启机器