本系列文章是基于<<尚硅谷大数据项目之电商数仓>> 写的,软件使用最新稳定版本,后续会详细介绍每个软件的安装配置过程以及使用中遇到的常见问题,软件原理不会做详细介绍(书中已经做了详细的介绍)。使用的技术包括:Java、Spring Boot、Maven、Gradle、Docker、Hadoop、Hive、Sqoop、SQL、BI等。
一、系统规划
服务器 | 操作系统 | CPU | 内存 | 存储 | 带宽 |
Node01 | CentOS / 7.6 x86_64 (64bit) | 4核 | 16G | 100G | 2M |
Node02 | CentOS / 7.6 x86_64 (64bit) | 4核 | 8G | 40G | 2M |
Node03 | CentOS / 7.6 x86_64 (64bit) | 4核 | 8G | 40G | 2M |
二、软件版本
软件 | 版本 |
CentOS | 7.6 |
Java | 1.8.101 |
Hadoop | 3.2.2 |
Zookeeper | 3.5.8 |
Kafka | 2.7.0 |
Flume | 1.9.0 |
Sqoop | 1.4.7 |
Hive | 3.1.2 |
Tez | 0.10.0 |
Azkaban | 3.90.0 |
Superset | 0.38.0 |
三、节点划分
| Node01 | Node02 | Node03 |
Java | √ | √ | √ |
Hadoop | √ | √ | √ |
Zookeeper | √ | √ | √ |
Kafka | √ | √ | √ |
Flume(生产) | √ | √ |
|
Flume(消费) |
|
| √ |
Docker |
| √ | √ |
Mysql |
| √ |
|
Sqool | √ |
|
|
Hive | √ | √ | √ |
Azkaban | √ | √ | √ |
Superset | √ |
|
|
四、约定
- root/all:表示root用户,所有服务器
- root/node01:表示root用户,node01服务器
- jack/node01:表示jack用户,node01服务器
五、系统配置和软件安装
- 修改hostname (root/all)
在每个节点执行,node01 替换为对应节点的hostname
hostnamectl set-hostname node01 |
修改etc/hosts
vi /etc/hosts |
将下列复制到hosts文件中,注释掉之前的ip地址,保留127.0.0.1
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 ::1 localhost localhost.localdomain localhost6 localhost6.localdomain6 #179.0.0.1 instance-h12aj instance-h12aj
179.0.0.1 node01 179.0.0.2 node02 179.0.0.3 node03 |
2. 关闭防火墙 (root/all)
systemctl disable firewalld systemctl stop firewalld |
3. 调整Linux参数 (root/all)
echo 0 > /proc/sys/vm/swappiness echo "vm.swappiness=0" >> /etc/sysctl.conf echo "echo 0 > /proc/sys/vm/swappiness" >> /etc/rc.d/rc.local cat /proc/sys/vm/swappiness
echo "echo never > /sys/kernel/mm/transparent_hugepage/enabled" >> /etc/rc.d/rc.local echo "echo never > /sys/kernel/mm/redhat_transparent_hugepage/defrag" >> /etc/rc.d/rc.local
echo "* soft nofile 128000" >> /etc/security/limits.conf echo "* hard nofile 128000" >> /etc/security/limits.conf echo "* soft nproc 128000" >> /etc/security/limits.conf echo "* hard nproc 128000" >> /etc/security/limits.conf sed -i 's/1024/unlimited/' /etc/security/limits.d/20-nproc.conf ulimit -SHn 128000 ulimit -SHu 128000 |
4. 卸载Mariadb (root/all)
rpm -qa|grep mariadb yum remove mariadb* |
5. 创建目录(root/all
mkdir -p /u01 /u02 |
6. 创建hadoop安装用户 (root/all)
所有服务器都执行相同的命令
1) 创建用户和密码,输入两次密码
[root@node01 ~]# useradd jack [root@node01 ~]# passwd jack Changing password for user jack. New password: Retype new password: passwd: all authentication tokens updated successfully. |
2) 修改sudoers,切换用户时免密码登录。首先给sudoers赋予写的权限,添加红色部分内容
[root@node01 ~]# chmod +w /etc/sudoers [root@node01 ~]# vi /etc/sudoers
## Allow root to run any commands anywhere root ALL=(ALL) ALL jack ALL=(ALL) NOPASSWD:ALL
[root@node01 ~]# chmod -w /etc/sudoers |
3) 更新u01,u02目录的所有者
[root@node01 /]# chown jack:jack /u01 /u02 |
7. 安装jdk (root/all)
1) 下载jdk,选择版本Java SE Development Kit 8u101及以上版本
https://www.oracle.com/java/technologies/javase/javase8-archive-downloads.html
2) 上传到服务器,存放在/u02目录下,其他目录通过scp命令复制jdk文件,选择yes,输入服务器密码
[root@node01 ~]# cd /u02 [root@node01 u02]# ls jdk-8u101-linux-x64.rpm [root@node01 u02]# scp jdk-8u101-linux-x64.rpm root@node02:/u02 [root@node01 u02]# scp jdk-8u101-linux-x64.rpm root@node02:/u03 |
3) 安装jdk,每个节点执行下列命令
[root@node01 u02]# rpm -ivh jdk-8u101-linux-x64.rpm |
4) 配置环境变量
4.1 编辑profile
[root@node01 ~]# vi /etc/profile |
4.2 在export PATH 前添加下列环境变化
[root@node01 ~]# vi /etc/profile |
4.3 生效环境变化
[root@node01 ~]# source /etc/profile |
4.4 验证java是否安装成功
[root@instance-ym97kqz8 ~]# java -version java version "1.8.0_101" Java(TM) SE Runtime Environment (build 1.8.0_101-b13) Java HotSpot(TM) 64-Bit Server VM (build 25.101-b13, mixed mode) |
8. 安装lzo压缩 (root/all)
1) 下载文件
[root@node01 u02]$ wget http://www.oberhumer.com/opensource/lzo/download/lzo-2.10.tar.gz |
2)安装软件
[root@node01 u02]$ tar -zxf lzo-2.10.tar.gz [root@node01 lzo-2.10]$ export CFLAGS=-m64 [root@node01 lzo-2.10]$ yum -y install lzo-devel zlib-devel gcc autoconf automake libtool lzop [root@node01 lzo-2.10]$ ./configure -enable-shared -prefix=/usr/local/hadoop/lzo/ [root@node01 lzo-2.10]$ make && make install |
六、其他软件安装
1、ssh免秘钥登录(jack/node01)
只需在01节点,jack用户执行下列操作
1) 切换到jack用户
[root@node01 ~]# su jack [jack@node01 root]$ cd [jack@node01 ~]$ |
2) 执行命令ssh-keygen -t rsa,生成公钥和私钥,一直按回车即可
[jack@node01 ~]$ ssh-keygen -t rsa Generating public/private rsa key pair. Enter file in which to save the key (/home/jack/.ssh/id_rsa): Created directory '/home/jack/.ssh'. Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in /home/jack/.ssh/id_rsa. Your public key has been saved in /home/jack/.ssh/id_rsa.pub. The key fingerprint is: SHA256:Pjd3XVB5tUmbpiM9rUYrHO6wFNKm51viId1hFs1YWlM jack@node01 The key's randomart image is: +---[RSA 2048]----+ | +.E=| | B oo*| | + o.*.| | . o +. | | .S+ * * ..| | .= B = =..| | ooBo*.+. .| | *oBoo. | | =.. | +----[SHA256]-----+ [jack@node01 ~]$ cd .ssh [jack@node01 .ssh]$ |
3) 执行ssh-copy-id -i将公钥文件传输给远程主机,需要输入远程主机的密码
[jack@node01 .ssh]$ ssh-copy-id -i id_rsa.pub jack@node01 [jack@node01 .ssh]$ ssh-copy-id -i id_rsa.pub jack@node02 [jack@node01 .ssh]$ ssh-copy-id -i id_rsa.pub jack@node03 |
4) 检验是否可以登录远程主机
[jack@node01 .ssh]$ ssh node02 Last login: Mon Nov 30 11:39:37 2020 [jack@node02 ~]$ exit logout Connection to node02 closed. [jack@node01 .ssh]$ ssh node03 [jack@node03 ~]$ exit logout Connection to node03 closed. [jack@node01 .ssh]$ |
2、创建同步程序(jack/node01)
1) 创建目录,在u01下创建bin目录
2) 在bin下创建shell文件,名称:xsync
#!/bin/bash # 判断参数个数 if [ $# -lt 1 ]; then echo "no args."; exit fi
# 遍历服务器 for host in node02 node03 do echo ===================== hadoop $host ================== # 遍历目录 for file in $@ do # 判断文件是否存在 if [ -e $file ]; then # 获取父目录 pdir=$(cd -P $(dirname $file); pwd)
# 获取当前文件的名称 fname=$(basename $file)
ssh $host "mkdir -p $pdir" rsync -av $pdir/$fname $USER@$host:$pdir else echo $file does not exists! fi done done; |
3) 添加执行权限
[jack@node01 bin]$ chmod +x xsync |
七、安装docker(root/node02)
1、安装软件
[root@node02 ~]# yum install -y yum-utils device-mapper-persistent-data lvm2 |
2、安装docker
[root@node02 ~]# yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
[root@node02 ~]# yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
[root@node02 ~]# yum install docker-ce
[root@node02 ~]# systemctl start docker.service [root@node02 ~]# systemctl enable docker.service |
3、配置docker加速
登录阿里云,进入页面:https://cr.console.aliyun.com/cn-hangzhou/instances/mirrors
记录加速器地址,替换下面的******
[root@node02 ~]# sudo tee /etc/docker/daemon.json <<-'EOF' { "registry-mirrors": ["https://*********.mirror.aliyuncs.com"] } EOF
[root@node02 ~]# sudo systemctl daemon-reload [root@node02 ~]# sudo systemctl restart docker |
八、安装mysql(root/node02)
1、从docker 下载Mysql
[root@node02 ~]# docker pull mysql |
2、安装MySql
通过docker ps -a 查看mysql的运行情况,如果状态是Up,表示启动成功
[root@node02 ~]# cd /u01 [root@node02 u01]# mkdir mysql [root@node02 u01]# cd mysql [root@node02 mysql]# docker run -p 3306:3306 --name mymysql -v $PWD/conf:/etc/mysql/conf.d -v $PWD/logs:/logs -v $PWD/data:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=123456 -e TZ=Asia/Shanghai --restart=always -d mysql [root@node02 mysql]# docker ps -a |
3、客户端连接,通过Navicat连接
查看mysql 版本:select version() from dual;