hadoop3.x集群部署-准备linux环境-时间同步 作者:马育民 • 2021-07-24 16:11 • 阅读:10325 # 介绍 大数据集群中,不同计算设备之间控制、计算、处理、应用等数据或操作都具有时序性 比如:将1T数据,拆分后存储到不同的服务器中,如果各个服务器的时间不同,那么存储文件的时间也不同,会导致一系列问题,是应用或操作或将无法正常进行。 ### 注意: 大数据系统是对 **时间敏感** 的计算处理系统,时间同步是大数据能够得到正确处理的基础保障,是大数据得以发挥作用的技术支撑。 ### 同步方式 使用网络时间同步协议(NTP) 实现时间同步 1. 用一台服务器作为时间服务器,其他服务器都与该时间服务器保持时间同步 2. 与 互联网中的时间服务器 保持同步。 在应用中,出于安全的考虑,大数据服务器都在内网,与互联网隔离,所以采用 **第一种方式** # hadoop1 将hadoop1做为 **时间服务器**,让 hadoop2、hadoop3的时间 与 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 ``` 将下面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 ``` **解释:** - `iburst` : 当server不可达时,以默认发包速率的8倍向服务器发包 保存退出 使该NTP服务器在不联网的情况下,使用本服务器的时间作为同步时间 ### 启动ntp服务 ``` systemctl start ntpd ``` 或 ``` service ntpd start ``` ### 查看服务器状态 ``` systemctl status ntpd ``` 或 ``` service ntpd status ``` 显示如下图,说明启动成功: [](https://www.malaoshi.top/upload/pic/linux/Snipaste_2021-07-24_16-34-35.png) ### 查看是否同步 ``` 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 ``` [参数说明](https://www.malaoshi.top/show_1IX1Y8f12kaZ.html "参数说明") ## 设置开机启动 ### 关闭 chronyd 需要先关闭 `chronyd` (也是时间同步服务)开机启动,否则会干扰 `npt` 开机启动 查看 `chronyd` 是否开机启动,执行下面命令: ``` systemctl is-enabled chronyd ``` 显示如下: ``` enabled ``` 说明 `chronyd` 开机启动,执行下面命令禁止: ``` systemctl disable chronyd ``` ### 开机启动 npt 设置 `npt` 开机启动 ``` systemctl enable ntpd ``` ### 测试 执行下面命令,重启系统: ``` reboot now ``` 启动后,执行下面命令查看 ntpd 是否启动成功: ``` systemctl status ntpd ``` 显示如下图,说明启动成功: [](https://www.malaoshi.top/upload/pic/linux/Snipaste_2021-07-24_16-34-35.png) # hadoop2 ### 安装 ``` yum install -y ntp ntpdate ``` 安装 ntp、ntpdate ### 配置 配置前先备份: ``` cp /etc/ntp.conf /etc/ntp.conf.bak ``` 编辑文件: ``` vim /etc/ntp.conf ``` 将下面4行注释掉: ``` #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 ``` 保存退出 使该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 ``` 显示如下图,说明启动成功: [](https://www.malaoshi.top/upload/pic/linux/Snipaste_2021-07-24_16-34-35.png) ### 查看是否同步 ``` 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 ``` 显示如下图,说明启动成功: [](https://www.malaoshi.top/upload/pic/linux/Snipaste_2021-07-24_16-34-35.png) # hadoop3 操作同hadoop2 原文出处:http://www.malaoshi.top/show_1IX1Y7hXooOl.html