大网数据广告活动
服务器运维问答

ntpd: permission denied writing to /var/log/ntpstats/ (statsdir directory)

· 52CE 我爱测

I am running a NTP server on an Ubuntu 20.04 LTS. The server work fine and the client poll correctly the server. But i keep getting a permission error when i want to record statistics. I tried to include the following lines in nt…

问题原文

原帖链接 · molik · CC BY-SA 4.0

I am running a NTP server on an Ubuntu 20.04 LTS. The server work fine and the client poll correctly the server. But i keep getting a permission error when i want to record statistics.

I tried to include the following lines in ntp.conf :

statistics rawstats
statsdir /var/log/ntpstats/
filegen rawstats file raw type day link enable

When looking at systemctl ntp status :

mars 05 09:08:48 RD-NTP ntpd[3534] : can't open /var/log/ntpstats/raw.20210305: Permission denied
mars 05 09:08:50 RD-NTP ntpd[3534] : can't open /var/log/ntpstats/raw.20210305: Permission denied
mars 05 09:08:52 RD-NTP ntpd[3534] : can't open /var/log/ntpstats/raw.20210305: Permission denied
mars 05 09:08:54 RD-NTP ntpd[3534] : can't open /var/log/ntpstats/raw.20210305: Permission denied

But for me, the directory have the correct permissions ls -al :

drwxr-xr-x 2 ntp ntp 4096 april 2 2020 .

Before choosing the default folder, i tried with one i created and adding ntp in the permission using this command : chmod ntp:ntp /home/ubuntu/ntpstats/, it wasnt working so i switched to this one, not working either.

Do you know why ntpd keep getting error even if ntp have the upper hand on the folder ?

已采纳解答

原帖链接 · Paul Gear · CC BY-SA 4.0

It's very likely that what is causing your permissions issue is not permissions bits, but AppArmor. The default AppArmor profile for ntpd on Ubuntu 20.04 (/etc/apparmor.d/usr.sbin.ntpd) contains:

...
/var/log/ntp w,
/var/log/ntp.log w,
/var/log/ntpd w,
/var/log/ntpstats/clockstats* rwl,
/var/log/ntpstats/loopstats*  rwl,
/var/log/ntpstats/peerstats*  rwl,
/var/log/ntpstats/protostats* rwl,
/var/log/ntpstats/rawstats*   rwl,
/var/log/ntpstats/sysstats*   rwl,
...

Note the mismatch in the filename it is expecting compared with the one ntpd is generating. If you change the AppArmor profile line referencing rawstats to be:

/var/log/ntpstats/raw*   rwl,

and reload AppArmor with systemctl reload apparmor, your stats logging will likely work.

Note also that loopstats and peerstats are more likely to be helpful in diagnosing NTP problems than rawstats. (See http://doc.ntp.org/current-stable/monopt.html#types for more on this.) Personally, I think if you're going to bother logging rawstats, you'd be better to just capture every NTP packet on the wire and process it with wireshark or a similar protocol analyser.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2021-03-03)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。