Hadoop集群实现时间同步

一.为什么要对集群实现时间同步

        因为我们在集群使用hive,mysql,hdfs之间等使用sqoop传输数据的时候,如果集群之间没有同步时间的话,那么就会报错,无法实现数据的传输。

        不仅如此,在集群的使用当中,如果不实现时间的同步的话,那么在使用的过程当中难免会出现问题。 

我使用的工具是mobaXterm

二.实现时间同步

1.时间服务器配置(必须root用户)

(1)检查安装:[root@HP111 ~]# rpm -qa | grep ntp
ntp-4.2.6p5-28.el7.centos.x86_64
ntpdate-4.2.6p5-28.el7.centos.x86_64
(2)安装:[root@HP111 ~]# yum install ntp

 yum install ntp


rpm -ivh ntp-4.2.6p5-18.el7.centos.x86_64.rpm(没网)
若出现找不到依赖则使用下面的命令

rpm -ivh ntp-4.2.6p5-18.el7.centos.x86_64.rpm --nodeps --force

修改ntp配置文件
[root@HP111 ~]# vi /etc/ntp.conf

nano /etc/ntp.conf


修改内容如下:
(1)修改1(授权192.168.1.0-192.168.1.255网段上的所有机器可以从这台机器上查询和同步时间)
#restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap
改为
restrict 192.168.x.0 mask 255.255.255.0 nomodify notrap
注意:这个网段必须是虚拟机的IP网段,你的网段不一定就是192.168.1.0
(2)修改2(集群在局域网中,不使用其他互联网上的时间)
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 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
(3)添加3(当该节点丢失网络连接,依然可以采用本地时间作为时间服务器为集群中的其他节点提供时间同步)
server 127.127.1.0
fudge 127.127.1.0 stratum 10
(4)修改/etc/sysconfig/ntpd 文件
[root@HP111 ~]# vi /etc/sysconfig/ntpd
增加内容如下(让硬件时间与系统时间一起同步)
SYNC_HWCLOCK=yes
(5)重新启动ntpd服务
注意:CentOS7和CentOS6命令不同
CentOS6用的是:
[root@HP111 ~]#service ntpd status 查看状态
[root@HP111 ~]#service ntpd start 启动 ntpd服务
CentOS7用的是:
[root@HP111 ~]# systemctl status ntpd.service 查看状态
[root@HP111 ~]# systemctl start ntpd.service 启动 ntpd服务
(5)设置ntpd服务开机启动
[root@HP111 ~]# chkconfig ntpd on (CentOS6)
[root@HP111 ~]# systemctl enable ntpd.service(CentOS7)
2. 只需要其他机器配置(必须root用户)其他机器也就是从节点
(1)在其他机器配置10分钟与时间服务器同步一次
[root@HP112 ~]# crontab -e
[root@HP113 ~]# crontab -e
编写定时任务如下:
每十分钟向主节点同步一次

*/10 * * * * /usr/sbin/ntpdate HP111


格外注意: 本次实验是CentOS7,我对着网上视频教程试N遍(视频老师用CentOS6),最后在凌晨1:30才发现这个错误(比较笨,如果不那么急急忙忙看清楚错误应该早一点解决)
CentOS7没有预装ntpdate,导致一直没有时间同步,后来我在从节点安装了ntpdate就完美解决.
对了,防火墙也要关闭.

从节点安装ntpdate:

 yum install ntpdate


(2)修改任意机器时间
[root@HP113 ~]# date -s 2017-9-5

date -s 2017-9-5


(3)十分钟后查看机器是否与时间服务器同步
[root@HP113 ~]# date
 

猜你喜欢

转载自blog.csdn.net/m0_52725750/article/details/130816182