一、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服务即可。

聂扬帆博客
一个分享IT运维相关工作经验和实战技巧的个人博客
2016年5月8日 上午1:10 沙发
进来看看、支持一下
2016年5月17日 下午9:55 板凳
哇哦,好专业的博客。
2016年5月23日 上午10:56 地板
很赞的说
2016年5月23日 上午11:47 4楼
博主好久不更新了呢
2016年5月25日 下午2:21 1层
@五四文娱 最近有点忙哈,会持续更新的
2021年4月3日 上午12:48 5楼
chrony好用的多