1. 程式人生 > >CentOS7 通過Ambari安裝Hadoop集群

CentOS7 通過Ambari安裝Hadoop集群

部門 2.6.0 5.1 資源文件 postgresq 賬號 left direct jar

第一次在cnblogs上發表文章,效果肯定不會好,希望各位多包涵。

編寫這個文檔的背景是月中的時候,部門老大希望我們能夠抽時間學習一下Hadoop大數據方面的技術;給我的學習內容是通過Ambari安裝Hadoop集群。通過一周左右的學習和實踐,整理出現在這篇安裝心得。

安裝默認使用Root用戶,避免權限問題導致不成功。

使用4臺虛擬機構建Ambari-Server、Hadoop集群,分配如下:

- 一臺虛擬機,作為Ambari-Server:

Hostname: ambari.server

- 三臺虛擬機,作為Hadoop集群:

Hostname01: hadoop.namenode
Hostname02: hadoop.datanode1
Hostname03: hadoop.datanode2

1. 安裝前的系統設定

a) 修改機器名、Hosts文件

查看當前的Hostname:

# hostname

  修改Hostname:(以ambari.server為例)

# hostnamectl set-hostname ambari.server

  修改每一臺機器上的/etc/hosts文件:

# vim /etc/hosts
192.168.141.159     ambari.server
192.168.141.160     hadoop.namenode
192.168.141.161     hadoop.datanode1
192.168.141.162     hadoop.datanode2

  修改完以後,重啟每一臺機器。

  b) 設置ntpd自動啟動,所有機器

  沒有安裝ntpd的機器,用yum命令安裝一下:

# yum install -y ntpd

  設置服務開機啟動:

# systemctl enable ntpd

  啟動服務:

# systemctl start ntpd

  c) 設置時間同步,所有機器

# cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
# ntpdate us.pool.ntp.org

  d) 關閉Selinux,所有機器

  修改配置:

# vim /etc/sysconfig/selinux
selinux=disalbed

  e) 關閉防火墻

# systemctl stop firewalld
# systemctl disable firewalld

  f) 制作集群的SSH免密碼登錄

在ambari.server上創建密鑰:

# ssh-keygen -t rsa

一路Enter到密鑰生成

進入~/.ssh目錄,查看密鑰文件:

私鑰:id_rsa
公鑰:id_rsa.pub

  切換到hadoop.namenode等機器上,創建~/.ssh目錄

# mkdir ~/.ssh 

從ambari.server上,發送公鑰給目標服務器:

# scp ~/.ssh/id_rsa.pub hadoop.namenode:/root/.ssh/authorized_keys _from_ambari
# scp ~/.ssh/id_rsa.pub hadoop.datanode1:/root/.ssh/authorized_keys _from_ambari
# scp ~/.ssh/id_rsa.pub hadoop.datanode2:/root/.ssh/authorized_keys _from_ambari

在被登錄的服務器上,合並公鑰:

# cd ~/.ssh
# cat authorized_keys _from_ambari >> authorized_keys

對所有服務器上的.ssh目錄和文件授權:

# chmod 700 ~/.ssh
# chmod 600 ~/.ssh/*

在ambari.server上驗證SHH可以免密碼登錄目標服務器:

# ssh hadoop.namenode

如果無需輸入密碼,且用hostname命令查看到正確的主機名,則表示配置免密碼登錄成功;

如果仍需要輸入密碼,則不成功;如果不成功,先嘗試權限修改;如果仍不成功,則要刪除密鑰再做一次。

2. 安裝JDK1.8

下載JDK 1.8.0.tar.gz文件,解壓:

# wget -c http://download.oracle.com/otn-pub/java/jdk/8u131-b11/d54c1d3a095b4ff2b6607d096fa80163/jdk-8u131-linux-x64.tar.gz
# mkdir /usr/local/jdk
# tar -xvf jdk-8u131-linux-x64.tar.gz -C /usr/local/jdk/

配置環境變量,添加以下內容:

# vim /etc/profile

#java
export JAVA_HOME=/usr/local/jdk/jdk1.8.0_131
export JRE_HOME=$JAVA_HOME/jre
export CLASSPATH=.:$JAVA_HOME/lib:$JRE_HOME/lib
export PATH=$PATH:$JAVA_HOME/bin:$JRE_HOME/bin

執行以下語句,使環境變量立刻生效:

# source /etc/profile

驗證Java安裝成功:

# java -version

java version "1.8.0_131"
Java(TM) SE Runtime Environment (build 1.8.0_131-b11)
Java HotSpot(TM) 64-Bit Server VM (build 25.131-b11, mixed mode)

3. 安裝MySQL

Ambari安裝會將安裝等信息寫入數據庫,建議使用自己安裝的MySQL數據庫,也可以不安裝而使用默認數據庫PostgreSQL。

Mysql數據庫安裝過程如下:

下載mysql的repo源(CentOS 7.2的yum源中默認沒有mysql,要先下載mysql的repo源):

# wget http://repo.mysql.com/mysql57-community-release-el7-8.noarch.rpm

  安裝mysql57-community-release-el7-8.noarch.rpm包:

# rpm -ivh mysql57-community-release-el7-8.noarch.rpm  --nodeps --force

安裝這個包後,會獲得兩個mysql的yum repo源:

# cd /etc/yum.repos.d
# ls -l

確認存在下列兩個repo源文件:

技術分享

安裝mysql:

# yum install -y mysql-server

啟動mysql服務,查看MySQL服務是否已啟動:

# systemctl start mysqld
# service mysqld status

重置root密碼:

MySQL5.7會在安裝後為root用戶生成一個隨機密碼,而不是像以往版本的空密碼。 可以安全模式修改root登錄密碼或者用隨機密碼登錄修改密碼。

下面用隨機密碼方式:

MySQL為root用戶生成的隨機密碼通過mysqld.log文件可以查找到:

# grep ‘temporary password‘ /var/log/mysqld.log
# mysql -u root -p
mysql> Enter password: (輸入剛才查詢到的隨機密碼)

修改root用戶密碼:(MySQL的密碼策略比較復雜,過於簡單的密碼會被拒絕)。首先修改安全策略,避免過於簡單的密碼被拒絕:

mysql> set global validate_password_policy=0;
mysql> set global validate_password_length=4;

重置用戶密碼:

mysql> alter user [email protected] identified by ‘root-1234‘;

完成後,保存退出:

mysql> flush privileges;
mysql> quit;

使用剛剛設置的新密碼登錄:

# mysql -u root -p

mysql> use mysql;

 如果進行操作出現下面的提示:
 You must reset your password using ALTER USER statement before executing this statement.

 就再設置一遍密碼:
 mysql> set password = password(‘root-1234‘);

開放3306端口

允許使用用戶名root密碼root-1234從任何主機連接到mysql服務器。

mysql> GRANT ALL PRIVILEGES ON *.* TO [email protected]%‘ IDENTIFIED BY ‘ root-1234‘ WITH GRANT OPTION;
mysql> FLUSH PRIVILEGES;

安裝mysql jdbc 驅動:

# yum install -y mysql-connector-java

4. 創建必要的數據庫和數據庫用戶

安裝完成後創建ambari數據庫及用戶,登錄root用戶執行下面語句:

mysql> create database ambari character set utf8;
mysql> CREATE USER [email protected]%‘ IDENTIFIED BY ‘ambari-1234‘;
mysql> GRANT ALL PRIVILEGES ON *.* TO [email protected]%‘;
mysql> FLUSH PRIVILEGES;

如果要安裝Hive,再創建Hive數據庫和用戶 再執行下面的語句:

mysql> create database hive character set utf8;
mysql> CREATE USER [email protected]%‘ IDENTIFIED BY ‘hive-1234‘;
mysql> GRANT ALL PRIVILEGES ON *.* TO [email protected]%‘;
mysql> FLUSH PRIVILEGES;

如果要安裝Oozie,再創建Oozie數據庫和用戶 再執行下面的語句:

mysql> create database oozie character set utf8;
mysql> CREATE USER [email protected]%‘ IDENTIFIED BY ‘oozie-1234‘;
mysql> GRANT ALL PRIVILEGES ON *.* TO [email protected]%‘;
mysql> FLUSH PRIVILEGES; 

5. 下載Ambari的資源

下載HortWorks官網上的3個庫到本地(也可以在線下載,但是速度會很慢)。

我們先把hortworks官網上需要下載的3個庫下載到本地(這個還是需要很長時間的,當然你也可以在線下載,通過wget但是由於文件比較大,所以下載會非常慢)然後把他上傳到我們的鏡像服務器上。

最新版本鏈接:http://docs.hortonworks.com/HDPDocuments/Ambari-2.5.0.3/bk_ambari-installation/content/download_the_ambari_repo_lnx7.html   

文檔編寫時采用的是Ambari 2.2.1.0,但安裝方法是一致的。

Ambari Repositories:

http://docs.hortonworks.com/HDPDocuments/Ambari-2.2.1.0/bk_Installing_HDP_AMB/content/_ambari_repositories.html

OS

Format

URL

RedHat 6

CentOS 6

Oracle Linux 6

Base URL

http://public-repo-1.hortonworks.com/ambari/centos6/2.x/updates/2.2.1.0

Repo File

http://public-repo-1.hortonworks.com/ambari/centos6/2.x/updates/2.2.1.0/ambari.repo

Tarball md5 | asc

http://public-repo-1.hortonworks.com/ambari/centos6/2.x/updates/2.2.1.0/ambari-2.2.1.0-centos6.tar.gz

RedHat 7

CentOS 7

Oracle Linux 7

Base URL

http://public-repo-1.hortonworks.com/ambari/centos7/2.x/updates/2.2.1.0

Repo File

http://public-repo-1.hortonworks.com/ambari/centos7/2.x/updates/2.2.1.0/ambari.repo

Tarball md5 | asc

http://public-repo-1.hortonworks.com/ambari/centos7/2.x/updates/2.2.1.0/ambari-2.2.1.0-centos7.tar.gz

  兩個是 HDP 2.4 Repositories:

OS

Version Number

Repository Name

Format

URL

RedHat 6

CentOS 6

Oracle Linux 6

HDP-2.4.0.0

HDP

Base URL

http://public-repo-1.hortonworks.com/HDP/centos6/2.x/updates/2.4.0.0

Repo File

http://public-repo-1.hortonworks.com/HDP/centos6/2.x/updates/2.4.0.0/hdp.repo

Tarballmd5 | asc

http://public-repo-1.hortonworks.com/HDP/centos6/2.x/updates/2.4.0.0/HDP-2.4.0.0-centos6-rpm.tar.gz

HDP-UTILS

Base URL

http://public-repo-1.hortonworks.com/HDP-UTILS-1.1.0.20/repos/centos6

Tarball md5 | asc

http://public-repo-1.hortonworks.com/HDP-UTILS-1.1.0.20/repos/centos6/HDP-UTILS-1.1.0.20-centos6.tar.gz

RedHat 7

CentOS 7

Oracle Linux 7

HDP-2.4.0.0

HDP

Base URL

http://public-repo-1.hortonworks.com/HDP/centos7/2.x/updates/2.4.0.0

Repo File

http://public-repo-1.hortonworks.com/HDP/centos7/2.x/updates/2.4.0.0/hdp.repo

Tarball md5 | asc

http://public-repo-1.hortonworks.com/HDP/centos7/2.x/updates/2.4.0.0/HDP-2.4.0.0-centos7-rpm.tar.gz

HDP-UTILS

Base URL

http://public-repo-1.hortonworks.com/HDP-UTILS-1.1.0.20/repos/centos7

Tarball md5 | asc

http://public-repo-1.hortonworks.com/HDP-UTILS-1.1.0.20/repos/centos7/HDP-UTILS-1.1.0.20-centos7.tar.gz

  嘗試新版本的話,請通過最新版鏈接中的找到最新版安裝包。

  (Latest)Ambari 2.5.0 Repositories

OS

Format

URL

RedHat 6

CentOS 6

Oracle Linux 6

Base URL

http://public-repo-1.hortonworks.com/ambari/centos6/2.x/updates/2.5.0.3

Repo File

http://public-repo-1.hortonworks.com/ambari/centos6/2.x/updates/2.5.0.3/ambari.repo

Tarball md5 | asc

http://public-repo-1.hortonworks.com/ambari/centos6/2.x/updates/2.5.0.3/ambari-2.5.0.3-centos6.tar.gz

RedHat 7

CentOS 7

Oracle Linux 7

Base URL

http://public-repo-1.hortonworks.com/ambari/centos7/2.x/updates/2.5.0.3

Repo File

http://public-repo-1.hortonworks.com/ambari/centos7/2.x/updates/2.5.0.3/ambari.repo

Tarball md5 | asc

http://public-repo-1.hortonworks.com/ambari/centos7/2.x/updates/2.5.0.3/ambari-2.5.0.3-centos7.tar.gz

  (Latest)兩個是 HDP 2.6 Repositories:

OS

Version Number

Repository Name

Format

URL

RedHat 6

CentOS 6

Oracle Linux 6

HDP-2.6.0.3

HDP

Base URL

http://public-repo-1.hortonworks.com/HDP/centos6/2.x/updates/2.6.0.3

Repo File

http://public-repo-1.hortonworks.com/HDP/centos6/2.x/updates/2.6.0.3/hdp.repo

Tarballmd5 | asc

http://public-repo-1.hortonworks.com/HDP/centos6/2.x/updates/2.6.0.3/HDP-2.6.0.3-centos6-rpm.tar.gz

HDP-UTILS

Base URL

http://public-repo-1.hortonworks.com/HDP-UTILS-1.1.0.21/repos/centos6

Tarball md5 | asc

http://public-repo-1.hortonworks.com/HDP-UTILS-1.1.0.21/repos/centos6/HDP-UTILS-1.1.0.21-centos6.tar.gz

RedHat 7

CentOS 7

Oracle Linux 7

HDP-2.4.0.0

HDP

Base URL

http://public-repo-1.hortonworks.com/HDP/centos7/2.x/updates/2.6.0.3

Repo File

http://public-repo-1.hortonworks.com/HDP/centos7/2.x/updates/2.6.0.3/hdp.repo

Tarball md5 | asc

http://public-repo-1.hortonworks.com/HDP/centos7/2.x/updates/2.6.0.3/HDP-2.6.0.3-centos7-rpm.tar.gz

HDP-UTILS

Base URL

http://public-repo-1.hortonworks.com/HDP-UTILS-1.1.0.21/repos/centos7

Tarball md5 | asc

http://public-repo-1.hortonworks.com/HDP-UTILS-1.1.0.21/repos/centos7/HDP-UTILS-1.1.0.21-centos7.tar.gz

 

6. 配置本地下載站

在ambari.server上配置httpd服務:

# yum install -y httpd

把下載到的3個資源文件,上傳到ambari.server,並解壓到制定目錄:

# mkdir /var/www/html/ambary-hdp
# tar -xvf ambari-2.2.1.0-centos7.tar.gz -C /var/www/html/ambary-hdp/ # tar -xvf HDP-2.4.0.0-centos7-rpm.tar.gz -C /var/www/html/ambary-hdp/ # tar -xvf HDP-UTILS-1.1.0.20-centos7.tar.gz -C /var/www/html/ambary-hdp/

啟動httpd服務:

# systemctl start httpd

通過瀏覽器訪問本地資源地址,如果能看到以下頁面,則表示配置成功:

技術分享

7. 配置Yum本地Repos資源池

在ambari.server上執行:

# yum install -y yum-plugin-priorities

a) 修改Yum安裝源的校驗

# vi /etc/yum/pluginconf.d/priorities.conf

#設置為以下內容

[main]
enabled=1
gpgcheck=0

b) 制作本地資源文件

創建Ambari、HDP、HDP-UTIL資源文件:

- ambary.repo:

[ambari-2.2.1.0]
name=ambari-2.2.1.0
baseurl=http://192.168.141.159/ambari-hdp/AMBARI-2.2.1.0/centos7/2.2.1.0-161
gpgcheck=0
gpgkey=http://192.168.141.159/ambari-hdp/AMBARI-2.2.1.0/centos7/2.2.1.0-161/RPM-GPG-KEY/RPM-GPG-KEY-Jenkins
enabled=1
priority=1

- hdp.repo

[HDP-2.4.0.0]
name=Hortonworks Data Platform Version - HDP-2.4.0.0
baseurl=http://192.168.141.159/ambari-hdp/HDP/centos7/2.x/updates/2.4.0.0
gpgcheck=0
gpgkey=http://192.168.141.159/ambari-hdp/HDP/centos7/RPM-GPG-KEY/RPM-GPG-KEY-Jenkins
enabled=1
priority=1

- hdp-util.repo

[HDP-UTILS-1.1.0.20]
name=Hortonworks Data Platform Version - HDP-UTILS-1.1.0.20
baseurl= http://192.168.141.159/ambari-hdp/HDP-UTILS-1.1.0.20/repos/centos7
gpgcheck=0
enabled=1
priority=1

制作完成後,移動到/etc/yum.repos.d/;依次執行以下命令,更新本地資源池:

# yum clean list

# yum update list

# yum makecache

等待更新完畢後,查看資源池:

# yum repolist

如果看到以下資源,表示配置成功:

技術分享

8. 安裝Ambari-Server

執行安裝命令:

# yum install -y ambary-server

安裝過程無需互動

(如果提示找不到KEY,則執行如下命令:

rpm --import /var/www/html/ambari-hdp/AMBARI-2.2.1.0/centos7/2.2.1.0-161/RPM-GPG-KEY/RPM-GPG-KEY-Jenkins)

將Ambari數據庫腳本導入到數據庫。

Ambari安裝會將安裝等信息寫入數據庫,建議使用自己安裝的MySQL數據庫,也可以不安裝而使用默認數據庫PostgreSQL。如果使用自己定義的數據庫,必須在啟動Ambari服務之前導入Ambari的sql腳本。

用root用戶登錄mysql

# mysql -uroot -p

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

9. 配置Ambari-Server

執行配置命令:

# ambari-server setup

提示是否自定義設置?輸入:y

Customize user account for ambari-server daemon [y/n] (n)? y

ambari-server 賬號。輸入:root。

Enter user account for ambari-server daemon (root): root

Adjusting ambari-server permissions and ownership...

檢查防火墻,如果關閉則不用操作。

Checking firewall status...

Redirecting to /bin/systemctl status iptables.service

設置JDK。輸入:3。

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

如果上面選擇3自定義JDK,則需要設置JAVA_HOME。輸入:

/usr/local/jdk/jdk1.8.0_131

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/local/jdk/jdk1.8.0_131

Validating JDK on Ambari Server...done.
Completing setup...

數據庫配置。選擇:y。

Configuring database...Enter advanced database configuration [y/n] (n)? y

選擇數據庫類型。輸入:3。

Configuring database...
========================================

Choose one of the following options:

[1] - PostgreSQL (Embedded)
[2] - Oracle
[3] - MySQL
[4] - PostgreSQL
[5] - Microsoft SQL Server (Tech Preview)
[6] - SQL Anywhere

==========================================

Enter choice (1): 3

設置數據庫的具體配置信息,根據實際情況輸入,如果和括號內相同,則可以直接回車。

Hostname (localhost): ambari.server
Port (3306):
Database name (ambari):
Username (ambari):
Enter Database Password (ambari-1234):

提示必須安裝MySQL JDBC,已安裝則直接通過。

WARNING: Before starting Ambari Server, you must copy the MySQL JDBC driver JAR file to /usr/share/java.

Press <enter> to continue.

啟動ambari-server服務

# ambari-server start

啟動後在瀏覽器輸入Ambari地址:

http://192.168.141.159:8080/#/login

看到如下頁面,則表示安裝成功:

技術分享

  

進入Ambari配置管理頁面:

用戶名:admin

密碼: admin

登錄成功進入以下頁面:

技術分享

10. 安裝Hadoop集群

a) 在集群節點上安裝JDK

在3臺作為Hadoop集群的機器上安裝JDK,要與ambari.server上安裝的完全一致

b) 安裝ambari-agent

將ambari.server上的3個.repo文件復制到hadoop集群的三臺服務器上;並完成yum源更新的命令。

  安裝ambari-agent:在集群的3臺電腦上執行添加,並添加成開機自啟動服務:  

# yum install -y ambari-agent
# chkconfig --add ambari-agent

c) 通過安裝向導,配置Hadoop集群

參考文檔:

http://www.cnblogs.com/boyzgw/p/6525313.html

http://www.cnblogs.com/zlslch/p/6629235.html

https://yq.aliyun.com/articles/60217

CentOS7 通過Ambari安裝Hadoop集群