1、准备相应的软件包
链接:https://pan.baidu.com/s/10s-NaFLfztKuWImZTiBMjA 密码:viqp
---声明 资源来自 若泽数据
2、统一时区
[root@bogon ~]# yum install -y ntp
时间必须统一,防止时区错乱导致出错。
设定一hadoop01为时间服务器,hadoop02、hadoop03 时间和hadoop01同步
[root@hadoop01 ~]# vi /etc/ntp.conf
# For more information about this file, see the man pages
# ntp.conf(5), ntp_acc(5), ntp_auth(5), ntp_clock(5), ntp_misc(5), ntp_mon(5).
driftfile /var/lib/ntp/drift
#time
server 0.asia.pool.ntp.org
server 1.asia.pool.ntp.org
server 2.asia.pool.ntp.org
server 3.asia.pool.ntp.org
# 当外部时间不可用,可以使用本地时间
server 127.127.1.0 iburst local clock
# 设置哪些网段的ip可以同步时间
restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap
# Permit time synchronization with our time source, but do not
# permit the source to query or modify the service on this system.
restrict default nomodify notrap nopeer noquery
# Permit all access over the loopback interface. This could
# be tightened as well, but to do so would effect some of
# the administrative functions.
restrict 127.0.0.1
restrict ::1
# Hosts on local network are less restricted.
#restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap
# Use public servers from the pool.ntp.org project.
# Please consider joining the pool (http://www.pool.ntp.org/join.html).
server 0.centos.pool.ntp.org iburst
server 1.centos.pool.ntp.org iburst
server 2.centos.pool.ntp.org iburst
//开启 ntpd
[root@hadoop01 ~]# systemctl start ntpd
[root@hadoop01 ~]# systemclt status ntpd
//验证ntpd
[root@hadoop01 ~]# ntpq -p
remote refid st t when poll reach delay offset jitter
==============================================================================
162.159.200.123 10.12.2.116 3 u 37 64 1 176.664 8.782 0.000
202-65-114-202. 195.66.241.10 2 u 39 64 1 259.655 -72.212 0.000
hkhkg1-ntp-004. .SHM. 1 u 38 64 1 29.584 25.795 0.000
LOCAL(0) .LOCL. 5 l 37 64 1 0.000 0.000 0.000
+a.chl.la 131.188.3.222 2 u 26 64 1 356.952 -0.455 14.579
*119.28.183.184 100.122.36.196 2 u 25 64 1 27.110 20.289 0.340
+h199-182-204-19 17.253.16.125 2 u 24 64 1 285.278 -2.685 42.187
[root@hadoop01 ~]# ntpq -p
hadoop02/hadoop03禁用ntpd服务
[root@hadoop02 ~]# systemctl disable ntpd
[root@hadoop02 ~]# systemctl status ntpd
● ntpd.service - Network Time Service
Loaded: loaded (/usr/lib/systemd/system/ntpd.service; disabled; vendor preset: disabled)
Active: inactive (dead)
[root@hadoop03 ~]# systemctl stop ntpd
[root@hadoop03 ~]# systemctl disable ntpd
[root@hadoop03 ~]# systemctl status ntpd
从hadoop01上同步时间
[root@hadoop01 ~]# /usr/sbin/ntpdate hadoop01
Error resolving hadoop01: Name or service not known (-2)
21 Nov 20:43:30 ntpdate[17859]: Can't find host hadoop01: Name or service not known (-2)
21 Nov 20:43:30 ntpdate[17859]: no servers can be used, exiting
[root@hadoop01 ~]# /usr/sbin/ntpdate 192.168.1.10
21 Nov 20:44:22 ntpdate[17871]: adjust time server 192.168.1.10 offset -0.044055 sec
[root@hadoop02 ~]# /usr/sbin/ntpdate hadoop01
21 Nov 20:50:19 ntpdate[25459]: adjust time server 192.168.1.10 offset -0.058990 sec
----上面出现连接失败的原因是 /etc/hosts 文件并更改别名。导致dns解析找不到对应的ip地址
---设定定时任务,防止时间错乱,每天同步一次
[root@bogon ~]# crontab -e
00 00 * * * /usr/sbin/ntpdate hadoop01
基础环境准备完毕,开始安装软件包。