Ubuntu时间同步

来源:互联网 发布:ubuntu vim 查找 编辑:程序博客网 时间:2024/04/28 01:50

根据需求,我们可能需要系统做时间同步,可以当客户端,与网络时间同步;也可以当服务端,允许其他机器请求同步。

客户端1.安装同步程序sudo apt-get install ntpdate2.执行同步命令sudo ntpdate cn.pool.ntp.org
服务端1.安装同步服务器程序
sudo apt-get install ntp


测试方法:

Linux的时间分为System Clock(系统时间)和Real Time Clock (硬件时间,简称RTC)。系统时间:指当前Linux Kernel中的时间。硬件时间:主板上有电池供电的时间。时间同步之后需要不要忘记将系统时间写入硬件时间。
与网络时间同步在联网的情况下,我的电脑会自动与网络事件同步,使用了同步命令会看不出效果,所以需要手动把系统时间调成一个方便判断的时间,再进行时间同步。sudo date -s "1970-01-01 08:00:00"系统时间修改为1970年1月1日早上8点date查看当前时间;也可以看右上角的时间,不过最好把时间设置成显示秒的模式,不然可能等几秒到一分钟的时间才能看到变化sudo ntpdate cn.pool.ntp.org同步时间date查看时间,对比之前看到的时间
sudo hwclock -w写入到硬件,也可以使用sudo hwclock --systohc

成为时间同步服务器
sudo /etc/init.d/ntp start开启服务
sudo date -s "1970-01-01 08:00:00"系统时间修改为1970年1月1日早上8点
ifconfig查看本机ip
查看设备a时间date
使用其他设备a执行命令sudo ntpdate “本机ip”
查看设备a时间,确认是否同步date

Reference:

http://www.cnblogs.com/liuchangchun/p/4685032.html

http://blog.csdn.net/buster2014/article/details/45331505