介绍
大数据集群中,不同计算设备之间控制、计算、处理、应用等数据或操作都具有时序性
比如:将1T数据,拆分后存储到不同的服务器中,如果各个服务器的时间不同,那么存储文件的时间也不同,会导致一系列问题,是应用或操作或将无法正常进行。
注意:
大数据系统是对 时间敏感 的计算处理系统,时间同步是大数据能够得到正确处理的基础保障,是大数据得以发挥作用的技术支撑。
同步方式
使用网络时间同步协议(NTP) 实现时间同步
用一台服务器作为时间服务器,其他服务器都与该时间服务器保持时间同步
与 互联网中的时间服务器 保持同步。
在应用中,出于安全的考虑,大数据服务器都在内网,与互联网隔离,所以采用 第一种方式
hadoop1 作为时间服务器
默认时间服务器在互联网,大数据服务器为了 安全,都在内网,连不上互联网,要修改配置,以 hadoop1 作为服务器,其他服务器在不联网的情况下,使用 hadoop1 的时间作为同步时间
hadoop1
查看是否安装 ntp
rpm -qa | grep ntp
没有显示,说明没安装
安装
yum install -y ntp ntpdate
安装 ntp、ntpdate
配置
配置前先备份:
cp /etc/ntp.conf /etc/ntp.conf.bak
编辑文件:
vim /etc/ntp.conf
输入命令显示行号
按 esc 健
按 shift+;
输入 set nu 敲回车,显示行号
修改
将下面4个默认的ntp服务器(21-24行) 注释掉(因为hadoop服务器在局域网,连不上外网):
#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 127.127.1.0 iburst
按 esc 健,按 shift+;,输入 wq 敲回车,保存退出
解释:
iburst: 当server不可达时,以默认发包速率的8倍向服务器发包
使该NTP服务器在不联网的情况下,使用本服务器的时间作为同步时间
启动ntp服务
systemctl start ntpd
或
service ntpd start
查看服务器状态
systemctl status ntpd
或
service ntpd status
显示如下图,说明启动成功:
查看是否同步
ntpq -p
显示如下:
remote refid st t when poll reach delay offset jitter
==============================================================================
*LOCAL(0) .LOCL. 5 l 14 64 37 0.000 0.000 0.000
设置开机启动
关闭 chronyd
需要先关闭 chronyd (也是时间同步服务)开机启动,否则会干扰 npt 开机启动
查看 chronyd 是否开机启动,执行下面命令:
systemctl is-enabled chronyd
显示如下:
enabled
说明 chronyd 开机启动,执行下面命令禁止:
systemctl disable chronyd
开机启动 npt
设置 npt 开机启动
systemctl enable ntpd
测试
执行下面命令,重启系统:
reboot now
启动后,执行下面命令查看 ntpd 是否启动成功:
systemctl status ntpd
显示如下图,说明启动成功:
hadoop2
安装
yum install -y ntp ntpdate
安装 ntp、ntpdate
配置
配置前先备份:
cp /etc/ntp.conf /etc/ntp.conf.bak
编辑文件:
vim /etc/ntp.conf
输入命令显示行号
按 esc 健
按 shift+;
输入 set nu 敲回车,显示行号
修改
将下面4个默认的ntp服务器(21-24行) 注释掉(因为hadoop服务器在局域网,连不上外网):
#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
添加下面部分
#配置上游时间服务器为本地的ntpd Server服务器
server hadoop1 iburst
#配置允许上游时间服务器主动修改本机的时间
restrict hadoop1 nomodify notrap noquery
按 esc 健,按 shift+;,输入 wq 敲回车,保存退出
使该NTP服务器在不联网的情况下,使用 服务器hadoop1 的时间作为同步时间
通过命令与hadoop1同步一下
ntpdate -u hadoop1
需要等几秒,显示如下:
24 Jul 16:52:51 ntpdate[8698]: adjust time server 192.168.58.101 offset 0.001826 sec
启动ntp服务
systemctl start ntpd
或
service ntpd start
查看服务器状态
systemctl status ntpd
或
service ntpd status
显示如下图,说明启动成功:
查看是否同步
ntpq -p
显示如下:
remote refid st t when poll reach delay offset jitter
==============================================================================
*hadoop1 LOCAL(0) 6 u 10 64 1 0.394 10.694 0.078
*hadoop1 表示使用 hadoop1 的时间作为同步时间
设置开机启动
关闭 chronyd
需要先关闭 chronyd (也是时间同步服务)开机启动,否则会干扰 npt 开机启动
查看 chronyd 是否开机启动,执行下面命令:
systemctl is-enabled chronyd
显示如下:
enabled
说明 chronyd 开机启动,执行下面命令禁止:
systemctl disable chronyd
开机启动 npt
开启 npt 开机启动
systemctl enable ntpd
测试
执行下面命令,重启系统:
reboot now
启动后,执行下面命令查看 ntpd 是否启动成功:
systemctl status ntpd
显示如下图,说明启动成功:
hadoop3
操作同hadoop2
