systemd 配置文件在哪里?

kar*_*hik 8 rhel systemd

如何在特定目标中启用特定单位?启用后,配置存储在哪里?

Joh*_*ith 8

正如 Hauke Laging 所说,systemctl enable ...将打印出有关正在执行的操作的信息。例如,在我的 Arch 系统上,如果我dhcpd在界面上启用服务enp0s3......

$ systemctl enable dhcpcd@enp0s3
Created symlink from /etc/systemd/system/multi-user.target.wants/dhcpcd@enp0s3.service
to /usr/lib/systemd/system/dhcpcd@.service
Run Code Online (Sandbox Code Playgroud)

禁用此服务时,您可以看到systemctl删除了之前的链接...

$ systemctl disable dhcpcd@enp0s3
Removed symlink /etc/systemd/system/multi-user.target.wants/dhcpcd@enp0s3.service
Run Code Online (Sandbox Code Playgroud)

所以,从这个输出中,你可以看出......

  • 调用时systemctl enable,会在 下创建符号链接/etc/systemd/system/multi-user.target.wants
  • 调用时systemctl disable,这个符号链接将被删除。

因此,如果您想获得已启用服务的列表(我想您称之为“配置”),您所要做的就是列出这些链接:

ls /etc/systemd/system/multi-user.target.wants
Run Code Online (Sandbox Code Playgroud)

但是,您可能会使用 找到更多信息systemctl list-unit-files,它将列出所有可用服务及其状态(启用、禁用、静态)。/etc/systemd/system根据它们所属的单位,您会看到启用的那些在 下某处有一个链接。

$ find /etc/systemd/system -type l
Run Code Online (Sandbox Code Playgroud)

虽然某些发行版的目录可能会更改,但它们是systemd(以及之前的其他系统)处理其设置的方式。虽然/etc/systemd包含多个配置文件,但单元特定的设置是通过链接处理的。对我来说,这种方法比文件更实用,因为它允许开发人员随包一起提供单元(安装在 下/usr/lib/systemd/system),但仍将控制权交给管理员,管理员可以决定在系统上安排哪些单元.

如果您有兴趣,Arch Wiki 实际上提供了对systemd. RHEL在他们的文档中也有一些关于它的信息