NTP时间同步

时间同步的作用

  1. NTP (Network Time Protocol,网络时间协议)是用来使计算机时间同步的一种协议
  2. 它可以使计算机对其服务器或时钟源做同步化,它可以提供高精准度的时间校正(LAN上与标准间差小于1毫秒,WAN上几十毫秒)
  3. 对于服务器群集来说,这个是一个很重要的服务,因为群集需要保证每个服务器的时间是保持一致的,这样它们在执行同一个任务时才不会出现有的服务器有滞后的现象,这样群集的状态才是健康的。

NTP的工作模式

  • C/S模式

NTP的协议及端口号

  • UDP协议123号端口

配置步骤

(1)配置环境

  • 服务端:192.168.1.13
  • 客户端1:192.168.1.14
  • 客户端2:192.168.1.15

(2)全部关闭防火墙

[root@server4 ~]# systemctl stop firewalld
[root@server4 ~]# systemctl disable firewalld
[root@server4 ~]# setenforce 0

(3)全部安装 ntpdate 软件

[root@server4 ~]# yum -y install ntpdate

(4)服务器端同步 aliyun 时间

[root@server4 ~]# ntpdate ntp.aliyun.com

(5)服务器端为其他客户机提供服务需要安装 ntp 软件

[root@server4 ~]# yum -y install ntp

(6)修改 ntp 配置文件

[root@server4 ~]# vi /etc/ntp.conf 
restrict default nomodify                      # 第8行
restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap  # 第17行,192.168.1.0 为本机上网网段
第 21 行到第 24 行删除,重新添加两行
fudge 127.127.1.0 stratum 10
server 127.127.1.0

(7)启动服务

[root@server4 ~]# systemctl start ntpd
[root@server4 ~]# netstat -anptu | grep ntpd
udp        0      0 192.168.1.13:123           0.0.0.0:*                78169/ntpd  

(8)设置周期性计划任务

[root@server4 ~]# crontab -e
*  *  *  *  *   /usr/sbin/update ntp.aliyun.com

(9)客户机设定同步源为 192.168.1.13

[root@server5 ~]# ntpdate 192.168.1.13
[root@server6 ~]# ntpdate 192.168.1.13

(10)客户机设置周期性计划任务

[root@server5 ~]# crontab -e
*  *  *  *  *   /usr/sbin/update 192.168.1.13
[root@server6 ~]# crontab -e
*  *  *  *  *   /usr/sbin/update 192.168.1.13
  • 0
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值