集群中,多个节点之间时间可能不是同步的,一般情况下问题不是很大,如果集群节点时间差距过大,会造成一些问题。
就比如 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为:192.17.0.144
可根据自身环境选择一个节点IP
打开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 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 192.17.0.144 iburst
配置好后保存退出
重启服务,等待一会后使用
或者使用ntpdate -u 192.17.0.144手动来进行同步
ntpq -p
命令查看
如果主机名前面出现 * 就表示时间同步成功
这一步需要等待一会…