一.相关文件
/usr/share/zonefile/下的时区文件
/usr/share/zoneinfo/Asia/Chongqing
/etc/localtime
/etc/ntp.conf
二.安装软件
yum -y install ntp ntpdate
三.部署过程
覆盖本地时区文件
cp /usr/share/zoneinfo/Asia/Chongqing /etc/localtime
配置ntp.conf
vim /etc/ntp.conf
a.配置访问权限:
在该文件第19行开始添加入访问你ntp服务器的网路或者主机。例如:
restrict 192.168.100.0 mask 255.255.255.0 nomodify notrap
restrict 192.168.240.0 mask 255.255.255.0 nomodify notrap
关于restrict格式如下:
restrict [ip] mask [mask_number] [parameter]
其中parameter如下:
ignore:居然所有类型的ntp连接
nomodify:不允许客户端修改服务器的时间参数,但是允许客户端透过这部主机进行时间校验。
noquery:不允许客户端进行时间校验。
notrap:不提供trap时间登录
notrust:拒绝没有认证的客户端
b.配置Sever段
server [IP or HOSTNAME] [PREFER]
国内经常用到的ntp服务器有如下:
ntp.sjtu.edu.cn
s1a.time.edu.cn
s1b.time.edu.cn
s1c.time.edu.cn
s1d.time.edu.cn
s1e.time.edu.cn
s2a.time.edu.cn
s2b.time.edu.cn
s2c.time.edu.cn
s2d.time.edu.cn
s2e.time.edu.cn
s2f.time.edu.cn
s2g.time.edu.cn
s2h.time.edu.cn
s2j.time.edu.cn
s2k.time.edu.cn
s2m.time.edu.cn
clock.cuhk.edu.hk
注销掉0.centos.pool.ntp.org
1.centos.pool.ntp.org
2.centos.pool.ntp.org
3.启动ntp服务
Server npd start
chkconfig --level 35 ntpd on
4.验证ntp服务
netstat -tlunp | grep ntp
udp 0 0 192.168.100.253:123 0.0.0.0:* 3846/ntpd
udp 0 0 127.0.0.1:123 0.0.0.0:* 3846/ntpd
udp 0 0 0.0.0.0:123 0.0.0.0:* 3846/ntpd
udp 0 0 fe80::211:25ff:fea8:153a:123 :::* 3846/ntpd
udp 0 0 ::1:123 :::* 3846/ntpd
udp 0 0 :::123 :::* 3846/ntpd
ntpstat
synchronised to NTP server (137.189.4.10) at stratum 2
time correct to within 46 ms
polling server every 64 s
5.客户端设置
ntpdate hwclock -w