1、安装NTP
$ sudo apt-get install ntp
2、NTP服务端配置文件位置
/etc/ntp.conf
3、NTP服务端配置文件参数说明
restrict -4 default kod nomodify notrap nopeer noquery
restrict -6 default kod nomodify notrap nopeer noquery
# -4 表示IP_V4; -6 表示IP_V6;
#default 表示默认配置
#kod 表示kiss o'death的意思,就是服务器太繁忙,让客户端范围其他服务器或者等一会再访问。
#nomodify 表示客户端不能使用 ntpc 与 ntpq 这两个程序来修改服务器的时间参数,但客户端可以通过服务器校时。
#notrap 表示禁止trap 这个远程事件登录 (remote event logging) 的功能。
#nopeer 表示不与其他同一层的NTP服务器进行时间同步。
#noquery 表示客户端不能够实用ntpq, ntpc 等指令来查询时间服务器,等于不提供 NTP 网络校时服务。
#ignore 表示拒绝所有类型的NTP连接。
#notrust 表示拒绝没有认证的客户端。
示例:
restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap
#表示192.168.1.1--192.168.1.254的客户端都可以与此校时服务器进行校时。
4、配置当前服务器为顶层服务器
server 127.127.1.0 perfer
fudge 127.127.1.0 stratum 0
#127.127.1.0表示本机
#perfer 表示优先使用
#stratum 1 表示第一层,第二层的服务器找第一层服务器同步时间,取值范围(1~15)。
5、客户端同步
一、手动同步:
$sudo nepdate 192.168.237.10 #192.168.237.10为时间同步服务器地址
二、crontab定期同步:
$sudo crontab -e #打开系统默认编辑器,编辑配置文件。
0 * * * * /user/sbin/ntpdate 192.168.237.10 #每天第0分钟执行时间同步。