Centos/Redhat_7.9配置ntp服务

本文详细介绍了NTP服务在计算机网络中的作用,包括安装、配置ntpdate和ntp,设置时间同步规则,以及如何在服务器和客户端上使用NTP进行时间同步。
摘要由CSDN通过智能技术生成

说明:
  NTP ( Network Time Protocol ) 服务的作用是在计算机网络中同步各个设备的时间,确保网络中所有设备的时间保持一致和准确。通过与参考时间源 ( NTP 服务器 ) 同步,可以避免不同设备之间出现时间差,确保网络中的事件顺序正确,同时避免一些服务因为时间不同步导致报错。

查看系统是否安装了ntp服务,一般默认安装ntpdate;

[root@CS01 ~]# rpm -qa | grep ntp
ntpdate-4.2.6p5-29.el7.centos.2.x86_64
ntp-4.2.6p5-29.el7.centos.2.x86_64

安装ntp服务

yum install ntp ntpdate -y

修改配置文件,同时过滤掉一些无用的信息

vim /etc/ntp.conf

driftfile /var/lib/ntp/drift
restrict default nomodify notrap nopeer noquery			## restrict限制操作,默认放开客户端所有操作
restrict 127.0.0.1			## 允许本机所有操作
restrict ::1

restrict 172.22.19.0 mask 255.255.255.0 nomodify notrap			## 限制172.22.19.0/24网段内的服务器不能修改
restrict 172.22.22.180 mask 255.255.255.0 nomodify notrap			## 限制172.22.22.180这台服务器不能修改

logfile /var/log/ntpd.log			## 默认日志路径,可根据需求修改

# server 0.centos.pool.ntp.org iburst			#####################################
# server 1.centos.pool.ntp.org iburst			##    这些系统自带的ntp服务器地址   ##
# server 2.centos.pool.ntp.org iburst			##            可以注销掉           ##
# server 3.centos.pool.ntp.org iburst			#####################################
server 127.127.1.1			## 配置本机为ntp服务

includefile /etc/ntp/crypto/pw
 
keys /etc/ntp/keys

disable monitor

启动ntp服务并加入开机启动;

systemctl start ntpd 
systemctl enable ntpd 
systemctl list-unit-files --type=service | grep ntpd
ss -nulp | grep ntpd			## 因为是UDP协议所以这里需要-u参数

[root@CS01 ~]# ntpq -p			## 查看ntp状态
     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
*LOCAL(1)        .LOCL.           5 l   29   64  377    0.000    0.000   0.000

ntp服务端如何同步外网的时间

/usr/sbin/ntpdate -u ntp1.aliyun.com 9000			## 因为ntpd将123端口占用,所以我们则可以只从端口去同步外网ntp服务器

客户端同步时间

ntpdate CS01
或者crontab -e加入
0 */2 * * * /usr/sbin/ntpdate CS01;/sbin/hwclock -w >/dev/null 2>&1
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值