栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 前沿技术 > 大数据 > 大数据系统

Linux 配置集群时间同步

Linux 配置集群时间同步

集群中,多个节点之间时间可能不是同步的,一般情况下问题不是很大,如果集群节点时间差距过大,会造成一些问题。
就比如 Hbase 的 RegionServer 服务起不来,会抛出一个错误,节点机的时间和master的时间差距大于30000ms
异常信息:

Caused by: org.apache.hadoop.ipc.RemoteException:
org.apache.hadoop.hbase.ClockOutOfSyncException: Server
s3,60020,1304927875246 has been rejected; Reported time is too far out
of sync with master. Time difference of 41450ms > max allowed of
30000ms

我们可以通过 ntp 服务来配置集群时间同步

首先查看是否已经安装 ntp

rpm -q ntp

如果已经安装了会显示出来

如果未安装,可以通过 yum -y install ntp 来安装

yum -y install ntp

查看是否是开机自启状态

systemctl is-enabled ntpd

可以看到默认是disable禁用开机启动的

执行 chkconfig ntpd on 或者 systemctl enable ntpd 设置为开机自启动

查看当前运行状态

service ntpd status


启动

service ntpd start


查看状态

这样就启动成功了
测试没问题,接下来开始修改配置文件
1、首先是选择一个节点当作时间服务器,该节点主要为其他节点提供时间,也就是其他节点向该节点同步时间。

我这里使用的时间服务器的IP为:172.16.32.204
可根据自身环境选择一个节点IP

打开ntp配置文件

vim /etc/ntp.conf

添加一行

restrict 172.16.0.0 mask 255.255.252.0 nomodify notrap

这个配置根据自己的网关和网段配置,只要能保证局域网主机通信就可以
我这里的ip是 172.16.32.204 所以网段配置为 172.16.0.0

将以下内容注释掉

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

注释掉后添加

server 127.127.1.0
fudge 127.127.1.0 stratum 10

效果图

配置好之后,保存并退出,执行 systemctl restart ntpd.service 重启ntp服务即可

服务端配置好后,接下来配置客户端
客户端即:向时间服务器同步时间的节点
首先步骤和上面差不多,安装ntp、开机自启…

修改配置文件

vim /etc/ntp.conf

客户端只需要将下面内容注释掉

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

然后添加
server 时间服务器IP

配置好后保存退出

手动同步以下时间

systemctl stop ntpd  # 先停止服务,否则ntp socket会被占用
ntpdate 时间服务器IP  # 手动执行同步
systemctl start ntpd  # 继续启动服务

同步时,会看到如下结果表示同步成功:
date查看时间

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/751168.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号