Hadoop集群时间同步

Hadoop集群时间同步

测试环境

IP 节点角色 主机名
10.10.101.100 master hadoop100
10.10.101.101 node hadoop101
10.10.101.102 node hadoop102

设置master服务器时间

(1)检查ntp是否安装,若没有安装则使用yum install -y ntp进行安装

1
2
3
4
5
6
7
[root@hadoop101 桌面]# rpm -qa|grep ntp

ntp-4.2.6p5-10.el6.centos.x86_64

fontpackages-filesystem-1.41-1.1.el6.noarch

ntpdate-4.2.6p5-10.el6.centos.x86_64

(2)修改ntp配置文件

1
[root@hadoop101 桌面]# vim /etc/ntp.conf

修改内容如下

a)修改1(授权192.168.1.0网段上的所有机器可以从这台机器上查询和同步时间)

1
2
3
#restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap为

restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap

b)修改2(集群在局域网中,不使用其他的网络时间)

1
2
3
4
5
6
7
8
9
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

c)添加3(当该节点丢失网络连接,依然可以作为时间服务器为集群中的其他节点提供时间同步)

1
2
server 127.127.1.0
fudge 127.127.1.0 stratum 10

(3)修改/etc/sysconfig/ntpd 文件

1
[root@hadoop101 桌面]# vim /etc/sysconfig/ntpd

增加内容如下(让硬件时间与系统时间一起同步)

1
SYNC_HWCLOCK=yes

(4)重新启动ntpd

1
2
3
4
5
6
7
[root@hadoop101 桌面]# service ntpd status

ntpd 已停

[root@hadoop101 桌面]# service ntpd start

正在启动 ntpd: [确定]

(5)设置开机自启动:

1
[root@hadoop101 桌面]# chkconfig ntpd on

node配置(必须root用户)

(1)在node配置10分钟与时间服务器同步一次

1
2
3
4
5
[root@hadoop102 hadoop-2.7.2]# crontab -e

#添加如下任务

*/10 * * * * /usr/sbin/ntpdate hadoop101

(2)修改任意node时间

1
[root@hadoop102 root]# date -s "2017-9-11 11:11:11"

(3)十分钟后查看机器是否与时间服务器同步

1
[root@hadoop102 root]# date