2022-09-02 配置集群时间同步

一、架构

1. 架构图

 

2. 解释

        从集群中挑选出一台服务器作为时间服务器,其他机器的时间都和该时间服务器的时间进行同步。

二、集群时间同步的配置方法

1. 时间服务器配置

(1) 在时间服务器上切换用户至root用户

su - root

(2) 查看本机是否已经安装ntp服务,如果没有,则安装ntp服务

# 查看本机是否已经安装了ntp服务
rpm -qa | grep -i -E "ntp"

# 如果执行上面的命令后,发现没有安装ntp服务,使用该命令安装
# yum –y install ntp

(3) 设置ntp服务为开启自启

# 设置ntp服务开机自启
systemctl enable ntpd

(4) 确保ntp服务处于关闭状态,修改它的ntp.conf配置文件

# 关闭ntp服务
systemctl stop ntpd

# 确认ntp服务当前未运行
systemctl status ntpd

# 使用文本编辑器打开ntp服务的配置文件,进行修改
sudo vim /etc/ntp.conf

# 第一处修改,配置集群内网段上的所有服务器都可以从本机查询和同步时间
# 第二个网络号根据自己集群所处的网络号来写
:%s/#restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap/restrict 192.168.159.0 mask 255.255.255.0 nomodify notrap/g

# 第二处修改,不使用互联网上的时间,使用局域网的时间
:%s/server 0.centos.pool.ntp.org iburst/#server 0.centos.pool.ntp.org iburst/g
:%s/server 1.centos.pool.ntp.org iburst/#server 1.centos.pool.ntp.org iburst/g
:%s/server 2.centos.pool.ntp.org iburst/#server 2.centos.pool.ntp.org iburst/g
:%s/server 3.centos.pool.ntp.org iburst/#server 3.centos.pool.ntp.org iburst/g

# 添加内容,如果该节点丢失了网络连接,就使用本地时间作为同步时间使用
server 127.127.1.0
fudge 127.127.1.0 stratum 10

# 退出保存

(5) ntp服务处于关闭的情况下,继续配置另一个配置文件:ntpd

# 使用文本编辑器打开配置文件,进行配置
vim /etc/sysconfig/ntpd

# 添加内容如下
SYNC_HWCLOCK=yes

# 保存退出

(6) 开启ntp服务,退出root用户

# 开启ntp服务
systemctl start ntpd

# 退出root用户
exit

2. 其他服务器配置

 (1) 在服务器上切换用户至root用户

su - root

(2) 查看本机是否已经安装ntp服务,如果没有,则安装ntp服务

# 查看本机是否已经安装了ntp服务
rpm -qa | grep -i -E "ntp"

# 如果执行上面的命令后,发现没有安装ntp服务,使用该命令安装
# yum –y install ntp

(3) 设置ntp服务为开启禁启

# 设置ntp服务开机自启
systemctl disable ntpd

(4) 确保ntp服务处于关闭状态

# 关闭ntp服务
systemctl stop ntpd

# 确认ntp服务当前未运行
systemctl status ntpd

(5) 使用crontab编写定时任务

# 启动crontab服务
systemctl start crond

# 编写定时任务
crontab -e

# 每隔十分钟进行时间同步,主机名为时间服务器的主机名,内容为:
*/10 * * * * sudo /usr/sbin/ntpdate hadoop101

(6) 退出root用户

exit

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值