我将ntp.conf
文件更改为从设备读取时间:
server 127.127.8.0 mode 2 # standard time from device
server 127.127.1.0 # local clock
fudge 127.127.1.0 stratum 12
设备文件是文件/dev/refclock-0
的链接/dev/mbgclock
。问题是当我运行 ntp 守护进程时,我观察到它的状态:
PARSE receiver #0: parse_start: open of /dev/refclock-0 failed: Permission denied
我将权限更改refclock-0
为 777 (我知道它很脏,只是为了测试)并将该行添加User=root
到 ntp 启动脚本,但错误仍然存在!我该如何解决?这是文件/usr/lib/systemd/system/ntpd.service
[Unit]
Description=Network Time Service
After=syslog.target ntpdate.service sntp.service
[Service]
User=root
Type=forking
EnvironmentFile=-/etc/sysconfig/ntpd
ExecStart=/usr/sbin/ntpd -u ntp:ntp $OPTIONS
PrivateTmp=true
[Install]
WantedBy=multi-user.target
这是 ntpd 服务的状态:
● ntpd.service - Network Time Service
Loaded: loaded (/usr/lib/systemd/system/ntpd.service; enabled; vendor preset: disabled)
Active: active (running) since Tue 2018-09-04 17:09:08 +0430; 16h ago
Process: 5741 ExecStart=/usr/sbin/ntpd -u ntp:ntp $OPTIONS (code=exited, status=0/SUCCESS)
Main PID: 5742 (ntpd)
CGroup: /system.slice/ntpd.service
└─5742 /usr/sbin/ntpd -u ntp:ntp -g
Sep 04 17:09:08 hardware ntpd[5742]: Listen normally on 2 lo 127.0.0.1 UDP 123
Sep 04 17:09:08 hardware ntpd[5742]: Listen normally on 3 enp3s0 192.168.1.60 UDP 123
Sep 04 17:09:08 hardware ntpd[5742]: Listen normally on 4 lo ::1 UDP 123
Sep 04 17:09:08 hardware ntpd[5742]: Listen normally on 5 enp3s0 fe80::7895:667b:cec:9b2 UDP 123
Sep 04 17:09:08 hardware ntpd[5742]: Listening on routing socket on fd #22 for interface updates
Sep 04 17:09:08 hardware ntpd[5742]: PARSE receiver #0: parse_start: open of /dev/refclock-0 failed: Permission denied
Sep 04 17:09:08 hardware ntpd[5742]: 127.127.8.0 interface 127.0.0.1 -> (none)
Sep 04 17:09:08 hardware ntpd[5742]: 0.0.0.0 c016 06 restart
Sep 04 17:09:08 hardware ntpd[5742]: 0.0.0.0 c012 02 freq_set kernel -9.533 PPM
Sep 04 17:09:10 hardware ntpd[5742]: 0.0.0.0 c515 05 clock_sync
ntp
默认情况下在 apparmor 隔离下运行。因此,对于 99% 的情况,您将被 apparmor Deny 阻止 - 检查 dmesg 输出。由于 refclocks 有很多潜在的名称,因此配置文件不能仅仅允许
/dev/*
,特别是因为大多数用户不使用 refclocks。因此配置文件已经有一个可调文件
/etc/apparmor.d/tunables/ntpd
:对于您的情况,以下内容应使其通过此阶段: