一. 集群规划
ip | 主机名 | 安装进程 |
---|---|---|
192.168.204.14 | hdp14 | namenode,ZKFC,resourcemanager |
192.168.204.15 | hdp15 | namenode,ZKFC,resourcemanager |
192.168.204.16 | hdp16 | natanode,nodemanager,zookeeper,Journalnode |
192.168.204.17 | hdp17 | natanode,nodemanager,zookeeper,Journalnode |
192.168.204.18 | hdp18 | natanode,nodemanager,zookeeper,Journalnode |
需要5台虚拟机,电脑配置20G以上。
二. 虚拟机环境配置
准备好一台虚拟机,4G内存,50G硬盘,配置好网络,连接Xshell工具
2.1 设置静态ip及主机名修改
root用户添加,修改ip的脚本ip.sh
[root@hdp14 ~]# cd /root/
[root@hdp14 ~]# mdkir bin
[root@hdp14 ~]# vim ip.sh
#添加下面的脚本内容
[root@hdp14 bin]# chmod +x ip.sh
[root@hdp14 bin]# ls
ip.sh
脚本内容
#!/bin/bash
file=/etc/sysconfig/network-scripts/ifcfg-ens33
hostnamectl --static set-hostname hdp14$1
echo "TYPE="Ethernet"" > $file
echo "BOOTPROTO="static"" >> $file
echo "NAME="ens33"" >> $file
echo "DEVICE="ens33"" >> $file
echo "ONBOOT="yes"" >> $file
echo ""IPADDR=192.168.204.$1"" >> $file
echo "PREFIX=24" >> $file
echo "GATEWAY=192.168.204.2" >> $file
echo "DNS1=192.168.204.2" >> $file
echo "DNS2=192.168.0.168" >> $file
#重启
reboot
执行修改语句
[root@hdp14 ~]# ip.sh 14
Invalid number of arguments.
Connection closed by foreign host.
Disconnected from remote host(hdp14149) at 18:24:40.
Type `help' to learn how to use Xshell prompt.
[c:\~]$
2.2 安装必要的环境
sudo yum install -y epel-release
sudo yum install -y psmisc nc net-tools rsync vim lrzsz ntp libzstd openssl-static tree iotop git
注:可使用Xshell工具,开多个窗口,将命令发送到所有会话,也可单台操作后期克隆,这里采用克隆虚拟机的方式
2.3 关闭防火墙和selinucx
关闭防火墙
[root@hdp14 ~]# systemctl stop firewalld
[root@hdp14 ~]# systemctl disable firewalld
关闭selinux
[root@hdp14 ~]# vi /etc/selinux/config
把SELINUX=enforce 改成SELINUX=disabled
2.4 修改hosts文件
vim /etc/hosts
#添加如下内容
192.168.204.10 hdp10
192.168.204.11 hdp11
192.168.204.12 hdp12
192.168.204.13 hdp13
192.168.204.14 hdp14
192.168.204.15 hdp15
192.168.204.16 hdp16
192.168.204.17 hdp17
192.168.204.18 hdp18
192.168.204.19 hdp19
2.5 配置普通用户(along)具有root权限
修改sudoers文件,添加新用户
[root@hdp14 ~]# adduser along
[root@hdp14 ~]# passwd along
修改权限
[root@hdp14 ~]# sudo vim /etc/sudoers
放开这一行:%wheel ALL=(ALL) ALL ,并下面添加一行
along ALL=(ALL) NOPASSWD:ALL
2.6 创建集群安装文件夹
创建/opt/bigdata和/opt/resource文件夹,并赋予along权限
[root@hdp14 ~]# sudo mkdir /opt/bigdata /opt/resource
[root@hdp14 ~]# sudo chown -R along:along /opt/bigdata /opt/resource
2.7 安装jdk1.8 配置环境变量
用along登陆,安装jdk
将jdk的tar包上传到集群的/opt/resource,并解压到/opt/bigdata
tar -zxf /opt/resource/jdk-8u212-linux-x64.tar.gz -C /opt/bigdata/
配置环境变量
sudo vim /etc/profile.d/my_env.sh
注意:这里环境变量不配置到/etc/profile文件中?
查看这个文件
[along@hdp14 hadoop-3.1.4]$ vim /etc/profile
靠前的地方有一段提示
# It's NOT a good idea to change this file unless you know what you
# are doing. It's much better to create a custom.sh shell script in
# /etc/profile.d/ to make custom changes to your environment, as this
# will prevent the need for merging in future updates.
文件末尾添加如下内容
#JAVA_HOME
export JAVA_HOME=/opt/bigdata/jdk1.8.0_212
export PATH=$PATH:$JAVA_HOME/bin
克隆4台虚拟机【hdp15,hdp16,hdp17,hdp18】分别使用ip.sh 脚本修改主机名和ip地址
ip.sh 15
...
2.8 为along,root用户配置免密登陆
每台服务器的root 和along用户都需要配置,以hdp14的root为例
进入用户目录:
[root@hdp14 ~]# ssh-keygen -t ecdsa
连续三次回车,生成公钥和私钥
将公钥复制到目标服务器:
[root@hdp14 opt]# ssh-copy-id hdp14
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_ecdsa.pub"
The authenticity of host 'hdp14 (192.168.204.14)' can't be established.
ECDSA key fingerprint is SHA256:cmFNNQajtQRotZPgk4ZmEFDJPChYRibK26PaCC81/pc.
ECDSA key fingerprint is MD5:d7:0b:cb:9c:0a:04:76:80:aa:37:f9:80:17:e8:4e:6b.
Are you sure you want to continue connecting (yes/no)? yes
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
root@hdp14's password:
Number of key(s) added: 1
Now try logging into the machine, with: "ssh 'hdp14'"
and check to make sure that only the key(s) you wanted were added.
剩余4台,执行相同操作
ssh-copy-id hdp15
ssh-copy-id hdp16
ssh-copy-id hdp17
ssh-copy-id hdp18
重启,along用户登录,重复上面的操作。
2.9 编辑工具脚本
2.9.1 批量发送命令的脚本xcall
#!/bin/bash
hosts=(hdp14 hdp15 hdp16 hdp17 hdp18)
for host in ${hosts[@]}
do
echo =============== $host ===============
ssh $host "$*"
done
添加执行权限,测试脚本
2.9.2 文件分发脚本 axync
#!/bin/bash
#1. 判断参数个数
if [ $# -lt 1 ]
then
echo 请指定要分发的文件!
exit;
fi
#2. 遍历集群所有机器
hosts=(hdp14 hdp15 hdp16 hdp17 hdp18)
for host in ${hosts[@]}
do
echo ==================== $host ====================
#3. 遍历所有目录,挨个发送
for file in $@
do
#4 判断文件是否存在
if [ -e $file ]
then
#5. 获取父目录
pdir=$(cd -P $(dirname $file); pwd)
#6. 获取当前文件的名称
fname=$(basename $file)
ssh $host "mkdir -p $pdir"
rsync -av $pdir/$fname $host:$pdir
else
echo $file 文件不存在!
fi
done
done
添加执行权限
[along@hdp14 bin]$ chmod +x axync
测试脚本
[along@hdp14 bin]$ axync axync
2.10 服务器之间集群同步
全部切换到root用户。
(0)查看所有节点ntpd服务状态和开机自启动状态
[along@hdp14 ~]$ sudo systemctl status ntpd
[along@hdp14 ~]$ sudo systemctl is-enabled ntpd
(1)在所有节点关闭ntp服务和自启动
[along@hdp14 ~]$ sudo systemctl stop ntpd
[along@hdp14 ~]$ sudo systemctl disable ntpd
(2)修改hdp14的ntp.conf配置文件
[along@hdp14 ~]$ sudo vim /etc/ntp.conf
修改内容如下
a)修改1(授权192.168.204.0-192.168.204.255网段上的所有机器可以从这台机器上查询和同步时间)
#restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap
为
restrict 192.168.204.0 mask 255.255.255.0 nomodify notrap
b)修改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
c)添加3(当该节点丢失网络连接,依然可以采用本地时间作为时间服务器为集群中的其他节点提供时间同步)
server 127.127.1.0
fudge 127.127.1.0 stratum 10
(3)修改hdp14的/etc/sysconfig/ntpd 文件
[along@hdp14 ~]$