目录
一、Ambari 简介
二、软件准备
1. 软件要求
2. Ambari 软件包下载
三、搭建HDP集群
1. 搭建 Master 节点
1.1 新建虚拟机
1.2 配置虚拟机网络
1.3 关闭防火墙 firewalld 和 Selinux
1.4 修改host
1.5 设置阿里云的yum源
1.6 安装时间同步服务 NTP
1.7 安装并配置JDK
1.8 禁用 Transparent Huge Pages
2. 克隆虚拟机
2.1 修改参数
2.2 最大打开文件要求
2.3 配置虚拟机免密登录ssh
四、在Master节点上安装配置 MySQL数据库
1. 安装MySQL数据库
2. 在mysql数据库中创建相应的User和DB
五、安装Nginx httpd
六、配置本地 Repo
七、安装Ambari
1. Master节点安装 Ambari-Server
2. 访问Ambari web页面
3. 安装集群
4. 自动安装各个节点的Ambari-Agent
5. 完成集群部署
八、参考文档
Ambari为您的集群提供了端到端的管理和监视解决方案。使用Ambari Web UI和REST API,您可以从中心位置部署,操作,管理配置更改以及监视群集中所有节点的服务。
注意:Ambari 2.7.4仅支持HDP-3.1.4和HDF-3.2.0,并且JDK必须满足 JDK1.8
可以通过这个网站 https://supportmatrix.hortonworks.com 来确定 Ambari 不同版本对不同产品版本的支持。
组件 | 描述 |
---|---|
虚拟操作系统 | Centos 7.6 |
Ambari | 2.7.4.0 |
HDP | 3.1.4.0 |
HDP-GPL | 3.1.4.0 |
HDP-UTILS | 1.1.0.22 |
MySQL | 5.7 |
OracleJDK8 | JDK 1.8.0_77 |
X86 | X86-64 |
Ambari 2.7.4:http://public-repo-1.hortonworks.com/ambari/centos7/2.x/updates/2.7.4.0/ambari-2.7.4.0-centos7.tar.gz
HDP-3.1.4.0:
OracleJDK8 1.8.0_77:https://www.oracle.com/technetwork/cn/java/javase/downloads/java-archive-javase8-2177648-zhs.html
Hostname | IP | Functions | 内存 | 磁盘 |
---|---|---|---|---|
zh-master.hdp | 192.168.121.77 |
|
3G | 60G |
zh-node1.hdp | 192.168.121.100 |
|
2G | 60G |
搭建 Master 节点的虚拟机,然后进行克隆,完成HDP集群的基础环境搭建。
参考:VMware创建Centos 7 虚拟机
搭建HDP集群时最好配置静态网络,防止IP地址的变化造成搭建错误。
虚拟机最好是能联通外网,简单来说就是 虚拟机能ping 通百度,这样我们就可以直接配置yum源进行安装包下载。
参考:
entos7网卡配置——动态与静态
VMware Centos 7虚拟机 网络配置
// 暂停防火墙服务
# systemctl stop firewalld.service
// 设置防火墙服务开机不自启
# systemctl disable firewalld.service
Removed symlink /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
// 查看防火墙服务开机不自启是否设置成功,disabled表示设置成功
# systemctl is-enabled firewalld.service
disabled
// 查看防火墙状态
# systemctl status firewalld.service
修改selinux的enforcing为disabled
// 将文件中的enforcing替换为disabled,并删除文件中的#注释和空行
# sed -i -e 's/enforcing/disabled/g' -e '/^#/d' -e '/^$/d' /etc/selinux/config
// 临时生效selinux设置
# setenforce 0
// 查看selinux状态
# getenforce
Permissive
// 查看selinux状态
# sestatus
SELinux status: enabled
SELinuxfs mount: /sys/fs/selinux
SELinux root directory: /etc/selinux
Loaded policy name: targeted
Current mode: permissive
Mode from config file: disabled
Policy MLS status: enabled
Policy deny_unknown status: allowed
Max kernel policy version: 31
# echo -e "192.168.200.10 zh-master.hdp zh-master \n192.168.200.20 zh-node1.hdp zh-node1" >> /etc/hosts
访问:https://opsx.alibaba.com/mirror
选择 centos 点击 帮助
提示:wget 命令需要下载,建议使用 curl -o
// 备份yum源
# mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
// 下载阿里云repo文件
# curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
// 生成缓存
# yum makecache
// 安装 ntp 服务
# yum install -y ntp
// 开启并设置开机自启ntp服务
# systemctl start ntpd
# systemctl enable ntpd
// 查看ntp服务状态
# systemctl status ntpd
将文件拖入命令行便可传输
// 创建java环境目录
# mkdir /usr/java
// 将安装包解压至/usr/java目录
# tar -zxvf jdk-8u77-linux-x64.tar.gz -C /usr/java/
配置环境变量
// 对文件进行备份
# cp /etc/profile /etc/profile.bak
// 添加环境变量,注意下面四行是一条命令
# sudo tee -a /etc/profile << 'EOF'
export JAVA_HOME=/usr/java/jdk1.8.0_77
export PATH=$PATH:$JAVA_HOME/bin
EOF
// 生效环境变量
# source /etc/profile
// 验证java环境
# java -version
java version "1.8.0_77"
Java(TM) SE Runtime Environment (build 1.8.0_77-b03)
Java HotSpot(TM) 64-Bit Server VM (build 25.77-b03, mixed mode)
操作系统后台有一个叫做 khugepaged 的进程,它会一直扫描所有进程占用的内存,在可能的情况下会把 4kpage 交换为 Huge Pages,在这个过程中,对于操作的内存的各种分配活动都需要各种内存锁,直接影响程序的内存访问性能,并且,这个过程对于应用是透明的,在应用层面不可控制,对于专门为 4k page 优化的程序来说,可能会造成随机的性能下降现象。
简单来说,如果不关闭THP,Hadoop的系统CPU使用率就会很高。
# cat /sys/kernel/mm/transparent_hugepage/defrag
[always] madvise never
# cat /sys/kernel/mm/transparent_hugepage/enabled
[always] madvise never
// 向文件末尾添加一个脚本,注意下面八行是一条命令
# sudo tee -a /etc/rc.d/rc.local << 'EOF'
if test -f /sys/kernel/mm/transparent_hugepage/enabled; then
echo never > /sys/kernel/mm/transparent_hugepage/enabled
fi
if test -f /sys/kernel/mm/transparent_hugepage/defrag; then
echo never > /sys/kernel/mm/transparent_hugepage/defrag
fi
EOF
// 赋予文件可执行权限
# chmod +x /etc/rc.d/rc.local
基础环境搭建完成后,重启虚拟机
# reboot
修改克隆出来的所有虚拟机mac地址,重新生成两张网卡的mac地址
# hostnamectl set-hostname zh-node1
Ctrl+D 退出登录后可看见自己修改的hostname
内网网卡
// 修改 IPADDR 字段,不能与其他虚拟机网卡冲突
# vi /etc/sysconfig/network-scripts/ifcfg-ens33
TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=static
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
IPV6_ADDR_GEN_MODE=stable-privacy
NAME=ens33
UUID=4f6fc668-7330-4e63-b490-bf62d6a313cd
DEVICE=ens33
ONBOOT=yes
IPADDR=192.168.100.20
PREFIX=24
外网网卡
// 修改 IPADDR 字段,不能与其他虚拟机网卡冲突
# vi /etc/sysconfig/network-scripts/ifcfg-ens34
TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=static
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
IPV6_ADDR_GEN_MODE=stable-privacy
NAME=ens34
UUID=0ebca8db-c64d-431c-937c-12d509b9523f
DEVICE=ens34
ONBOOT=yes
IPADDR=192.168.200.20
PREFIX=24
GATEWAY=192.168.200.2
DNS1=114.114.114.114
DNS2=114.114.115.115
重启网卡,验证网络
// 重启网络
# service network restart
Restarting network (via systemctl): [ OK ]
// 查看网卡
# ip addr
// ping百度进行验证
# ping -c2 www.baidu.com
PING www.a.shifen.com (39.156.66.18) 56(84) bytes of data.
64 bytes from 39.156.66.18 (39.156.66.18): icmp_seq=1 ttl=128 time=227 ms
64 bytes from 39.156.66.18 (39.156.66.18): icmp_seq=2 ttl=128 time=130 ms
--- www.a.shifen.com ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1002ms
rtt min/avg/max/mdev = 130.347/179.004/227.661/48.657 ms
// master节点
# ping -c4 zh-node1
// node1节点
# ping -c4 zh-master
注:Master、node节点均需操作,重启后失效
建议的最大打开文件描述符数为10000或更多。要检查为最大打开文件描述符数设置的当前值,请在每个主机上执行以下shell命令:
# ulimit -Sn
# ulimit -Hn
如果输出不大于10000,请运行以下命令将其设置为合适的默认值:
# ulimit -n 10000
注:Master、node1节点均需设置
修改物理机的 hosts 文件,文件位置在 C:\Windows\System32\drivers\etc 目录下。
编解 hosts 文件,添加以下三行
# VMware hosts End
192.168.200.10 zh-master.hdp zh-master
192.168.200.20 zh-node1.hdp zh-node1
输入命令后,一直回车
# ssh-keygen -t rsa
两个节点相互传递公钥
// Master节点
# ssh-copy-id -i /root/.ssh/id_rsa.pub root@zh-node1
# cat /root/.ssh/id_rsa.pub >> /root/.ssh/authorized_keys
# scp /root/.ssh/id_rsa.pub zh-node1:/root/
// Node1节点
# ssh-copy-id -i /root/.ssh/id_rsa.pub root@zh-master
# cat /root/id_rsa.pub >> /root/.ssh/authorized_keys
// 在master、node1节点 执行
# ls /root/.ssh/
# cat /root/.ssh/authorized_keys
出现如下结果则表示配置正确
// 在sshd_config文件内添加
# vi /etc/ssh/sshd_config
RSAAuthentication yes
PubkeyAuthentication yes
重启sshd服务,生效配置
# systemctl restart sshd
// 先安装 wget 命令
# yum install -y wget
// 下载 Mysql RPM包
# wget -i -c http://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm
// 安装MySQL RPM包
# yum install -y mysql57-community-release-el7-10.noarch.rpm
// 安装MySQL和 Mysql-java连接器
# yum -y install mysql-community-server mysql-connector-java
// 查看下载后的jar包,看目录中是否有mysql-connector-java:
# ls /usr/share/java
// 启动Mysql服务
# systemctl start mysqld.service
// 查看Mysql服务状态
# systemctl status mysqld.service
// 设置Mysql服务开机自启
# systemctl enable mysqld.service
此时MySQL已经开始正常运行,不过要想进入MySQL还得先找出此时root用户的密码,通过如下命令可以在日志文件中找出密码:
# cat /var/log/mysqld.log | grep password
登录mysql,输入密码 q&gL2k?>zOeE 密码没有空格
# mysql -uroot -p
Enter password: // 建议密码复制粘贴,没有空格,明文无法登录
输入初始密码,此时不能做任何事情,因为MySQL默认必须修改密码之后才能操作数据库
// 设置MySQL密码安全强度为0,最低长度为1
set global validate_password_policy=0;
set global validate_password_length=1;
// 修改root用户密码
ALTER USER 'root'@'localhost' IDENTIFIED BY '123456';
// 为root用户授予所有权限并设置本地登录
grant all privileges on *.* to 'root'@'localhost' identified by '123456';
// 为root用户授予所有权限并设置远程登录
grant all privileges on *.* to 'root'@'%' identified by '123456';
// 刷新权限系统
flush privileges;
由于安装了Yum Repository,以后每次yum操作都会自动更新,需要把这个卸载掉
# yum -y remove mysql57-community-release-el7-10.noarch
# mysql -uroot -p123456
mysql> create database ambari character set utf8;
Query OK, 1 row affected (0.02 sec)
mysql> CREATE USER 'ambari'@'%'IDENTIFIED BY '123456';
Query OK, 0 rows affected (0.01 sec)
mysql> GRANT ALL PRIVILEGES ON ambari.* TO 'ambari'@'%';
Query OK, 0 rows affected (0.00 sec)
mysql> create database hive character set utf8;
Query OK, 1 row affected (0.00 sec)
mysql> CREATE USER 'hive'@'%'IDENTIFIED BY '123456';
Query OK, 0 rows affected (0.00 sec)
mysql> GRANT ALL PRIVILEGES ON hive.* TO 'hive'@'%';
Query OK, 0 rows affected (0.00 sec)
mysql> create database oozie character set utf8;
Query OK, 1 row affected (0.00 sec)
mysql> CREATE USER 'oozie'@'%'IDENTIFIED BY '123456';
Query OK, 0 rows affected (0.00 sec)
mysql> GRANT ALL PRIVILEGES ON oozie.* TO 'oozie'@'%';
Query OK, 0 rows affected (0.00 sec)
使用MySQL时,用于Ranger管理策略存储表的存储引擎必须支持事务。InnoDB是支持事务的引擎的示例。不支持事务的存储引擎不适合用作策略存储。
应该使用MySQL数据库管理员来创建Ranger数据库。
以下一系列命令可用于
rangerdba
使用password 创建 用户rangerdba
。以root用户身份登录,然后使用以下命令创建该
rangerdba
用户并为其授予足够的特权。
mysql> CREATE DATABASE ranger;
Query OK, 0 rows affected (0.00 sec)
mysql> CREATE USER 'rangerdba'@'localhost' IDENTIFIED BY 'rangerdba';
Query OK, 0 rows affected (0.00 sec)
mysql> GRANT ALL PRIVILEGES ON *.* TO 'rangerdba'@'localhost';
Query OK, 0 rows affected (0.00 sec)
mysql> CREATE USER 'rangerdba'@'%' IDENTIFIED BY 'rangerdba';
Query OK, 0 rows affected (0.00 sec)
mysql> GRANT ALL PRIVILEGES ON *.* TO 'rangerdba'@'%';
Query OK, 0 rows affected (0.00 sec)
mysql> GRANT ALL PRIVILEGES ON *.* TO 'rangerdba'@'localhost' WITH GRANT OPTION;
Query OK, 0 rows affected (0.00 sec)
mysql> GRANT ALL PRIVILEGES ON *.* TO 'rangerdba'@'%' WITH GRANT OPTION;
Query OK, 0 rows affected (0.00 sec)
mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)
注:以下步骤在 Node1节点 执行
1. 下载 Nginx
# yum install -y epel-release
# yum install -y nginx
2. 修改 /etc/nginx/nginx.conf 文件
// 对文件进行备份
# cp /etc/nginx/nginx.conf /etc/nginx/nginx.conf.bak
# vi /etc/nginx/nginx.conf
autoindex on;
autoindex_exact_size on;
autoindex_localtime on;
root ambari;
3. 启动并设置开机自启Nginx服务
# systemctl start nginx
# systemctl enable nginx
4. 新建文件夹
# mkdir /usr/share/nginx/ambari
5. 上传 Ambari安装包、HDP安装包 至nginx
# tar -zxvf HDP-GPL-3.1.4.0-centos7-gpl.tar.gz -C /usr/share/nginx/ambari/
# tar -zxvf HDP-3.1.4.0-centos7-rpm.tar.gz -C /usr/share/nginx/ambari/
# tar -zxvf HDP-UTILS-1.1.0.22-centos7.tar.gz -C /usr/share/nginx/ambari/
# tar -zxvf ambari-2.7.4.0-centos7.tar.gz -C /usr/share/nginx/ambari/
注:以下步骤在 Node1节点 执行
1. 下载相关 yum 工具
# yum install -y yum-utils
# yum repolist
# yum install -y createrepo wget
2. 配置 Ambari Repo
// 下载2.7.4.0版本的ambari.repo
# wget -O /etc/yum.repos.d/ambari.repo http://public-repo-1.hortonworks.com/ambari/centos7/2.x/updates/2.7.4.0/ambari.repo
3. 修改 ambari.repo 配置文件
修改 baseurl 选项,将http地址换为我们的nginx地址
# vi /etc/yum.repos.d/ambari.repo
如果你是按照我的博客配置的 Nginx ,你也可以复制粘贴我的 ambari.repo 配置文件进行修改
#VERSION_NUMBER=2.7.4.0-118
[ambari-2.7.4.0]
#json.url = http://public-repo-1.hortonworks.com/HDP/hdp_urlinfo.json
name=ambari Version - ambari-2.7.4.0
baseurl=http://192.168.200.20/ambari/centos7/2.7.4.0-118/
gpgcheck=1
gpgkey=http://192.168.200.20/ambari/centos7/2.7.4.0-118/RPM-GPG-KEY/RPM-GPG-KEY-Jenkins
enabled=1
priority=1
4. 添加 HDP.repo 配置文件
# vi /etc/yum.repos.d/HDP.repo
添加如下内容
#VERSION_NUMBER=3.1.4.0-315
[HDP-3.1.4.0-315]
name=HDP Version - HDP-3.1.4.0-315
baseurl=http://192.168.200.20/HDP/centos7
gpgcheck=1
gpgkey=http://192.168.200.20/HDP/centos7/3.1.4.0-315/RPM-GPG-KEY/RPM-GPG-KEY-Jenkins
enabled=1
priority=1
[HDP-UTILS-1.1.0.22]
name=HDP-UTILS Version - HDP-UTILS-1.1.0.22
baseurl=http://192.168.200.20/HDP-UTILS/
gpgcheck=1
gpgkey=http://192.168.200.20/HDP-UTILS/centos7/1.1.0.22/RPM-GPG-KEY/RPM-GPG-KEY-Jenkins
enabled=1
priority=1
5. 将 Repo 配置文件分发至各个节点
# scp /etc/yum.repos.d/ambari.repo /etc/yum.repos.d/HDP.repo zh-master:/etc/yum.repos.d/
6. 生成本地源
使用createrepo命令,创建yum本地源(软件仓库),即为存放本地特定位置的众多rpm包建立索引,描述各包所需依赖信息,并形成元数据。
# createrepo /usr/share/nginx/ambari/HDP/centos7/
# createrepo /usr/share/nginx/ambari/HDP-UTILS/
[root@zh-master ~]# yum install -y ambari-server
[root@zh-master ~]# ambari-server setup
Using python /usr/bin/python
Setup ambari-server
Checking SELinux...
SELinux status is 'disabled'
Customize user account for ambari-server daemon [y/n] (n)? y
Enter user account for ambari-server daemon (root):root # 用户
Adjusting ambari-server permissions and ownership...
Checking firewall status...
Checking JDK...
[1] Oracle JDK 1.8 + Java Cryptography Extension (JCE) Policy Files 8
[2] Custom JDK
==============================================================================
Enter choice (1): 2 # 选择自定义jdk
WARNING: JDK must be installed on all hosts and JAVA_HOME must be valid on all hosts.
WARNING: JCE Policy files are required for configuring Kerberos security. If you plan to use Kerberos,please make sure JCE Unlimited Strength Jurisdiction Policy Files are valid on all hosts.
Path to JAVA_HOME: /usr/java/jdk1.8.0_77 # jdk安装路径
Validating JDK on Ambari Server...done.
Check JDK version for Ambari Server...
JDK version found: 8
Minimum JDK version is 8 for Ambari. Skipping to setup different JDK for Ambari Server.
Checking GPL software agreement...
GPL License for LZO: https://www.gnu.org/licenses/old-licenses/gpl-2.0.en.html
Enable Ambari Server to download and install GPL Licensed LZO packages [y/n] (n)? y
Completing setup...
Configuring database...
Enter advanced database configuration [y/n] (n)? y
Configuring database...
==============================================================================
Choose one of the following options:
[1] - PostgreSQL (Embedded)
[2] - Oracle
[3] - MySQL / MariaDB
[4] - PostgreSQL
[5] - Microsoft SQL Server (Tech Preview)
[6] - SQL Anywhere
[7] - BDB
==============================================================================
Enter choice (1): 3 # 选择安装的mysql
Hostname (localhost): zh-master # 输入Master节点的hostname
Port (3306): # 默认
Database name (ambari):
Username (ambari):
Enter Database Password (bigdata): # 密码不显示
Re-enter password:
Configuring ambari database...
Should ambari use existing default jdbc /usr/share/java/mysql-connector-java.jar [y/n] (y)? y
Configuring remote database connection properties...
WARNING: Before starting Ambari Server, you must run the following DDL directly from the database shell to create the schema: /var/lib/ambari-server/resources/Ambari-DDL-MySQL-CREATE.sql # 此处需注意,启动ambari之前需要执行此句
Proceed with configuring remote database connection properties [y/n] (y)? y
Extracting system views...
ambari-admin-2.7.3.0.139.jar
....
Ambari repo file contains latest json url http://public-repo-1.hortonworks.com/HDP/hdp_urlinfo.json, updating stacks repoinfos with it...
Adjusting ambari-server permissions and ownership...
Ambari Server 'setup' completed successfully. # 安装成功
[root@zh-master ~]# mysql -u ambari -p -h zh-master
// 切换数据库
mysql> use ambari;
Database changed
mysql> source /var/lib/ambari-server/resources/Ambari-DDL-MySQL-CREATE.sql;
// 执行完,查看有无报错信息,并查看数据表
mysql> show tables;
如果启动失败,尝试重新启动
[root@zh-master ~]# ambari-server start
[root@zh-master ~]# ambari-server restart
Using python /usr/bin/python
Restarting ambari-server
Waiting for server stop...
Ambari Server stopped
Ambari Server running with administrator privileges.
Organizing resource files at /var/lib/ambari-server/resources...
Ambari database consistency check started...
Server PID at: /var/run/ambari-server/ambari-server.pid
Server out at: /var/log/ambari-server/ambari-server.out
Server log at: /var/log/ambari-server/ambari-server.log
Waiting for server start...................................
Server started listening on 8080
DB configs consistency check: no errors and warnings were found.
默认端口8080,Username:admin;Password:admin;http://192.168.200.10:8080
HDP-3.1:http://192.168.200.20/HDP/centos7/
HDP-3.1-GPL:http://192.168.200.20/HDP-GPL/centos7/3.1.4.0-315/
HDP-UTILS-1.1.0.22:http://192.168.200.20/HDP-UTILS/centos7/1.1.0.22/
// 查看Master节点的密钥内容
[root@zh-master ~]# cat /root/.ssh/id_rsa
注意:注册主机的 hostname 的填写格式为 主机名.后缀的形式
例如我的虚拟机的 /etc/hosts 文件填写的是
那么注册主机的 hostname 就应该填写zh-master.hdp 与 zh-node1.hdp
若在注册过程中遇到 ssh 拒绝访问 问题,请参考:
https://blog.csdn.net/wang_zhenwei/article/details/53955871
https://blog.csdn.net/wang_zhenwei/article/details/53105390
自己选择安装 hadoop 组件,这里由于电脑性能,我只选择了几个较为基础的服务作为测试
[root@zh-master ~]# ambari-server setup --jdbc-db=mysql --jdbc-driver=/usr/share/java/mysql-connector-java.jar
Using python /usr/bin/python
Setup ambari-server
Copying /usr/share/java/mysql-connector-java.jar to /var/lib/ambari-server/resources/mysql-connector-java.jar
If you are updating existing jdbc driver jar for mysql with mysql-connector-java.jar. Please remove the old driver jar, from all hosts. Restarting services that need the driver, will automatically copy the new jar to the hosts.
JDBC driver was successfully initialized.
Ambari Server 'setup' completed successfully.
https://docs.cloudera.com/HDPDocuments/Ambari-2.7.4.0/bk_ambari-installation/content/ch_Getting_Ready.html
https://blog.csdn.net/Happy_Sunshine_Boy/article/details/86595945#commentBox