一、测试环境为:树莓派3B+
pi@raspberrypi:~/workfile/lorawan/lorawan-gw $ uname -a
Linux raspberrypi 6.1.21-v7+ #1642 SMP Mon Apr 3 17:20:52 BST 2023 armv7l GNU/Linux
测试过程中,请确保树莓派连接网络 ;
二、安装ntp相关命令,并设置时区
step 1 :安装 ntp 和 ntpdate 命令
sudo apt install ntp sudo apt install ntpdate
step2 :修改本地时区,输入指令 : sudo dpkg-reconfigure tzdata
pi@raspberrypi:~ $ sudo dpkg-reconfigure tzdata
select "Asia"
按回车键,select "Shanghai"
按回车健,确定即可;
step3 : 重启ntp服务器
sudo /etc/init.d/ntp restart
step4 : 自动同步时间
pi@raspberrypi:~ $ sudo systemctl status ntp.service
● ntp.service - Network Time Service
Loaded: loaded (/lib/systemd/system/ntp.service; enabled; vendor preset: enabled)
Active: active (running) since Tue 2023-08-22 20:14:59 CST; 1min 12s ago
Docs: man:ntpd(8)
Process: 1778 ExecStart=/usr/lib/ntp/ntp-systemd-wrapper (code=exited, status=0/SUCCESS)
Main PID: 1784 (ntpd)
Tasks: 2 (limit: 1595)
CPU: 128ms
CGroup: /system.slice/ntp.service
└─1784 /usr/sbin/ntpd -p /var/run/ntpd.pid -g -u 117:125
Aug 22 20:14:59 raspberrypi systemd[1]: Started Network Time Service.
Aug 22 20:15:00 raspberrypi ntpd[1784]: Soliciting pool server 193.182.111.143
Aug 22 20:15:01 raspberrypi ntpd[1784]: Soliciting pool server 84.16.67.12
Aug 22 20:15:01 raspberrypi ntpd[1784]: Soliciting pool server 94.237.64.20
Aug 22 20:15:02 raspberrypi ntpd[1784]: Soliciting pool server 79.133.44.136
Aug 22 20:15:02 raspberrypi ntpd[1784]: Soliciting pool server 79.133.44.136
Aug 22 20:15:03 raspberrypi ntpd[1784]: Soliciting pool server 36.110.233.85
Aug 22 20:15:03 raspberrypi ntpd[1784]: Soliciting pool server 202.112.29.82
Aug 22 20:15:04 raspberrypi ntpd[1784]: Soliciting pool server 119.28.183.184
Aug 22 20:15:05 raspberrypi ntpd[1784]: Soliciting pool server 185.209.85.222
三、其他
参考过很多的文章,提及到以下命令:
sudo timedatectl set-ntp true
实际测试,在执行以上命令时会出现如下异常
pi@raspberrypi:~/workfile $ sudo sudo timedatectl set-ntp true
Failed to set ntp: NTP not supported pi@raspberrypi:~/workfile $
在设置过程中,暂忽略使用该命令;