Linux CentOS7 服务器集群时间同步(ntp)

1. 安装 ntp


# 确认是否已安装 ntp, 若只有 ntpdate,则需删除 ntpdate
[root@localhost ~]# rpm -qa|grep ntp

# 删除已安装 ntpdate
[root@localhost ~]# yum remove ntpdate –y

# 安装ntp
[root@localhost ~]# yum install ntp -y

2. 配置服务端


[root@localhost ~]# vi /etc/ntp.conf
# 如果集群是在一个封闭的局域网内,可以屏蔽掉默认的server:
# server 0.centos.pool.ntp.org iburst
# server 1.centos.pool.ntp.org iburst
# server 2.centos.pool.ntp.org iburst
# server 3.centos.pool.ntp.org iburst
# 授权192.168.89.0网段上的所有机器可以从这台机器上查询和同步时间
restrict 192.168.89.0 mask 255.255.255.0 nomodify notrap

# 将本地时钟作为时间供给源,即便它失去网络连接,仍可以继续为网络提供服务;
server 127.127.1.0 #local clock
fudge 127.127.1.0 stratum 3

# 防火墙放开 123 端口
[root@localhost ~]# iptables -A INPUT -s 192.168.89.0/24 -p udp --dport 123 -j ACCEPT
[root@localhost ~]# iptables -A INPUT -p udp --dport 123 -j DROP

# 重启服务
[root@localhost ~]# systemctl stop ntpd.service
[root@localhost ~]# systemctl start ntpd.service

3. 配置客户端


# 修改/etc/ntp.conf,增加时间同步主节点
[root@localhost ~]# vi /etc/ntp.conf
server 192.168.89.121 prefer

# 重启服务,客户端从服务端同步时间
[root@localhost ~]# systemctl stop ntpd.service
[root@localhost ~]# systemctl start ntpd.service

亲,如果您觉得文章对您有那么一小点点帮助,希望您能给点个赞,谢谢!打赏个一分钱,那我会超级开心(✿◠‿◠)

在这里插入图片描述

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值