环境说明

  • Ubuntu 21.10

问题说明

有个接口报错,debug后是服务器时间跟接口服务器时间对不上,然该服走代理使用ntpdate时间同步报错

14 Mar 13:18:32 ntpdate[2101582]: no server suitable for synchronization found

关闭代理又正常,然服务代理不能关。

步骤说明

ntpdate 时间同步

安装

apt-get install ntpdate

与网络服务器同步时间
ntpdate cn.pool.ntp.org

htpdate 时间同步

因ntp同步失败,使用htpdate进行同步

安装
  • 编译安装:

    git clone https://github.com/iridium77/htpdate
    make && make install
  • apt-get install htpdate

同步
htpdate -t -s cn.pool.ntp.org

配置定时同步

crontab -e

0 3 * * * /usr/sbin/htpdate -t -s cn.pool.ntp.org

参数详细

htpdate -h

htpdate version 1.2.2
Usage: htpdate [-046abdhlqstxD] [-i pid file] [-m minpoll] [-M maxpoll]
[-p precision] [-P <proxyserver>[:port]] [-u user[:group]]
<host[:port]> ...

-0 HTTP/1.0 request
-4 Force IPv4 name resolution only
-6 Force IPv6 name resolution only
-a adjust time smoothly
-b burst mode
-d debug mode
-D daemon mode
-h help
-i pid file
-l use syslog for output
-m minimum poll interval
-M maximum poll interval
-p precision (ms)
-P proxy server
-q query only, don't make time changes (default)
-s set time
-t turn off sanity time check
-u run daemon as user
-x adjust kernel clock
host web server hostname or ip address (maximum of 16)
port port number (default 80 and 8080 for proxy server)

问题解决

配置netpaln有遇到报错

root@axinblog:/etc/netplan# vim 00-installer-config.yaml
root@axinblog:/etc/netplan# netplan apply

** (generate:2184865): WARNING **: 13:28:38.017: `gateway4` has been deprecated, use default routes instead.
See the 'Default routes' section of the documentation for more details.

参考

netplan generate: gateway4 已被弃用,改用默认路由

Netplan configuration examples

解决

vim /etc/netplan/00-installer-config.yaml

#gateway4: 192.168.1.1

改为如下
routes:
- to: default
via: 192.168.1.1

应用

netplan apply

参考文献

ntpdate:没有找到适合于同步的服务器