hadoop集群时间同步:设定一台机器为标准时间服务器,其余所有的机器都与这台服务器时间定时同步,eg:每隔10min,同步一次时间。
准备条件:
三台已经安装完成的虚拟机集群hadoop100、hadoop101、hadoop102
单台虚拟机的ip分别为192.168.5.100、192.168.5.101、192.168.5.102
ntp服务协议:
网络时间服务协议(Network Time Protocol, NTP),是用来使计算机时间同步化的一种协议,它可以使计算机对其服务器做时间同步化。
1. 检查ntp是否安装
[kevin@hadoop100 ~]$ rpm -qa|grep ntp
fontpackages-filesystem-1.41-1.1.el6.noarch
ntp-4.2.6p5-10.el6.centos.x86_64
ntpdate-4.2.6p5-10.el6.centos.x86_64
2. 修改ntp配置文件
[kevin@hadoop100 ~]$ sudo vim /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
由于本地三台虚拟机的IP是192.168.5.100-102,
修改为
restrict 192.168.5.0 mask 255.255.255.0 nomodify notrap
(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
3. 修改/etc/sysconfig/ntpd 文件
目的是让硬件时间与系统时间一起同步
[kevin@hadoop100 ~]$ vim /etc/sysconfig/ntpd
增加内容
SYNC_HWCLOCK=yes
4. 设置ntpd服务开机自启
[kevin@hadoop100 ~]$ chkconfig ntpd on
查看ntpd服务状态
[kevin@hadoop100 ~]$ service ntpd status
ntpd (pid 2597) 正在运行...
若ntpd服务关闭,启动
[kevin@hadoop100 ~]$ service ntpd start
5. 其他服务器配置
编写crontab脚本,在其他机器配置每隔10min与标准时间服务器hadoop100同步一次
[kevin@hadoop101 ~]$ crontab -e
[kevin@hadoop102 ~]$ crontab -e
编写定时任务如下,定时10分钟同步一次
*/10 * * * * /usr/sbin/ntpdate hadoop100