一、NTP服务器搭建
1、NTP Server安装# wget http://www.eecis.udel.edu/~ntp/ntp_spool/ntp4/ntp-4.2/ntp-4.2.8p7.tar.gz
# tar zxvf ntp-4.2.8p7.tar.gz
# cd ntp-4.2.8p7
# ./configure --prefix=/usr/local/ntp --enable-all-clocks --enable-parse-clocks
# make && make install
2、修改配置文件
编辑/etc/ntp.conf文件
a、允许任何IP进行同步找到restrict default kod nomodify notrap nopeer noquery注释掉,在下面添加一行
restrict default nomodify
b、允许指定IP进行同步在restrict default nomodify notrap noquery之后增加一行
restrict IP段 mask 掩码 nomodify
3、启动服务# service ntpd start
# chkconfig --level 35 ntpd on #开机启动
二、NTP客户端配置# date ##查看同步之前的系统时间
# ntpdate xx.xx.xx.xx ## xx为ntp server的ip
# hwclock -w ##把时间写入BIOS
设置排程自动同步# crontab -e
00 04 * * * /usr/sbin/ntpdate xx.xx.xx.xx; /sbin/hwclock -w ##每天凌晨4点自动同步
常见问题:
1、客户端同步时间时出现no server suitable for synchronization found
原因:ntp服务器不可用
解决办法:
a、查看防火墙是否开放udp 123端口;
b、在ntp服务器运行watch ntpq -p命令,观察reach delay offset jitter几个列是否有值,如果都为0则公共时间服务器不可达;
c、在ntp服务器上线关闭ntp服务,检查公共时间服务器是否可用;ps:公共时间服务器配置在/etc/ntp.conf下,找到Use public servers from the pool.ntp.org project一行,下面已server开头的即是。使用下面命令一个个去测试,更换上同步成功的server# service ntpd stop;
# /usr/sbin/ntpdate asia.pool.ntp.org
最后开启ntpd服务即可。