Linux配置NTP时间同步

实验环境

NTP服务端:192.168.174.133
NTP客户端:192.168.174.134

安装

1. 确认是否已安装ntp(Linux默认会安装)

rpm -qa|grep ntp

在这里插入图片描述
本机已经安装NTP,如果未安装则使用yum进行安装

2. 安装NTP服务

yum -y install ntp ntpdate

3. 设置防火墙,打开NTP端口
ntp_server和ntp_client均需开放123/udp端口

firewall-cmd --zone=public --add-port=123/udp --permanent
firewall-cmd --reload

在这里插入图片描述

服务端配置

1. 修改配置文件

vim /etc/ntp.conf
//192.168.174.133为当前节点IP地址
restrict 192.168.174.133 nomodify notrap nopeer noquery
//集群所在网段、掩码、权限
restrict 192.168.174.0 mask 255.255.255.0 nomodify notrap

server 127.127.1.0
fudge 127.127.1.0 stratum 10
interface ignore  wildcard
//192.168.174.133为当前节点IP地址
interface listen  192.168.174.133
interface listen  127.0.0.1

在这里插入图片描述

2. 启动NTP服务、设置NTP开机启动
因为centos7默认使用chronyd来进行时间同步服务,所以使用ntp服务需要关闭chronyd服务
查看chronyd状态

systemctl status chronyd

在这里插入图片描述

禁止chronyd开机启动

systemctl disable chronyd.service

在这里插入图片描述

启动ntp服务

systemctl start ntpd  

容许ntp服务开机启动

systemctl enable ntpd

在这里插入图片描述

客户端配置

1. 修改配置文件

vim /etc/ntp.conf
//当前节点IP地址
restrict 192.168.174.134 nomodify notrap nopeer noquery
//集群所在网段的网段(Gateway),子网掩码(Genmask)
restrict 192.168.174.0 mask 255.255.255.0 nomodify notrap
//NTP服务器IP地址
server 192.168.174.133 iburst
//NTP服务器层级设置
fudge 192.168.174.133 stratum 10

在这里插入图片描述

2. 预先同步一次时间
ntpd进程进行同步时,只能同步较小的时间差,为防止时间差别太大,提前使用ntpdate进行一次时间同步

ntpdate 192.168.174.133

在这里插入图片描述

3. 开机启动、设置防火墙

firewall-cmd --zone=public --add-port=123/udp --permanent 设置ntp防火墙开放策略
firewall-cmd --reload  重新加载防火墙

在这里插入图片描述

4. 开启NTP服务器设置NTP自启动

systemctl status chronyd   查看chronyd状态 
systemctl disable chronyd.service   禁止chronyd开机启动
systemctl start ntpd    启动ntp服务
systemctl enable ntpd    容许ntp服务开机启动

在这里插入图片描述

查看ntp服务状态

systemctl status ntpd

在这里插入图片描述

查看ntp链接状态

ntpq -p
remote://本机和上层ntp的ip或主机名,“+”表示优先,“*”表示次优先
refid://参考上一层ntp主机地址
st://stratum阶层
when://多少秒前曾经同步过时间
poll://下次更新在多少秒后
reach://已经向上层ntp服务器要求更新的次数
delay://网络延迟
offset://时间补偿
jitter://系统时间与bios时间差

在这里插入图片描述

查看ntpd进程的状态

watch "ntpq -p"

在这里插入图片描述

  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值