NTP是网络时间协议(Network Time Protocol),它是用来同步网络中各个计算机的时间的协议。本文,我们采用ntpd做时间同步,ntpd不仅仅是时间同步服务器,它还可以做客户端与标准时间服务器进行同步时间,而且是平滑同步
一、部署过程
1、安装NTP
yum install -y ntp
2、修改NTP配置
vim /etc/ntp.conf
#在配置中增加以下配置:
#允许上层时间服务器主动修改本机时间
restrict time.pool.aliyun.com nomodify notrap noquery
#允许所有主机通过本机同步时间
restrict default nomodify notrap
#外部时间服务器不可用时,以本地时间作为时间服务
server time.pool.aliyun.com iburst
server 127.127.1.0
fudge 127.127.1.0 stratum 10
说明:
- nomodfiy:客户端不能更改服务端的时间参数,但是客户端可以通过服务端进行网络校时。
- noquery:不提供客户端的时间查询。
- notrap:不提供trap这个远程时间登录的功能
3、启动NTP服务&开机启动设置
#启动NTP服务
systemctl start ntpd
#将NTP服务设置为开机启动
systemctl enable ntpd
4、查看NTP服务是否有和上层ntp连通
(一般需要5分钟左右)
# ntpstat
synchronised to NTP server (84.16.73.33) at stratum 2
time correct to within 250 ms
polling server every 512 s
5、防火墙配置
#开放NTP端口
firewall-cmd --add-port=123/udp --permanent
#重载防火墙规则
firewall-cmd --reload
二、客户端同步设置
1、安装NTP
yum install -y ntp
2、修改NTP配置
vim /etc/ntp.conf
#修改server节点
server 192.168.70.149
#在配置中增加以下配置:
#允许上层时间服务器主动修改本机时间
restrict 192.168.70.149 nomodify notrap noquery
#外部时间服务器不可用时,以本地时间作为时间服务
server 127.127.1.0
fudge 127.127.1.0 stratum 10
3、启动NTP服务&开机启动设置
#启动NTP服务
systemctl start ntpd
#将NTP服务设置为开机启动
systemctl enable ntpd
评论区