根据需求,我们可能需要系统做时间同步,可以当客户端,与网络时间同步;也可以当服务端,允许其他机器请求同步。
客户端 1.安装同步程序 sudo apt-get install ntpdate 2.执行同步命令 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