Centos7配置ntp时间同步

本文详细描述了如何在CentOS7系统中配置NTP,包括服务器端的安装、配置和启动,以及客户端的同步步骤。提示注意可能需要关闭防火墙以确保时间同步成功。
摘要由CSDN通过智能技术生成

时间同步是使客户端与服务器的时间同步

配置条件: 需要两台或两台以上的主机进行操作,需要一台服务器端,其余主机都是客户端。
server:192.168.120.10
client1:192.168.120.20

配置方式:

1.服务器端

[root@centos7 ~]# yum install -y ntp*	#安装ntp服务 
[root@centos7 ~]# vi /etc/ntp.conf	#配置ntp文件
restrict 192.168.120.0 mask 255.255.255.0 nomodify notrap	#去掉#,修改为指定的网段
server 127.127.1.0	#以本机服务器为时间同步服务器
fudge 127.127.1.0 stratum 10  #fudge设置层级关系
[root@centos7 ~]# systemctl start ntp	#启动ntp服务
[root@centos7 ~]# systemctl enable ntp	#开机自启ntp服务
[root@centos7 ~]# timedatectl
Local time: Sat 2021-08-28 09:32:08 CST
Universal time: Sat 2021-08-28 01:32:08 UTC
RTC time: Sat 2021-08-28 01:32:08
Time zone: Asia/Shanghai (CST, +0800)
NTP enabled: yes
NTP synchronized: yes
RTC in local TZ: no
DST active: n/a

2.客户端配置

[root@centos7 ~]# yum install -y ntp*
[root@centos7 ~]# vi /etc/ntp.conf
restrict 192.168.120.0 mask 255.255.255.0 nomodify notrap	#去掉#,修改为指定的网段
server 127.127.1.0	#以本机服务器为时间同步服务器
fudge 127.127.1.0 stratum 10  #fudge设置层级关系
[root@centos7 ~]# systemctl start ntp	#启动ntp服务
[root@centos7 ~]# systemctl enable ntp	#开机自启ntp服务
[root@centos7 ~]# timedatectl  #查看是否时间相同
Local time: Sat 2021-08-28 09:32:08 CST
Universal time: Sat 2021-08-28 01:32:08 UTC
RTC time: Sat 2021-08-28 01:32:08
Time zone: Asia/Shanghai (CST, +0800)
NTP enabled: yes
NTP synchronized: yes
RTC in local TZ: no
DST active: n/a

须知

这样就做完了,如果没有同步需等待一会。
注意:等待了一会时间还是未能同步需关闭防火墙,或者放行ntp的端口

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值