我更改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
答案1
ntp
默认情况下,在 apparmor 隔离下运行。因此,99% 的情况下,您将被 apparmor Deny 阻止 - 检查 dmesg 输出。
由于参考时钟有太多潜在名称,因此配置文件不能仅仅允许,/dev/*
特别是因为大多数用户不使用参考时钟。
因此该配置文件已经有一个可调文件/etc/apparmor.d/tunables/ntpd
::
#Add your ntpd devices here eg. if you have a DCF clock
# @{NTPD_DEVICE}="/dev/ttyS1"
@{NTPD_DEVICE}="/dev/null"
对于您的情况,以下内容应该可以使其通过此阶段:
@{NTPD_DEVICE}="refclock-0"