安装ntp
#检查服务是否安装
rpm -q ntp
#安装ntp服务器
yum -y install ntp
修改配置文件:/etc/ntp.conf
内容如下:
restrict default kod nomodify notrap nopeer noquery
restrict -6 default kod nomodify notrap nopeer noquery
restrict 127.0.0.1
restrict -6 ::1
fudge 127.127.1.0 stratum 10
driftfile /var/lib/ntp/drift
keys /etc/ntp/keys
logfile /var/log/ntp.log
includefile /etc/ntp/crypto/pw
server 128.199.84.169
![](https://i-blog.csdnimg.cn/blog_migrate/d58f5fbe560c4f284572f3708be4a449.png)
设置ntpd为系统服务,并开机自启动
systemctl enable ntpd
systemctl restart ntpd
测试Ntpd服务
1. 修改系统时间
date -s "2016-03-09 07:00:00"
![](https://i-blog.csdnimg.cn/blog_migrate/6d000fe2c10bf936e26a050f368ad93a.png)
2. 使用tcpdump抓包测试
在一个终端执行:
tcpdump -i eth0 -s 0 -vvvvv udp port 123
说明:ntpd是使用udp 123端口来传输数据的
![](https://i-blog.csdnimg.cn/blog_migrate/6ffc1765cf98aeb6b9e367112b821e01.png)
3. 重启ntpd服务,查看时间同步结果
systemctl restart ntpd
![](https://i-blog.csdnimg.cn/blog_migrate/510d04327b884be692d1384f7a7f2cf1.png)
此时看看tcpdump抓包情况
![](https://i-blog.csdnimg.cn/blog_migrate/881cd53bca6958d1aed442c6991cd19a.png)
手动同步时间
ntpdate 128.199.84.169
其他命令
1. ntpq -p
查看本机和上层服务器的时间同步结果
2. ntptrace
可以用來追踪某台时间服务器的时间对应关系
3. ntpdate IP ,如:ntpdate 128.199.84.169
客户端与NTP server进行时钟同步。
4.
tail -f /var/log/ntp.log
查看ntp日志
systemctl stop ntpd.service
ntpdate 128.199.84.169 #手动同步