AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / ubuntu / 问题 / 1373918
Accepted
Zach
Zach
Asked: 2021-11-07 04:01:25 +0800 CST2021-11-07 04:01:25 +0800 CST 2021-11-07 04:01:25 +0800 CST

未使用 NTP 配置

  • 772

我正在尝试在运行 Ubuntu 20.04(无头)的 SBC 上设置 GPS NTP 服务器,但我遇到了配置问题。当我重新启动时,我得到了这个:

$ ntpq -p

     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
*_gateway        163.237.218.18   2 u   22   64    1    2.727    0.011   0.159

/etc/ntp.conf 说:

pool 1.ubuntu.pool.ntp.org iburst
pool 2.ubuntu.pool.ntp.org iburst
pool 3.ubuntu.pool.ntp.org iburst

# Use Ubuntu's ntp server as a fallback.
#pool ntp.ubuntu.com

# Access control configuration; see /usr/share/doc/ntp-doc/html/accopt.html for
# details.  The web page <http://support.ntp.org/bin/view/Support/AccessRestrictions>
# might also be helpful.
#
# Note that "restrict" applies to both servers and clients, so a configuration
# that might be intended to block requests from certain clients could also end
# up blocking replies from your own upstream servers.

# By default, exchange time with everybody, but don't allow configuration.
restrict -4 default kod notrap nomodify nopeer noquery limited
restrict -6 default kod notrap nomodify nopeer noquery limited

# Local users may interrogate the ntp server more closely.
restrict 127.0.0.1
restrict ::1

# Needed for adding pool entries
restrict source notrap nomodify noquery

# Clients from this (example!) subnet have unlimited access, but only if
# cryptographically authenticated.
#restrict 192.168.123.0 mask 255.255.255.0 notrust


# If you want to provide time to your local subnet, change the next line.
# (Again, the address is an example only.)
#broadcast 192.168.123.255

# If you want to listen to time broadcasts on your local subnet, de-comment the
# next lines.  Please do this only if you trust everybody on the network!
#disable auth
#broadcastclient

# GPS Serial data reference
server 127.127.28.0 minpoll 4 maxpoll 4
fudge 127.127.28.0 time1 0.0 refid GPS

# GPS PPS reference
server 127.127.28.1 minpoll 4 maxpoll 4 prefer
fudge 127.127.28.1 refid PPS

/etc/ntp/step-tickers
为空白

我在互联网上找到了一个配置,用于制作一个将作为 GPS 时间服务器运行的“设备”,它说要这样做:

$ su -
# killall -9 gpsd ntpd
# gpsd -n /dev/ttyXX
# sleep 2
# ntpd -gN
# sleep 2
# cgps 

那行得通

root@ubuntu:/home/zach# ntpq -p
     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
 0.ubuntu.pool.n .POOL.          16 p    -   64    0    0.000    0.000   0.000
 1.ubuntu.pool.n .POOL.          16 p    -   64    0    0.000    0.000   0.000
 2.ubuntu.pool.n .POOL.          16 p    -   64    0    0.000    0.000   0.000
 3.ubuntu.pool.n .POOL.          16 p    -   64    0    0.000    0.000   0.000
*SHM(0)          .GPS.            0 l    8   16    1    0.000  -40.232   0.000
 SHM(1)          .PPS.            0 l    -   16    0    0.000    0.000   0.000

知道为什么我不能让 ntp 在启动时读取 /etc/ntp.conf 吗?

编辑:我不确定 gpsd 是否在启动时运行。

我做了一个dmesg | grep gps,什么都没出现。

然后,我编写了一个 bash 脚本,其中包含 killall 行。我认为它不会运行(crontab 中的@startup sh),因为它必须被提升。我尝试了 init.d (我真的不知道我在那里做什么)并且我收到一条错误消息 audit: type=1400 audit(1636322022.316:45): apparmor="DENIED" operation="ptrace" profile="/usr/sbin/gpsd" pid=2794 comm="gpsd" requested_mask="read" denied_mask="read" peer="/usr/sbin/ntpd"

webserver
  • 2 2 个回答
  • 357 Views

2 个回答

  • Voted
  1. Best Answer
    Zach
    2021-11-10T18:35:55+08:002021-11-10T18:35:55+08:00

    好的,感谢@ChristianEhrhardt,由于某种我不知道的原因,Chrony 的使用似乎效果很好。

    我已经运行了 gpsd,所以我不必搞砸它,但在这里指出这一点很重要。我使用的是通过 USB 而不是PPS 插入的 GPS。设备是 ttyACM0

    我在互联网上使用了几个指南,我不确定我采取的确切步骤,但它是这样的:

    sudo apt install chrony

    然后我必须配置 .conf 文件

    sudo nano /etc/chrony/chrony.conf

    我发现为了让 GPS 时间服务器真正为其他计算机提供时间,我必须取消注释,如下所示。我有几个子网,所以我把它打开了

    #Allow to be a NTP server 
    allow 192.168.0.0/24
    

    我需要添加我的 GPS 源,所以我添加了:

    #GPS Sources
    refclock SHM 0 refid GPS precision 1e-1 offset 0 delay 0 stratum 2
    refclock SOCK /var/run/chrony.ttyACM0.sock refid PPS
    

    我知道重启服务是一回事,但我更喜欢重启。

    sudo reboot now

    然后我将其作为服务启用

    systemctl enable chrony

    然后我检查以确保它有效

    chronyc sources

    最后,我确认它正在为其他计算机服务。我去了另一台机器并检查了ntpq -p

    和TA-DA

    • 1
  2. crpb
    2021-11-08T12:22:10+08:002021-11-08T12:22:10+08:00

    如果您的服务器通过 DHCP 获取 IP,也可以通过 /var/lib/ntp/ntp.conf.dhcp 设置 ntp 选项。有时我什至有一个来自安装的挥之不去的文件,即使在更改为静态配置后也能保持这种行为。如果是这样,只需将其删除。

    也许这样的服务可以工作/未经测试

    [Unit]
    Description=NTP-GPSD-FIX
    Requires=ntpd.service
    Requires=gpsd.service?
    
    [Service]
    ExecStart=/path/to/a/script/with/the/commands
    
    [Install]
    WantedBy=multi-user.target
    
    • 0

相关问题

  • 设置多个 Intranet 站点

  • 网络开发 - 奇怪的事情

  • 如何将目录和文件权限授予 Web 服务器

  • 如何使用 DRBD 进行整个系统的复制

  • 远程管理服务器?

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    如何运行 .sh 脚本?

    • 16 个回答
  • Marko Smith

    如何安装 .tar.gz(或 .tar.bz2)文件?

    • 14 个回答
  • Marko Smith

    如何列出所有已安装的软件包

    • 24 个回答
  • Marko Smith

    无法锁定管理目录 (/var/lib/dpkg/) 是另一个进程在使用它吗?

    • 25 个回答
  • Martin Hope
    Flimm 如何在没有 sudo 的情况下使用 docker? 2014-06-07 00:17:43 +0800 CST
  • Martin Hope
    Ivan 如何列出所有已安装的软件包 2010-12-17 18:08:49 +0800 CST
  • Martin Hope
    La Ode Adam Saputra 无法锁定管理目录 (/var/lib/dpkg/) 是另一个进程在使用它吗? 2010-11-30 18:12:48 +0800 CST
  • Martin Hope
    David Barry 如何从命令行确定目录(文件夹)的总大小? 2010-08-06 10:20:23 +0800 CST
  • Martin Hope
    jfoucher “以下软件包已被保留:”为什么以及如何解决? 2010-08-01 13:59:22 +0800 CST
  • Martin Hope
    David Ashford 如何删除 PPA? 2010-07-30 01:09:42 +0800 CST

热门标签

10.10 10.04 gnome networking server command-line package-management software-recommendation sound xorg

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve