树莓派时间更新为中国区时间

一、测试环境为:树莓派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 $

        在设置过程中,暂忽略使用该命令;

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值