搭建时间同步服务器

yum安装ntp依赖包

yum -y install ntp

修改配置文件

#ntp和上级服务器同步所需时间记录文件
driftfile /var/lib/ntp/drift
#下级服务器同步时间规则,
#ignore :关闭所有的 NTP 联机服务
#nomodify:客户端不能更改服务端的时间参数,但是客户端可以通过服务端进行网络校时
#notrust:客户端除非通过认证,否则该客户端来源将被视为不信任子网
#noquery:不提供客户端的时间查询
Restrict default nomodify #默认不允许客户端更改服务端的参数
restrict -6 default kod nomodify notrap nopeer noquery 
#配置,notrap拒绝特殊的ntpdq捕获消息,noquery拒绝btodq/ntpdc查询  
estrict 192.168.4.0 mask 255.255.255.0 nomodify notrap 
restrict 192.168.10.0 mask 255.255.255.0 nomodify notrap
restrict 0.0.0.0 mask 0.0.0.0  nomodify notrap notrus
restrict 127.0.0.1 restrict ::1
#上级时间服务器
server 210.72.145.44 prefer 
#中国国家授时中心地址优先使用
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


# 如果无法与上层ntp server通信以本地时间为标准时间
server   127.127.1.0    # local clock
fudge    127.127.1.0 stratum 10

#日志文件
logfile /var/log/ntp.log

includefile /etc/ntp/crypto/pw
keys /etc/ntp/keys disable monitor

将时间写入CMOS

cat >> /etc/sysconfig/ntpd <<
SYNC_HWCLOCK=yes
EOF

启动服务器

systemctl start ntpd.service

客户端时间同步 shell crontab -e */15 * * * * /usr/sbin/ntpdate 192.168.4.18

猜你喜欢

转载自www.cnblogs.com/baijuminglu/p/9275067.html