安装cloudera Manager的时候,必须要求集群的主机之间时间同步,搭建一个NTP服务器的思路是,首先通过一台主机master与外网进行时间同步,然后其他的slaver主机与主机master进行时间同步。

1、所有节点配置NTP服务

集群中所有主机必须保持时间同步,如果时间相差较大会引起各种问题。 具体思路如下:

master节点作为ntp服务器与外界对时中心同步时间,随后对所有datanode节点提供时间同步服务。

所有datanode节点以master节点为基础同步时间。

所有节点安装相关组件:yum install ntp。完成后,配置开机启动:chkconfig ntpd on,检查是否设置成功:chkconfig --list ntpd其中2-5为on状态就代表成功。

2、主节点配置

在配置之前,先使用ntpdate手动同步一下时间,免得本机与对时中心时间差距太大,使得ntpd不能正常同步。这里选用65.55.56.206作为对时中心,ntpdate -u 65.55.56.206

ntp服务只有一个配置文件,配置好了就OK。 这里只给出有用的配置,不需要的配置都用#注掉,这里就不在给出:

driftfile /var/lib/ntp/drift
restrict 127.0.0.1
restrict -6 ::1
restrict default nomodify notrap 
server 65.55.56.206 prefer
includefile /etc/ntp/crypto/pw
keys /etc/ntp/keys

配置文件完成,保存退出,启动服务,执行如下命令:service ntpd start

检查是否成功,用ntpstat命令查看同步状态,出现以下状态代表启动成功:

synchronised to NTP server () at stratum 2
time correct to within 74 ms
polling server every 128 s

如果出现异常请等待几分钟,一般等待5-10分钟才能同步。

3、配置ntp客户端(所有datanode节点)

driftfile /var/lib/ntp/drift
restrict 127.0.0.1
restrict -6 ::1
restrict default kod nomodify notrap nopeer noquery
restrict -6 default kod nomodify notrap nopeer noquery
#这里是主节点的主机名或者ip
server n1
includefile /etc/ntp/crypto/pw
keys /etc/ntp/keys

ok保存退出,请求服务器前,请先使用ntpdate手动同步一下时间:ntpdate -u n1 (主节点ntp服务器)

注意:由于上面配置的NTP服务器,之前在cloudera 集群中经常出现错误,说我的NTP服务器没设置,经过查询文档。发现还需要在集群所有的节点上执行如下命令:Synchronize the system clock (to prevent synchronization problems).

 执行: hwclock --systohc

 

这里可能出现同步失败的情况,请不要着急,一般是本地的ntp服务器还没有正常启动,一般需要等待5-10分钟才可以正常同步。启动服务:service ntpd start

因为是连接内网,这次启动等待的时间会比master节点快一些,但是也需要耐心等待一会儿。