测试平台:两个机器,一个交换机
同步方法:使用ntp工具来同步时间
NTP简介:NTP 是通过网络来同步时间的一种 TCP/IP 协议。通常客户端向服务器请求当前的时间,并根据结果来设置其时钟。
安装方法:sudo apt-get install ntp(本地时间服务器安装,其他设备可以不装),sudo apt-get install ntpdate(都要安装)。
使用方法:两个机器,IP分别为192.168.1.112,192.168.1.113.使用IP为192.168.1.112的设备获取网络时间(ntpdate -u cn.pool.ntp.org),并设置这个设备作为本地的时间服务器(配置ntp.conf文件,下面会说到)。IP为192.168.1.113的设备同步到本地的时间服务器(ntpdate -u 192.168.1.112),这样两台机器的设备即可同步。
配置文件说明:
192.168.1.112的ntp配置文件(/etc/ntp.conf)
# /etc/ntp.conf, configuration for ntpd; see ntp.conf(5) for help
driftfile /var/lib/ntp/ntp.drift
# Enable this if you want statistics to be logged.
#statsdir /var/log/ntpstats/
statistics loopstats peerstats clockstats
filegen loopsta