一、概述
Apache Ambari
是 Hortonworks 贡献给Apache开源社区的顶级项目,它是一个基于web的工具,用于装置、装备、管理和监督 Hadoop 集群。 Ambari 目前已支持大多数 Hadoop 组件,包括 HDFS、MapReduce、Hive、Pig、 Hbase、Zookeper、Sqoop 和 Hcatalog 等。
想了解更多 Apache Ambari 可以阅读我这篇文章:【大数据】大数据 Hadoop 管理工具 Apache Ambari(HDP)
二、前期准备
1)布置 docker
# 装置yum-config-manager装备工具
yum -y install yum-utils
# 建议运用阿里云yum源:(引荐)
#yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
# 装置docker-ce版别
yum install -y docker-ce
# 发动并开机发动
systemctl enable --now docker
docker --version
2)布置 docker-compose
curl -SL https://github.com/docker/compose/releases/download/v2.16.0/docker-compose-linux-x86_64 -o /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose
docker-compose --version
三、Apache Ambari 编排布置
1)获取 Ambari 装置包
编译过程中可能会遇到许多问题,这里就不一一列举了,可关注我大众号 大数据与云原生技术共享
回复 hdp
获取已编译好的装置包。
其间装置包说明:
-
Ambari
:WEB应用程序,后台为Ambari Server,担任与HDP布置的集群作业节点进行通讯,集群操控节点包括Hdfs,Spark,Zk,Hive,Hbase等等。 -
HDP
:HDP包中包含了许多常用的工具,比如Hadoop,Hive,Hbase,Spark等 -
HDP-UTIL
:是HDP的另一个软件包,它包含了一些额外的实用工具和服务,用于增强HDP的功用和管理能力。这些实用工具和服务可以与HDP集群一起运用,以提供更多的功用和工具支持。 -
HDP-GPL
:是HDP的一部分,它包含了HDP中运用的开源软件的源代码,这些软件遵循GPL(GNU通用公共许可证)或其他开源许可证。
2)yum 源装备文件
【温馨提示】留意修正成自己的ip
ambari.repo
#VERSION_NUMBER=2.7.5.0-72
[ambari-2.7.5.0]
#json.url = http://public-repo-1.hortonworks.com/HDP/hdp_urlinfo.json
name=ambari Version - ambari-2.7.5.0
baseurl=http://httpd:18080/ambari/centos7/2.7.5.0-72/
gpgcheck=1
gpgkey=http://httpd:18080/ambari/centos7/2.7.5.0-72/RPM-GPG-KEY/RPM-GPG-KEY-Jenkins
enabled=1
priority=1
hdp.repo
#VERSION_NUMBER=3.1.5.0-152
[HDP-3.1.5.0]
name=HDP Version - HDP-3.1.5.0
baseurl=http://httpd:18080/HDP/centos7/3.1.5.0-152/
gpgcheck=1
gpgkey=http://httpd:18080/HDP/centos7/3.1.5.0-152/RPM-GPG-KEY/RPM-GPG-KEY-Jenkins
enabled=1
priority=1
[HDP-UTILS-1.1.0.22]
name=Hortonworks Data Platform Utils Version - HDP-UTILS-1.1.0.22
baseurl=http://httpd:18080/HDP-UTILS/centos7/1.1.0.22/
gpgcheck=1
gpgkey=http://httpd:18080/HDP-UTILS/centos7/1.1.0.22/RPM-GPG-KEY/RPM-GPG-KEY-Jenkins
enabled=1
priority=1
3)用户和库初始化sql文件
init.sql
# 创立数据库
CREATE DATABASE IF NOT EXISTS ambari default charset utf8 COLLATE utf8_general_ci;
CREATE DATABASE IF NOT EXISTS hive default charset utf8 COLLATE utf8_general_ci;
CREATE DATABASE IF NOT EXISTS oozie default charset utf8 COLLATE utf8_general_ci;
# 创立 ambari 用户
CREATE USER 'ambari'@'%'IDENTIFIED BY 'ambari';
GRANT ALL PRIVILEGES ON ambari.* TO 'ambari'@'%';
#创立 hive用户
CREATE USER 'hive'@'%'IDENTIFIED BY 'hive';
GRANT ALL PRIVILEGES ON hive.* TO 'hive'@'%';
# 创立 oozie 用户
CREATE USER 'oozie'@'%'IDENTIFIED BY 'oozie';
GRANT ALL PRIVILEGES ON *.* TO 'oozie'@'%';
FLUSH PRIVILEGES;
4)发动脚本 bootstrap.sh
#!/bin/bash
mysql_host=mysql-test
mysql_passwd=123456
mysql_port=3306
ambari_db=ambari
ambari_username=ambari
ambari_password=ambari
java_home=/opt/apache/jdk1.8.0_212
mysql_driver=/usr/share/java/mysql-connector-java-5.1.39.jar
wait_for() {
echo Waiting for $1 to listen on $2...
while ! nc -z $1 $2; do echo waiting...; sleep 1s; done
}
setup_ambari() {
# 强制替换文件
cp -f /tmp/dbConfiguration.py /lib/ambari-server/lib/ambari_server/dbConfiguration.py
yum -y install expect >/dev/null 2>&1
expect -c "
set timeout -1;
spawn ambari-server setup;
expect {
continue* {send -- y\r;exp_continue;}
Customize* {send -- y\r;exp_continue;}
Change* {send -- n\r;exp_continue;}
daemon* {send -- ambari\r;exp_continue;}
change* {send -- y\r;exp_continue;}
choice* {send -- 2\r;exp_continue;}
JAVA_HOME* {send -- $java_home\r;exp_continue;}
LZO* {send -- y\r;exp_continue;}
configuration* {send -- y\r;exp_continue;}
choice* {send -- 2\r;exp_continue;}
Hostname* {send -- ${mysql_host}\r;exp_continue;}
Port* {send -- ${mysql_port}\r;exp_continue;}
Database* {send -- ${ambari_db}\r;exp_continue;}
Username* {send -- ${ambari_username}\r;exp_continue;}
Password* {send -- ${ambari_password}\r;exp_continue;}
Re-enter* {send -- ${ambari_password}\r;exp_continue;}
driver* {send -- ${mysql_driver}\r;exp_continue;}
connection* {send -- y\r;exp_continue;}
eof {exit 0;}
};"
}
# wait for mysql and httpd
wait_for mysql-test 3306
wait_for httpd 80
# 开端ambari装置
yum -y install ambari-server
re=`mysql -uroot -h${mysql_host} -p${mysql_passwd} -P${mysql_port} -e "show databases"|grep ambari|wc -l`
if [ $re -eq 0 ];then
# sql 初始化
mysql -uroot -h${mysql_host} -p${mysql_passwd} -P${mysql_port} </tmp/init.sql
mysql -uroot -h${mysql_host} -p${mysql_passwd} -P${mysql_port} ${ambari_db} </var/lib/ambari-server/resources/Ambari-DDL-MySQL-CREATE.sql
fi
# 装备
setup_ambari
# 发动ambari服务
/usr/sbin/ambari-server start
# 输出公钥
cat ~/.ssh/id_rsa
tail -f /var/log/ambari-server/ambari-server.log
5)修正源码
调整源码文件,细讲这里就不讲了,对运用者无需关注,如想了解修正部分可以私信联系我,修正的文件:/lib/ambari-server/lib/ambari_server/dbConfiguration.py
6)构建镜像 Dockerfile
FROM registry.cn-hangzhou.aliyuncs.com/bigdata_cloudnative/centos-jdk:7.7.1908
# install sshd
RUN yum install openssh openssh-clients -y
# 生成ssh密钥对
RUN ssh-keygen -f ~/.ssh/id_rsa -P '' -q
# 添加yum 源
COPY ambari.repo /etc/yum.repos.d/
COPY hdp.repo /etc/yum.repos.d/
# install client mysql
COPY mysql /usr/bin/
# add mysql-connector
# wget https://repo1.maven.org/maven2/mysql/mysql-connector-java/5.1.39/mysql-connector-java-5.1.39.jar
RUN mkdir /usr/share/java
COPY mysql-connector-java-5.1.39.jar /var/lib/ambari-server/resources/
COPY mysql-connector-java-5.1.39.jar /usr/share/java/
COPY mysql-connector-java-5.1.39.jar /usr/lib/ambari-server/
COPY init.sql /tmp/
COPY dbConfiguration.py /tmp/
# copy bootstrap.sh
COPY bootstrap.sh /opt/apache/
RUN chmod +x /opt/apache/bootstrap.sh
WORKDIR /opt/apache
开端构建镜像
docker build -t registry.cn-hangzhou.aliyuncs.com/bigdata_cloudnative/ambari:2.7.5.0 . --no-cache
# 为了便利小伙伴下载即可运用,我这里将镜像文件推送到阿里云的镜像仓库
docker push registry.cn-hangzhou.aliyuncs.com/bigdata_cloudnative/ambari:2.7.5.0
### 参数解释
# -t:指定镜像称号
# . :当时目录Dockerfile
# -f:指定Dockerfile途径
# --no-cache:不缓存
7)装备 hosts
在 /etc/hosts
文件中添加如下(留意修正成自己机器的ip):
192.168.182.110 mysql-test
192.168.182.110 httpd
8)编排 docker-compose.yaml
version: '3'
services:
mysql-test:
image: registry.cn-hangzhou.aliyuncs.com/bigdata_cloudnative/mysql-test:5.7
restart: always
container_name: mysql-test
hostname: mysql-test
environment:
MYSQL_ROOT_PASSWORD: 123456
TZ: Asia/Shanghai
ports:
- 3306:3306
volumes:
- ./data:/var/lib/mysql
- ./conf/my.cnf:/etc/mysql/my.cnf
command:
--max_connections=1000
--character-set-server=utf8mb4
--collation-server=utf8mb4_general_ci
--default-authentication-plugin=mysql_native_password
healthcheck:
test: ["CMD-SHELL", "curl --silent localhost:3306 >/dev/null || exit 1"]
interval: 10s
timeout: 10s
retries: 3
httpd:
container_name: httpd
hostname: httpd
image: registry.cn-hangzhou.aliyuncs.com/bigdata_cloudnative/httpd:latest
ports:
- "18080:80"
privileged: true
restart: always
volumes:
- "./packages/ambari/:/usr/local/apache2/htdocs/"
ambari-server:
image: registry.cn-hangzhou.aliyuncs.com/bigdata_cloudnative/ambari:2.7.5.0
container_name: ambari-server
hostname: ambari-server
restart: always
privileged: true
network_mode: "host"
volumes:
- /etc/hosts:/etc/hosts
depends_on:
- mysql-test
- httpd
command: ["sh","-c","/opt/apache/bootstrap.sh"]
healthcheck:
test: ["CMD-SHELL", "netstat -tnlp|grep :8080 || exit 1"]
interval: 10s
timeout: 10s
retries: 8
9)开端布置
# --project-name指定项目称号,默许是当时目录称号
docker-compose -f docker-compose.yaml up -d
# 检查
docker-compose -f docker-compose.yaml ps
# 卸载
docker-compose -f docker-compose.yaml down
10)检测
登录web:http://ip:8080
默许账号/密码:admin/admin
五、通过 Apache Ambari 装置 Hadoop 组件
1)Cluster Information
2)Get Started
3)Select Version
http://httpd:18080/HDP/centos7/3.1.5.0-152/
http://httpd:18080/HDP-GPL/centos7/3.1.5.0-152/
http://httpd:18080/HDP-UTILS/centos7/1.1.0.22/
4)Install Options
获取ssh 私钥
docker exec -it ambari-server cat ~/.ssh/id_rsa
5)Confirm Hosts(装置 ambari-agent)
1、装备相互(容器到目标主机)
# 获取ssh公钥
docker exec -it ambari-server cat ~/.ssh/id_rsa.pub
2、装备yum 源
scp /etc/yum.repos.d/hdp.repo 192.168.182.111:/etc/yum.repos.d/
scp /etc/yum.repos.d/ambari.repo 192.168.182.111:/etc/yum.repos.d/
3、装备hosts
在 /etc/hosts
文件中添加如下(留意修正成自己机器的ip):
192.168.182.110 httpd
3、开端装置 ambari-agent
检查日志
tail -200f /var/log/ambari-agent/ambari-agent.log
检查装备
vi /etc/ambari-agent/conf/ambari-agent.ini
装置完结
4、装置 JDK(装置大数据组件需要)
官网下载:www.oracle.com/java/techno…
百度云下载
链接:pan.baidu.com/s/1-rgW-Z-s… 提取码:
8888
mkdir /opt/apache
# 修改/etc/profile,文末刺进以下内容:
# set java
export JAVA_HOME=/opt/apache/jdk1.8.0_212
export PATH=$JAVA_HOME/bin:$PATH
6)Choose Services(挑选所需装置的大数据组件)
7)Assign Masters
8)Assign Slaves and Clients
9)Customize Services
10)Review
11)Install, Start and Test
装置完结
12)Summary
到此通过 docker-compose 快速布置 Apache Ambari 保姆级教程就完毕了,装置包获取可关注我大众号:大数据与云原生技术共享
,在大众号里回复 dca
即可获取下载链接。有任何疑问欢迎给我留言或私信~