Ambari環境搭建(離線搭建)

ambari 離線部署

Ambari介紹

Ambari 是 Apache Software Foundation 的一個頂級開源項目,是一個集中部署、管理、監控 Hadoop 分佈式集羣的工具。可是這裏的 Hadoop 是一個廣義概念,並不只僅指的是 Hadoop(HDFS、MapReduce),而是指 Hadoop 生態圈(包括 Spark、Hive、Hbase,Sqoop,Zookeeper、Flume 等),Ambari 可使 Hadoop 大數據軟件更容易使用,且能夠方便的集成咱們本身的服務讓 Ambari 統一管理。html

  • 部署:自動化部署 Hadoop 軟件,可以自動處理服務、組件之間的依賴(好比 HBase 依賴 HDFS,DataNode 啓動的時候,須要 NameNode 先啓動等)。
  • 管理:Hadoop 服務組件的啓動、中止、重啓,配置文件的多版本管理。
  • 監控:Hadoop 服務的當前狀態(組件節點的存活狀況、YARN 任務執行狀況等),當前主機的狀態(內存、硬盤、CPU、網絡等),並且能夠自定義報警事件。

clipboard.png

ambari版本對應表

這次採用HDP2.5版本java

clipboard.png

集羣規劃

集羣hostname 軟件安裝
nn1 ambari-agent,namenode,datanode,zookeeper
nn2 ambari-agent,namenode,datanode,zookeeper
rm ambari-server,resourcemanager,historyserver,datanode

安裝Ambari-Server

前提先下載好須要的離線包。
並將這些包上傳到節點rm上。
須要的離線包介紹:node

  • HDP-UTILS-1.1.0.21-centos7.tar.gz(HDP工具包)
  • ambari-2.4.1.0-centos7.tar.gz(ambari離線包)
  • HDP-2.5.0.0-centos7-rpm.tar.gz(官方下載連接地址
  • CentOS-7-x86_64-DVD-1503-01.iso(Centos7離線包)
  • jdk

Centos7 64 系統軟件要求

  • yum and rpm
  • scp,curl,unzip,tar,and wget
  • openSSL
  • Python 2.7.x
  • jdk 1.8.0_77(官方建議,不過我用的1.8.0_11也能夠)
  • 建議修改最大打開文件描述爲10000,臨時改變 ulimit -n 10000

永久更改,須要修改配置文件,且須要重啓,建議和selinux關閉一塊兒作完了,再作重啓動做。python

vi /etc/security/limits.conf
添加
* soft nofile 10000
* hard nofile 10000
  • 語言必須是默認的英文

安裝ansible(自選)

注意:後續步驟,使用的是ansible的命令,若是沒有安裝ansible,則請使用原始命令。
例:
ansible all -m command -a 'systemctl stop firewalld'
等同於在每臺主機上執行命令
systemctl stop firewalld mysql

ansible安裝與操做linux

配置ssh免密

修改hosts,增長你的集羣信息,每臺配置同樣git

192.168.0.135   nn1.ambari      nn1
192.168.0.136   nn2.ambari      nn2
192.168.0.137   rm.ambari       rm

在rm節點上,執行命令ssh-keygen,直接敲enter鍵四次,而後再執行github

ssh-copy-id nn1
ssh-copy-id nn2
ssh-copy-id rm

關閉防火牆

ansible all -m command -a 'systemctl stop firewalld'
ansible all -m command -a 'systemctl disable firewalld'web

關閉Selinux

修改/etc/selinux/config,改成SELINUX=disable,須要重啓sql

安裝jdk

一、解壓包

cd /opt
tar -zxvf  jdk-8u111-linux-x64.tar.gz

二、在/etc/profile添加配置

export JAVA_HOME=/opt/jdk1.8.0_111
export PATH=$JAVA_HOME/bin:$PATH
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar

三、複製jdk包和配置文件到nn一、nn2節點

scp -r jdk1.8.0_111 nn2:/opt/
scp /etc/profile nn2:/etc/
scp -r jdk1.8.0_111 nn1:/opt/
scp /etc/profile nn1:/etc/

四、驗證一下
java -version

離線掛載Centos7源

一、新建一個準備掛載的目錄(爲了後面方便httpd源,直接建立在httpd的默認目錄上)
mkdir -p /var/www/html/centos7
二、掛載鏡像文件
mount -t iso9660 -o loop /opt/CentOS-7-x86_64-DVD-1511.iso /var/www/html/centos7
三、備份其餘repo文件,構建離線源

cd /etc/yum.repos.d
mkdir backup
mv Centos-* backup
touch centos-media.repo

在centos-media.repo寫入如下內容

[centos7-media]
name=Centos linux 7.0
baseurl=file:///var/www/html/centos7
enabled=1
gpgcheck=0

四、驗證離線源是否可用。

yum clean all
yum makecache

配置ambari,HDP離線源

一、配置路徑

cd /var/www/html
mkdir ambari
mkdir hdp

二、解壓包到相應路徑

tar -zxvf /opt/Ambari/ambari-2.4.1.0-centos7.tar.gz -C /var/www/html/ambari/
 tar -zxvf /opt/Ambari/HDP-2.5.0.0-centos7-rpm.tar.gz -C /var/www/html/hdp/
 tar -zxvf /opt/Ambari/HDP-UTILS-1.1.0.21-centos7.tar.gz -C /var/www/html/hdp/

三、構建離線源

3.一、 在rm節點上構建

ambari離線源
vi /etc/yum.repos.d/ambari.repo

[ambari-2.4.1.0]
name=ambari-2.4.1.0 - Updates
baseurl=http://rm/ambari/AMBARI-2.4.1.0/centos7/2.4.1.0-22
gpgcheck=0
#gpgkey=http://public-repo-1.hortonworks.com/ambari/centos7/RPM-GPG-KEY/RPM-GPG-KEY-Jenkins
enabled=1
priority=1

hdp離線源
vi /etc/yum.repos.d/hdp.repo

[HDP-2.5]
name=HDP-2.5
baseurl=http://rm/hdp/HDP/centos7
enabled=1
gpgcheck=0

hdp-utils離線源
vi /etc/yum.repos.d/hdp-utils.repo

[HDP-UTILS-1.1.0.21]
name=HDP-UTILS-1.1.0.21
baseurl=http://rm/hdp/HDP-UTILS-1.1.0.21/repos/centos7
enabled=1
gpgcheck=0

安裝Apache Httpd

一、安裝
yum install httpd -y
二、修改配置
vi /etc/httpd/conf/httpd.conf

clipboard.png

將圖中標示的紅色,分別修改成
ServerName rm:80

<Directory />
  Options FollowSymLinks
  AllowOverride None
  Order allow,deny
  Allow from all
</Directory>

三、啓動httpd
systemctl start httpd
systemctl enable httpd
四、驗證一下,離線源是否可用了
在本身電腦打開瀏覽器,輸入rm/centos7(前提本機須要配置好hosts),出現以下圖,表示成功了。

clipboard.png

安裝時間同步工具chrony

ansible all -m yum -a "name=chrony"

在rm節點修改chrony的配置文件

clipboard.png

在nn1和nn2節點上修改配置文件,只須要增長要同步的服務器便可

clipboard.png

啓動chrony服務
ansible all -m command -a 'systemctl start chronyd'

自行檢查時間是否已經同步了。

安裝ambari-server

一、安裝
yum install ambari-server -y
二、配置
ambari-server setup

大多數照着默認往下走就行了。

[root@rm ~]# 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] Oracle JDK 1.7 + Java Cryptography Extension (JCE) Policy Files 7
[3] Custom JDK
==============================================================================
Enter choice (1): 3
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: /opt/jdk1.8.0_111
Validating JDK on Ambari Server...done.
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): 1
Database name (ambari): ambari
Postgres schema (ambari): ambari
Username (ambari): ambari
Enter Database Password (bigdata):
Invalid characters in password. Use only alphanumeric or _ or - characters
Enter Database Password (bigdata):
Default properties detected. Using built-in database.
Configuring ambari database...
Checking PostgreSQL...
Running initdb: This may take up to a minute.
Initializing database ... OK


About to start PostgreSQL
Configuring local database...
Connecting to local database...done.
Configuring PostgreSQL...
Restarting PostgreSQL
Extracting system views...
ambari-admin-2.4.1.0.22.jar
...........
Adjusting ambari-server permissions and ownership...
Ambari Server 'setup' completed successfully.

三、啓動
ambari-server start

安裝ambari-agent

做爲ambari-agent的條件:

  • 防火牆關閉
  • selinux關閉
  • jdk安裝
  • chrony安裝
  • 由於這次是離線環境,還須要配置好離線源

由於前面四個條件,在安裝ambari-server的時候已經安裝好了。

要作的工做只有配置離線源

離線源配置
刪除默認repo
rm -f /etc/yum.repos.d/*.repo

複製rm的離線源到其餘節點

scp /etc/yum.repos.d/ambari.repo nn1:/etc/yum.repos.d/
scp /etc/yum.repos.d/ambari.repo nn2:/etc/yum.repos.d/
scp /etc/yum.repos.d/hdp.repo nn2:/etc/yum.repos.d/
scp /etc/yum.repos.d/hdp.repo nn1:/etc/yum.repos.d/
scp /etc/yum.repos.d/hdp-utils.repo nn1:/etc/yum.repos.d/
scp /etc/yum.repos.d/hdp-utils.repo nn2:/etc/yum.repos.d/

3.3 在nn1和nn2上驗證一下

yum makecache

新的一臺ambari-agent

你須要從新配置前面提到的前置環境。

另外須要修改ambari-server的/etc/hosts,把新的機子加進來,而且執行ssh-copy-id $new_hostname

在ambari-web上安裝集羣

打開瀏覽器,輸入ambari-server所在節點的IP/HostName:8080,接下來就是直接在界面上操做了。

注意一些坑就行了。

因爲界面這邊忘記截屏了,因此給個連接-部署一個Hadoop2.X集羣做爲參考。

安裝的時候,會報錯snappy包不對

resource_management.core.exceptions.Fail: Execution of '/usr/bin/yum -d 0 -e 0 -y install snappy-devel' returned 1. Error: Package: snappy-devel-1.0.5-1.el6.x86_64 (HDP-UTILS-1.1.0.21)
           Requires: snappy(x86-64) = 1.0.5-1.el6
           Installed: snappy-1.1.0-3.el7.x86_64 (@anaconda)
               snappy(x86-64) = 1.1.0-3.el7
           Available: snappy-1.0.5-1.el6.x86_64 (HDP-UTILS-1.1.0.21)
               snappy(x86-64) = 1.0.5-1.el6
 You could try using --skip-broken to work around the problem
 You could try running: rpm -Va --nofiles --nodigest

卸載自帶的snappy
ansible all -m yum -a 'name=snappy state=removed'
安裝snappy-devel
ansible all -m yum -a 'name=snappy-devel'

網上現有資源docker安裝ambari

這個很方便,基本10分鐘就能夠搭建一個測試集羣,但美中不足的是,做者的源不是離線的,要搭建集羣須要有網絡環境。

一、安裝docker
二、下載github docker ambari
github docker-ambari
三、根據網址上的readme文檔,進行簡單部署就行了

3.1 解壓包  
3.2 進入解壓包目錄  
`. ambari-functions or source ambari-functions`   
3.3 啓動集羣  
`amb-start-cluster 3`  

![](../images/ambari/ambari_docker_github_result.jpg)

問題殘留

做者在readme中提到
Ambari containers started by ambari-function are using bridge networking. This means that you will not be able to communicate with containers directly from host unless you specify the route to containers. You can do this with:

# Getting the IP of docker-machine or boot2docker
docker-machine ip <name-of-docker-vm>
# or
boot2docker ip

# Setting up the
sudo route add -net 172.17.0.0/16 <docker-machine or boot2docker>
# e.g:
sudo route add -net 172.17.0.0/16 192.168.99.100

大致的意思就是能夠經過本機能夠經過配置路由來連通172.17.0.0的網絡,也就是說做者並無把端口映射出來,我配置了本身的網絡路由,但並不能連通。

後面是經過修改docker啓動ambari-server的命令來啓動ambari-server,而後輸入宿主機IP:映射端口號,就能夠訪問做者建立的ambari-server鏡像了。如圖:

clipboard.png

clipboard.png

docker離線搭建ambari

一、 先把ambari和HDP離線源放在宿主機上,並解壓出來
二、 開始構建Dockerfile

準備文件以下

ambari.repo           
Dockerfile                 
hdp.repo                   
hdp-utils.repo             
httpd.conf                 
jdk-8u111-linux-x64.tar.gz 
supervisord.conf

Dockerfile內容

FROM centos

MAINTAINER linjk

# 安裝JDK
ADD jdk-8u111-linux-x64.tar.gz /usr/local/src/
ENV JAVA_HOME=/usr/local/src/jdk1.8.0_111
ENV PATH=$PATH:$JAVA_HOME/bin
ENV CLASSPATH=.:$JAVA_HOME/jre/lib/rt.jar:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar

# 安裝httpd以及其餘必要工具
RUN yum makecache Fast \
        && yum install httpd openssh-server net-tools chrony -y
# 安裝supervisor
RUN yum -y install python-setuptools \
                && easy_install supervisor \
                && mkdir -p /etc/supervisor
COPY supervisord.conf /etc/supervisor/
COPY httpd.conf /etc/httpd/conf/httpd.conf

RUN mkdir -p /var/www/html/centos/ \
        && mkdir -p /var/www/html/ambari/ \
        && mkdir -p /var/www/html/hdp/
COPY *.repo /etc/yum.repos.d/

# 安裝mariadb和mariadb-server
yum install -y mariadb mariadb-server mysql-connector-java

EXPOSE 22 80 9001 8080 3306

CMD supervisord -c /etc/supervisor/supervisord.conf

ambari.repo內容

[ambari-2.4.1.0]
name=ambari-2.4.1.0 - Updates
baseurl=http://ambari-server/ambari/AMBARI-2.4.1.0/centos7/2.4.1.0-22
gpgcheck=0
#gpgkey=http://public-repo-1.hortonworks.com/ambari/centos7/RPM-GPG-KEY/RPM-GPG-KEY-Jenkins
enabled=1
priority=1

hdp.repo內容

[HDP-2.5]
name=HDP-2.5
baseurl=http://ambari-server/hdp/HDP/centos7
enabled=1
gpgcheck=0

hdp-utils.repo內容

[HDP-UTILS-1.1.0.21]
name=HDP-UTILS-1.1.0.21
baseurl=http://ambari-server/hdp/HDP-UTILS-1.1.0.21/repos/centos7
enabled=1
gpgcheck=0

httpd.conf修改的內容

ServerName ambari-server:80

#
# Deny access to the entirety of your server's filesystem. You must
# explicitly permit access to web content directories in other
# <Directory> blocks below.
#
<Directory />
  Options FollowSymLinks
  AllowOverride None
  Order allow,deny
  Allow from all
</Directory>

supervisor內容

unix_http_server]
file=/var/run/supervisor.sock

[supervisord]
nodaemon=true

[rpcinterface:supervisor]
supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface

[supervisorctl]
serverurl=unix:///var/run/supervisor.sock

[inet_http_server]
port=*:9001

[program:sshd]
command=/usr/sbin/sshd -D

[program:httpd]
command=/usr/sbin/httpd

三、 構建鏡像ambari-server(以前壓縮包放在/opt/ambari和/opt/hdp/下)
docker run -d -P -v /opt/ambari/:/var/www/html/ambari/ -v /opt/hdp/:/var/www/html/hdp/ -h ambari-server --name as ambari-server /usr/sbin/init

四、 進入容器啓動和配置mariaDB

4.一、 啓動
systemctl start mariadb
4.二、 設置開機啓動
systemctl enable mariadb
4.三、 配置
mysql_secure_installation

會出現一個交互界面,基本一路回車,設置密碼界面

首先是設置密碼,會提示先輸入密碼
Enter current password for root (enter for none):<–初次運行直接回車

設置密碼
Set root password? [Y/n] <– 是否設置root用戶密碼,輸入y並回車或直接回車
New password: <– 設置root用戶的密碼
Re-enter new password: <– 再輸入一次你設置的密碼

其餘配置
Remove anonymous users? [Y/n] <– 是否刪除匿名用戶,回車
Disallow root login remotely? [Y/n] <–是否禁止root遠程登陸,回車,
Remove test database and access to it? [Y/n] <– 是否刪除test數據庫,回車
Reload privilege tables now? [Y/n] <– 是否從新加載權限表,回車

4.四、 (自選)配置mariadb的字符集
vi /etc/my.cnf
4.五、 添加用戶設置權限

create database ambari;
use ambari;
CREATE USER 'ambari'@'%' IDENTIFIED BY 'bigdata';
GRANT ALL PRIVILEGES ON *.* TO 'ambari'@'%';
CREATE USER 'ambari'@'ambari-server' IDENTIFIED BY 'bigdata';
GRANT ALL PRIVILEGES ON *.* TO 'ambari'@'ambari-server';

五、 安裝ambari-server並配置和啓動
5.一、 安裝
yum install ambari-server
5.二、 配置
ambari-server setup

出現交互界面

Using python  /usr/bin/python
Setup ambari-server
Checking SELinux...
WARNING: Could not run /usr/sbin/sestatus: OK
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...
Do you want to change Oracle JDK [y/n] (n)? y
[1] Oracle JDK 1.8 + Java Cryptography Extension (JCE) Policy Files 8
[2] Oracle JDK 1.7 + Java Cryptography Extension (JCE) Policy Files 7
[3] Custom JDK
==============================================================================
Enter choice (1): 3
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 o
Path to JAVA_HOME: /usr/local/src/jdk1.8.0_111
Validating JDK on Ambari Server...done.
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 (3): 3
Hostname (ambari-server):
Port (3306):
Database name (ambari):
Username (ambari):
Enter Database Password (bigdata):
Configuring ambari database...
Copying JDBC drivers to server resources...
Configuring remote database connection properties...
WARNING: Before starting Ambari Server, you must run the following DDL against the database to create the schema: /var/lib/ambari-server/resources/Ambari-DDL-MySQL-CREATE.sql
Proceed with configuring remote database connection properties [y/n] (y)? y
Extracting system views...
ambari-admin-2.4.1.0.22.jar
...........
Adjusting ambari-server permissions and ownership...
Ambari Server 'setup' completed successfully.

根據警告到mysql去執行sql語句,注意use ambari;

use ambari;
source  /var/lib/ambari-server/resources/Ambari-DDL-MySQL-CREATE.sql

驗證一下,是否有生成一些ambari配置表

show tables;

六、 啓動
ambari-server start 七、 驗證 在瀏覽器打開 $宿主機IP:映射端口

相關文章
相關標籤/搜索