我已经设置了 name 来使用 chroot,例如 Fedora 和 RockyLinux (-t /var/named/chroot)。守护进程工作正常,只有一个小问题...单元启动,但 systemd 将其标记为失败!
root@dns1:~# systemctl start named&
[1] 6158
root@dns1:~#
root@dns1:~# pgrep -a named
6152 /usr/sbin/named -f -u bind -t /var/named/chroot -4 -c /etc/named.conf
两分钟后..
root@dns1:~# jobs
[1]+ Running systemctl start named &
root@dns1:~# Job for named.service failed because a timeout was exceeded.
See "systemctl status named.service" and "journalctl -xeu named.service" for details.
系统被标记为“正在激活”
systemctl status named
● named.service - BIND Domain Name Server
Loaded: loaded (/lib/systemd/system/named.service; enabled; preset: enabled)
Drop-In: /run/systemd/system/service.d
└─zzz-lxc-service.conf
Active: activating (start) since Mon 2023-10-30 16:45:58 CET; 31s ago
Docs: man:named(8)
Main PID: 6165 (named)
Memory: 9.2M
CGroup: /system.slice/named.service
└─6165 /usr/sbin/named -f -u bind -t /var/named/chroot -4 -c /etc/named.conf
这是单位
cat named.service
[Unit]
Description=BIND Domain Name Server
Documentation=man:named(8)
After=network.target
Wants=nss-lookup.target
Before=nss-lookup.target
[Service]
Type=notify
EnvironmentFile=-/etc/default/named
ExecStart=/usr/sbin/named -f $OPTIONS
ExecReload=/usr/sbin/rndc reload
ExecStop=/usr/sbin/rndc stop
Restart=on-failure
[Install]
WantedBy=multi-user.target
Alias=bind9.service
答案1
Type=notify
啊,这是行不通的——如果你让 BIND9 将自己放入 chroot,它就无法访问让 systemd 知道它已经启动所需的套接字。
rocky 8.7 通过将 放入options {directory "/var/named"}
配置文件而不是命令行,并在那里明确声明 pidfiles 来解决这个问题。还是没用notify
,但是forking
。
答案2
找到了解决方案,使用这个简单的语法就可以正常工作
vim 命名服务
[Unit]
Description=BIND Domain Name Server
Documentation=man:named(8)
After=network.target
Wants=nss-lookup.target
Before=nss-lookup.target
[Service]
ExecStart=/usr/sbin/named -f -u named -t /var/named/chroot -u bind -c /etc/named.conf
ExecReload=/usr/sbin/rndc reload
[Install]
WantedBy=multi-user.target
Alias=bind9.service
然后我重新启动
systemctl daemon-reload
systemctl restart named
工作正常,重新启动并重新加载
systemctl status named
● named.service - BIND Domain Name Server
Loaded: loaded (/lib/systemd/system/named.service; enabled; preset: enabled)
Drop-In: /run/systemd/system/service.d
└─zzz-lxc-service.conf
Active: active (running) since Mon 2023-10-30 19:43:58 CET; 1min 16s ago
Docs: man:named(8)
Main PID: 7218 (named)
Memory: 9.5M
CGroup: /system.slice/named.service
└─7218 /usr/sbin/named -f -u named -t /var/named/chroot -u bind -c /etc/named.conf