Hadooop分布式集群搭建之--ntp同步集群时间

时间同步方式:hadoop112作为时间服务器,hadoop113、hadoop114定时同步hadoop112的时间,每10分钟同步一次。

配置时间同步具体实操:

一、时间服务器配置(必须root用户)

1、检查ntp是否安装

[root@hadoop112 hadoop]# rpm -qa|grep ntp
fontpackages-filesystem-1.41-1.1.el6.noarch
ntpdate-4.2.6p5-10.el6.centos.x86_64
ntp-4.2.6p5-10.el6.centos.x86_64

2、修改ntp配置文件

[root@hadoop112 hadoop]# vi /etc/ntp.conf

修改内容如下:

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

注意:根据自己虚拟机ip的地址进行调整

打开注销去掉#号 #restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap为
restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap

修改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(当该节点丢失网络连接,依然可以采用本地时间作为时间服务器为集群中的其他节点提供时间同步)
server 127.127.1.0
fudge 127.127.1.0 stratum 10

3、修改/etc/sysconfig/ntpd 文件

[root@hadoop112 hadoop]# vim /etc/sysconfig/ntpd

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

SYNC_HWCLOCK=yes

4、重新启动ntpd服务

[root@hadoop112 hadoop]# service ntpd status
ntpd 已停
[root@hadoop112 hadoop]# service ntpd start
正在启动 ntpd:                                            [确定]

5、设置ntpd服务开机启动

[root@hadoop112 hadoop]# chkconfig ntpd on

二、其他机器配置(必须root用户)

1、在其他机器配置10分钟与时间服务器同步一次

在hadoop113、hadoop114上分别执行以下操作:

 [root@hadoop113 hadoop]# crontab -e

编写定时任务如下:

*/10 * * * * /usr/sbin/ntpdate hadoop112

2、修改任意机器时间

date -s "2016-6-14 13:21:51"

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

[root@hadoop113 hadoop]# date

注:测试的时候可以将10分钟调整为2分钟,节省时间。
hadoop113和hadoop114上的ntpd服务必须是关闭状态,否则无法同步hadoop112的时间。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值