查看: 8226|回复: 2

beaglebone black 自动同步时间设置

[复制链接]
  • TA的每日心情
    慵懒
    2016-6-15 14:29
  • 签到天数: 6 天

    连续签到: 1 天

    [LV.2]偶尔看看I

    发表于 2013-8-10 23:29:41 | 显示全部楼层 |阅读模式
    分享到:
    bb black每次上电时间都不对,因此我花了点时间把自动同步时间设置好了,下面讲一下流程:

    首先得安装NTP服务:

    opkg update
    opkg install ntp

    然后,可以手动同步时间:
    root@beaglebone:~# ntpdate -b -s -u cn.pool.ntp.org
    root@beaglebone:~# date

    这个时候如果没什么问题,应该会同步到UCT时间,跟北京时间是有8个小时的,注意一下。下面我们将时间改成+8时区,我用的是香港的时间,zoneinfo里面没有北京时间的配置文件,因此找了同样时区的香港时间:

    root@beaglebone:/etc# rm localtime
    root@beaglebone:/etc# ln -s /usr/share/zoneinfo/Asia/Hong_Kong /etc/localtime

    第二步去配置 /etc/ntp.conf,我将其改成这样:
    1. # This is the most basic ntp configuration file
    2. # The driftfile must remain in a place specific to this
    3. # machine - it records the machine specific clock error

    4. driftfile /etc/ntp.drift
    5. logfile /var/log/ntpd.log

    6. # NTP Servers
    7. server cn.pool.ntp.org
    8. server 0.ie.pool.ntp.org

    9. # Using local hardware clock as fallback
    10. # Disable this when using ntpd -q -g -x as ntpdate or it will sync to itself
    11. # server 127.127.1.0
    12. # fudge 127.127.1.0 stratum 14

    13. # Defining a default security setting
    14. restrict default
    复制代码
    当然也可以在server项中自己添加想要的对时服务器。

    下面开始配置自动对时服务,首先打开两个服务:

    root@beaglebone:/etc# systemctl enable ntpdate.service
    root@beaglebone:/etc# systemctl enable ntpd.service

    然后进入到service文件的目录 ,更改一下第二个服务的配置文件:

    vi /lib/systemd/system/ntpdate.service

    原始的文件应该是:
    1. [Unit]
    2. Description=Network Time Service (one-shot ntpdate mode)
    3. Before=ntpd.service

    4. [Service]
    5. Type=oneshot
    6. ExecStart=/usr/bin/ntpdate-sync silent
    7. RemainAfterExit=yes

    8. [Install]
    9. WantedBy=multi-user.target
    复制代码
    将其更改为:
    1. [Unit]
    2. Description=Network Time Service (one-shot ntpdate mode)
    3. Before=ntpd.service

    4. [Service]
    5. Type=oneshot
    6. ExecStart=/usr/bin/ntpd -q -g -x
    7. ExecStart=/sbin/hwclock --systohc
    8. RemainAfterExit=yes

    9. [Install]
    10. WantedBy=multi-user.target
    复制代码
    然后reboot,连接上网络后板子就会自动对时了。
    回复

    使用道具 举报

  • TA的每日心情
    开心
    2013-8-7 09:31
  • 签到天数: 5 天

    连续签到: 1 天

    [LV.2]偶尔看看I

    发表于 2013-8-13 15:21:20 | 显示全部楼层
    strong  a
    {:soso_e179:}
    回复 支持 反对

    使用道具 举报

  • TA的每日心情
    开心
    2017-12-27 09:25
  • 签到天数: 1 天

    连续签到: 1 天

    [LV.1]初来乍到

    发表于 2017-12-27 10:54:26 | 显示全部楼层
    谢谢分享。
    回复 支持 反对

    使用道具 举报

    您需要登录后才可以回帖 注册/登录

    本版积分规则

    关闭

    站长推荐上一条 /2 下一条

    手机版|小黑屋|与非网

    GMT+8, 2024-4-28 22:03 , Processed in 0.130083 second(s), 19 queries , MemCache On.

    ICP经营许可证 苏B2-20140176  苏ICP备14012660号-2   苏州灵动帧格网络科技有限公司 版权所有.

    苏公网安备 32059002001037号

    Powered by Discuz! X3.4

    Copyright © 2001-2024, Tencent Cloud.