CentOS 7下systemd管理的详解

2020-01-30 16:47:36王冬梅

What=debugfs

Where=/sys/kernel/debug

Type=debugfs

这个配置单元文件定义了一个挂载点。挂载配置单元文件有一个[Mount]配置小节,里面配置了 What,Where 和Type 三个数据项。这都是挂载命令所必须的,例子中的配置等同于下面这个挂载命令:

mount –t debugfs /sys/kernel/debug debugfs

Systemd系统管理:

systemd 的主要命令行工具是 systemctl。

多数管理员应该都已经非常熟悉系统服务和 init 系统的管理,比如 service、chkconfig以及 telinit 命令的使用。systemd 也完成同样的管理任务,只是命令工具systemctl 的语法有所不同而已。

启动服务

systemctl start httpd.service 如图1:

停止服务

systemctl stop httpd.service  如图2:

重启服务

systemctl restarthttpd.service  如图3:

重载服务

systemctl reloadhttpd.service

条件式重启

systemctl condrestarthttpd.service

状态查看

systemctl statushttpd.service

列出可以启动或停止的服务列表。

systemctl list-unit-files –type=service

设置服务为开机启动

chkconfig httpd on

systemctl enablehttpd.service

取消服务开机启动;

systemctl disablehttpd.service

检查一个服务在当前环境下被配置为启用还是禁用。

systemctl is-enabledhttpd.service;echo $?

输出在各个运行级别下服务的启用和禁用情况

systemctl list-unit-files –type=service

列出某服务在哪些运行级别下启用和禁用。

ls /etc/lib/systemd/system/*.wants/httpd.service

改变用户运行级别:

systemctl isolatemulti-user.target

multi-user.target   ==  第3运行级别

graphical.target    ==  第5运行级别

runlevel3.target 符号链接,指向multi-user.target

runlevel5.target 符号链接,指向graphical.target

改变默认运行级别:

[root@kalaguiyinsystem]# systemctl set-default multi-user.target 

rm'/etc/systemd/system/default.target'

ln -s'/usr/lib/systemd/system/multi-user.target''/etc/systemd/system/default.target'

上述操作的实质是删除/usr/lib/systemd/system/default.target,然后将目标级别的target文件链接至/etc/systemd/system/default.target文件;

systemd 已经不仅仅是一个初始化系统了: