linux集群安装ntp时间同步

这里搭建的时间同步服务器模式为:
master主节点作为服务器,slave01,slave02,slave03访问master01.
master:192.168.200.20
slave01:192.168.200.21
slave02:192.168.200.22
slave03:192.168.200.23
一:所有节点先下载服务:
yum install ntp -y
二:修改配置文件
路径为/etc/ntp.conf
master内容修改为:
restrict default kod nomodify notrap nopeer noquery
restrict -6 default kod nomodify notrap nopeer noquery
restrict 220.130.158.71
restrict 59.124.196.83
restrict 59.124.196.84
restrict 127.0.0.1
restrict -6 ::1
#:将192.168.200.0修改为对外开放的ip段.表示ip为192.168.100的可以访问
restrict 192.168.200.0 mask 255.255.255.0 nomodify
server time1.aliyun.com prefer
server 220.130.158.71
server 59.124.196.83
server 59.124.196.84
driftfile /var/lib/ntp/drift
keys /etc/ntp/keys
slave内容修改为:
ftfile /var/lib/ntp/drift
restrict 127.0.0.1
restrict -6 ::1
#:192.168.200.20修改为自己作为ntp主节点的ip地址
server 192.168.200.20
restrict 192.168.200.20 nomodify notrap noquery
server 127.127.1.0 # local clock
fudge 127.127.1.0 stratum 10
includefile /etc/ntp/crypto/pw
keys /etc/ntp/keys
三.配置完后重启服务.
命令:service ntpd restart
等待十几分钟左右.查询master状态
命令:ntpstat
master成功的状态
客服端执行命令:ntpdate -u 192.168.200.20 .ip为master的地址
查看状态 ntpstat
客户端成功的状态

五.将所有节点作为自启动.
chkconfig ntpd on
六.结束
七.如果自启动没有起作用.
查看ntp状态 service ntpd status
如果没有启动.Active: inactive (dead)
查看是否设置了自启动:
systemctl is-enabled ntpd
结果:enabled
如果显示已经设置了自启动.常见情况是chrony和ntp冲突
查看chrony状态
命令:systemctl is-enabled chronyd
结果:enabled
解决冲突:
systemctl disable chronyd.service
再启动ntp,重新设置一遍自启动.
然后重启节点.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Linux 集群中,由于多台服务器之间的时间差异可能会影响到一些应用程序的正常运行,因此需要进行时间同步。下面介绍两种常用的时间同步方案: 1. NTP 时间同步方案 NTP(Network Time Protocol)是一种用于同步网络中计算机时间的协议,通过在服务器上运行 NTP 服务器,其他计算机可以通过 NTP 协议与服务器进行时间同步。 具体操作步骤如下: 1)在一个节点上安装 NTP 服务器软件: ``` yum install ntp ``` 2)编辑配置文件 /etc/ntp.conf,将服务器地址修改为本地服务器的 IP 地址: ``` server 127.127.1.0 fudge 127.127.1.0 stratum 10 server 0.cn.pool.ntp.org ``` 3)启动 NTP 服务并设置开机自启动: ``` systemctl start ntpd systemctl enable ntpd ``` 4)在其他节点上安装 NTP 客户端软件: ``` yum install ntpdate ``` 5)使用以下命令进行时间同步: ``` ntpdate -u 服务器IP地址 ``` 2. Chrony 时间同步方案 Chrony 是一种轻量级的时间同步软件,相比 NTP 更加精准和稳定。Chrony 的主要优势在于它可以快速适应网络延迟的变化,从而更加准确地进行时间同步。 具体操作步骤如下: 1)在所有节点上安装 Chrony 软件: ``` yum install chrony ``` 2)编辑配置文件 /etc/chrony.conf,将服务器地址修改为本地服务器的 IP 地址: ``` server 127.127.1.0 fudge 127.127.1.0 stratum 10 server 0.cn.pool.ntp.org ``` 3)启动 Chrony 服务并设置开机自启动: ``` systemctl start chronyd systemctl enable chronyd ``` 通过以上两种方案的操作,就可以完成 Linux 集群中的时间同步。需要注意的是,在使用 NTP 或 Chrony 进行时间同步时,要确保所有节点的时间都正确,并且所有节点都能够访问到 NTP 或 Chrony 服务器。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值