避坑:
1,服务器全部安装ntp服务,通过ntp.conf配置文件中minpoll、maxpoll两个参数来调整轮训时间源服务器同步频率,测试很多次,全部失败。
2,调整方式:server 0.centos.pool.ntp.org iburst minpoll 3 maxpoll 4
3,有调整成功的欢迎给出指导意见,以下是比较稳妥的一种时间同步方式。
4,参数调整参考:
http://www.ntp.org/ntpfaq/NTP-s-algo.htm#Q-ALGO-POLL-BEST
https://www.eecis.udel.edu/~mills/ntp/html/poll.html

时间同步服务器搭建

一、环境准备

虚拟机IP系统
ntp时间同步服务器(服务端)192.168.2.10centos7
同步主服务器时间 (客户端)192.168.2.11centos7

二、安装服务

1,服务端(2.10)

1,安装ntp服务

yum -y install ntp

2,修改配置文件: vi /etc/ntp.conf

restrict default nomodify notrap nopeer noquery
# Use public servers from the pool.ntp.org project.
# Please consider joining the pool (http://www.pool.ntp.org/join.html).
#server 0.centos.pool.ntp.org iburst
#server 1.centos.pool.ntp.org iburst
#server 2.centos.pool.ntp.org iburst
#server 3.centos.pool.ntp.org iburst
# server 全部注释,添加下面时间源地址
server 127.127.1.0 
fudge  127.127.1.0 stratum 0

3,启动ntp服务

systemctl start ntpd

2,客户端(2.11)

1,添加hosts 域名映射 vi /etc/hosts

192.168.2.10 ntpd.com

2,安装ntpdate

yum -y install ntpdate

3,测试ntpdate 命令是否安装成功,并测试是否可以同步本地时间服务器

4.1 date  # 查看系统当前时间(同时查看时间服务器上的时间是否一致)
4.2 /usr/sbin/ntpdate ntpd.com # ntpd.com这个域名映射的是本地局域网内的时间服务器

4,添加定时任务:crontab -e , 每10分钟同步一次服务器时间

*/10 * * * * /usr/sbin/ntpdate ntpd.com

三、设置开机自启动

1,关闭linux时间同步服务:chronyd

systemctl diable chronyd

2,设置ntp开机自启动

systemctl enable ntpd

3,启动ntpd

systemctl start ntpd

四、查看时间同步日志信息

cat /var/spool/mail/root

详细ntp配置说明可以参考:ntp配置参数详解

Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐