1. 程式人生 > >基於ubuntu14.04的ambari安裝及叢集部署

基於ubuntu14.04的ambari安裝及叢集部署

第一節. Ambari簡介

Ambari跟Hadoop等開源軟體一樣,也是Apache Software Foundation中的一個專案,並且是頂級專案。目前最新的釋出版本是2.4.1。就Ambari的作用來說,就是建立、管理、監視Hadoop的叢集,但是這裡的Hadoop是廣義,指的是Hadoop整個生態圈(例如 Hive,Hbase,Sqoop,Zookeeper等,而並不僅是特指Hadoop。用一句話來說,Ambari就是為了讓Hadoop以及相關的大資料軟體更容易使用的一個工具。

說到這裡,大家就應該明白什麼人最需要 Ambari了。那些苦苦花費好幾天去安裝、除錯Hadoop的初學者是最能體會到 Ambari的方便之處的。而且,Ambari現在所支援的平臺元件也越來越多,例如流行的Spark,Storm等計算框架,以及資源排程平臺YARN等,我們都能輕鬆地通過Ambari來進行部署。

Ambari自身也是一個分散式架構的軟體,主要由兩部分組成:Ambari Server 和 Ambari Agent。簡單來說:

  • 使用者通過 mbari Server通知Ambari Agent安裝對應的軟體;
  • Agent會定時地傳送各個機器每個軟體模組的狀態給Ambari Server;
  • 最終這些狀態資訊會呈現在Ambari的GUI,方便使用者瞭解到叢集的各種狀態,並進行相應的維護。

詳細的操作和介紹會在後續章節介紹。

第二節. 配置Ambari安裝環境

關於 Ambari 的安裝,目前網上能找到兩個發行版,一個是 Apache 的 Ambari,另一個是 Hortonworks 的,兩者區別不大。這裡就以 Hortonworks 的 Ambari 2.2.2 作為示例。本文使用四臺 Ubuntu14.04

作為安裝環境,四臺機器分別為node0.example.com、 node1.example.com、node2.example.com、node3.example.com。node0 計劃安裝為 Ambari 的 Server,另外三臺為 Ambari Agent。

先了解如何如何使用vagrant快速搭建虛擬機器叢集的,可以檢視文章《使用Vagrant建立虛擬機器叢集

安裝 Ambari 最方便的方式就是使用公共的庫源(public repository)。有興趣的朋友可以自己研究一下搭建一個本地庫(local repository)進行安裝。這個不是重點,所以不在此贅述。在進行具體的安裝之前,需要做幾個準備工作。

1.建立四臺機器的域名

例如node0.example.com機器:

$ sudo echo node0 > /etc/hostname
$ sudo vim /etc/hosts
#在檔案中新增本機的主機資訊:
192.168.17.200 node0.example.com node0

然後依次為node1-node3修改主機名及域名資訊,切記域名資訊必須是FQDN格式的,如node0.example.com, node0是主機名,example.com是域名字尾。

注意:需要將在/etc/hosts中將127.0.0.1對應的資訊註釋或者刪除,否則可能引起節點之間通訊失敗,其原因是這行hosts導致元件的埠監聽繫結到了127.0.0.1而不是ip或者0.0.0.0,所以其他節點沒法連線到這個節點。為了確保Ambari server可以根據Ambari Agent的域名資訊聯接,需要將node1-node3的域名資訊新增到node0

在node0中執行以下操作:

$ sudo vim /etc/hosts
#在檔案中新增如下資訊
192.168.17.201 node1.example.com node1
192.168.17.202 node2.example.com node2
192.168.17.203 node3.example.com node3

驗證:

$ ping node1.example.com
$ ping  node1

2.SSH的無密碼登入 Ambari的Server會SSH到Agent的機器,拷貝並執行一些命令。因此我們需要配置 Ambari Server到Agent的SSH無密碼登入。在這個例子裡,node0可以SSH無密碼登入node1、node2和 node3。步驟:

  • 使用root使用者
    $ sudo -i
    
  • 分別在node0-node3建立ssh key
$ ssh-keygen -t rsa
  • 將Ambari Server的public key的內容複製到node0-node3的 /home/hadoop/.ssh/authorized_keys
  • 驗證:在node0輸入
    $ ssh [email protected]
    

3.安裝啟動ntp

$ ape-get install ntp
$ ntpq -p

4.檢視是否開啟transparent_hugepage

$ cat /sys/kernel/mm/transparent_hugepage/enabled
 [always] madvise never

always代表開啟不存在該檔案就是沒開啟臨時關閉

$ echo never > /sys/kernel/mm/transparent_hugepage/enabled

當重啟系統後,會自動還原為always 以上的準備工作完成後,便可以真正的開始安裝 Ambari 了。

第三節. 安裝Ambari

安裝過程

首先需要獲取 Ambari 的公共庫檔案(public repository)。登入到 Linux 主機並執行下面的命令(也可以自己手工下載):

$ sudo -i
$ cd /etc/apt/sources.list.d
$ wget http://public-repo-1.hortonworks.com/ambari/ubuntu14/2.x/updates/2.2.2.0/ambari.list
$ apt-key adv --recv-keys --keyserver keyserver.ubuntu.com B9733A7A07513CAD
$ apt-get update
$ apt-get install ambari-server

如果執行apt-key adv --recv-keys --keyserver keyserver.ubuntu.com B9733A7A07513CAD失敗,請使用代理方式,如下

$ apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 B9733A7A07513CAD

待安裝完成後,便需要對Ambari Server做一個簡單的配置。執行下邊的命令。

$ ambari-server setup

在這個互動式的設定中,採用預設配置即可。Ambari會使用Postgres資料庫,預設會安裝並使用Oracle的JDK。預設設定了Amabri GUI的登陸使用者名稱為admin/admin。並且指定Ambari Server的執行使用者為root 簡單的setup配置完成後。就可以啟動Ambari了。執行下面的命令。

$ ambari-server start

當成功啟動 Ambari Server 之後,便可以從瀏覽器登入,預設的埠為 8080。以本文環境為例,在瀏覽器的位址列輸入 http://node0.example.com:8080,登入密碼為 admin/admin。登入 Ambari 之後的頁面如下圖

至此,Ambari Server 就安裝完成了。

第四節.部署一個Hadoop2.x叢集

登入 Ambari 之後,點選按鈕“Launch Install Wizard”,就可以開始建立屬於自己的大資料平臺。

第一步命名叢集的名字。本環境為bigdata。

第二步選擇一個Stack,這個Stack相當於一個Hadoop生態圈軟體的集合。Stack的版本越高,裡面的軟體版本也就越高。這裡我們選擇 HDP2.4,裡面的對應的Hadoop版本為2.7.x。

第三步指定Agent機器(如果配置了域,必須包含完整域名,例如本文環境的域為example.com),這些機器會被安裝Hadoop等軟體包。還記得在安裝章節中提到的SSH無密碼登陸嗎,這裡需要指定當時在Ambari Server機器生成的私鑰(ssh-keygen生成的,公鑰已經拷貝到Ambari Agent的機器,具體的SSH無密碼登入配置,可以在網上很容易找到配置方法,不在此贅述)。另外不要選擇“Perform manual registration on hosts and do not use SSH“。因為我們需要Ambari Server自動去安裝Ambari Agent。

Target Hosts中填

node[0-3].example.com
或
node0.example.com
node1.example.com
node2.example.com
node3.example.com

第四步Ambari Server會自動安裝Ambari Agent到剛才指定的機器列表。安裝完成後,Agent會向 Ambari Server註冊。成功註冊後,就可以繼續Next到下一步。

To manually resolve issues on each host run the HostCleanup script (Python 2.6 or greater is required):

python /usr/lib/python2.6/site-packages/ambari_agent/HostCleanup.py --silent --skip=users

Note: Clean up of Firewall and Transparent Huge Page issues are not supported by the HostCleanup script.

Note: To clean up in interactive mode, remove --silent option. To clean up all resources, including users, remove --skip=users option. Use --help for a list of available options.

注意:如果沒有將transparent_hugepage關閉的話,會報以上錯誤,如何設定為關閉狀態請參照準備部分

第五步這裡我們終於看到跟Hadoop有關的名詞了。在這一步,我們需要選擇要安裝的軟體名稱。本文環境選擇了 HDFS,YARN+MapReduce2,Zoopkeeper,Storm以及Spark。選的越多,就會需要越多的機器記憶體。選擇之後就可以繼續下一步了。這裡需要注意某些Service是有依賴關係的。如果您選了一個需要依賴其他Service的一個 Service,Ambari 會提醒安裝對應依賴的 Service。

第六步和第七步分別是選擇安裝軟體所指定的 Master機器和Slave機器,以及Client機器。這裡使用預設選擇即可(真正在生產環境中,需要根據具體的機器配置選擇)。

第八步就是Service的配置。絕大部分配置已經有預設值,不需要修改,初學者,如果不需要進行調優是可以直接使用預設配置的。有些Service會有一些必須的手工配置項,則必須手動輸入,才可以下一步。本文環境直接使用預設配置。

第九步Ambari會總結一個安裝列表,供使用者審閱。這裡沒問題,就直接下一步。

第十步Ambari會開始安裝選擇的Service到Ambari Agent的機器。這裡可能需要等好一會,因為都是線上安裝。安裝完成之後,Ambari就會啟動這些Service。

安裝完成之後,就可以檢視Ambari的Dashboard了。

第五節. 安裝過程中的常見問題

在第四節中第十步遇到的問題:

stderr: /var/lib/ambari-agent/data/errors-1265.txt

Python script has been killed due to timeout after waiting 1800 secs

stdout: /var/lib/ambari-agent/data/output-1265.txt

2016-10-04 19:40:43,872 - Using hadoop conf dir: /usr/hdp/current/hadoop-client/conf 2016-10-04 19:40:43,874 - Group['spark'] {} 2016-10-04 19:40:43,876 - Group['hadoop'] {} 2016-10-04 19:40:43,877 - Group['users'] {} 2016-10-04 19:40:43,877 - User['hive'] {'gid': 'hadoop', 'fetch_nonlocal_groups': True, 'groups': [u'hadoop']} 2016-10-04 19:40:43,884 - User['zookeeper'] {'gid': 'hadoop', 'fetch_nonlocal_groups': True, 'groups': [u'hadoop']} 2016-10-04 19:40:43,886 - User['spark'] {'gid': 'hadoop', 'fetch_nonlocal_groups': True, 'groups': [u'hadoop']} 2016-10-04 19:40:43,887 - User['ambari-qa'] {'gid': 'hadoop', 'fetch_nonlocal_groups': True, 'groups': [u'users']} 2016-10-04 19:40:43,888 - User['tez'] {'gid': 'hadoop', 'fetch_nonlocal_groups': True, 'groups': [u'users']} 2016-10-04 19:40:43,897 - User['hdfs'] {'gid': 'hadoop', 'fetch_nonlocal_groups': True, 'groups': [u'hadoop']} 2016-10-04 19:40:43,899 - User['yarn'] {'gid': 'hadoop', 'fetch_nonlocal_groups': True, 'groups': [u'hadoop']} 2016-10-04 19:40:43,900 - User['hcat'] {'gid': 'hadoop', 'fetch_nonlocal_groups': True, 'groups': [u'hadoop']} 2016-10-04 19:40:43,901 - User['mapred'] {'gid': 'hadoop', 'fetch_nonlocal_groups': True, 'groups': [u'hadoop']} 2016-10-04 19:40:43,902 - File['/var/lib/ambari-agent/tmp/changeUid.sh'] {'content': StaticFile('changeToSecureUid.sh'), 'mode': 0555} 2016-10-04 19:40:43,917 - Execute['/var/lib/ambari-agent/tmp/changeUid.sh ambari-qa /tmp/hadoop-ambari-qa,/tmp/hsperfdata_ambari-qa,/home/ambari-qa,/tmp/ambari-qa,/tmp/sqoop-ambari-qa'] {'not_if': '(test $(id -u ambari-qa) -gt 1000) || (false)'} 2016-10-04 19:40:43,944 - Skipping Execute['/var/lib/ambari-agent/tmp/changeUid.sh ambari-qa /tmp/hadoop-ambari-qa,/tmp/hsperfdata_ambari-qa,/home/ambari-qa,/tmp/ambari-qa,/tmp/sqoop-ambari-qa'] due to not_if 2016-10-04 19:40:43,945 - Group['hdfs'] {} 2016-10-04 19:40:43,946 - User['hdfs'] {'fetch_nonlocal_groups': True, 'groups': [u'hadoop', u'hdfs']} 2016-10-04 19:40:43,947 - FS Type: 2016-10-04 19:40:43,948 - Directory['/etc/hadoop'] {'mode': 0755} 2016-10-04 19:40:43,948 - Directory['/var/lib/ambari-agent/tmp/hadoop_java_io_tmpdir'] {'owner': 'hdfs', 'group': 'hadoop', 'mode': 0777} 2016-10-04 19:40:43,969 - Repository['HDP-2.4'] {'base_url': 'http://public-repo-1.hortonworks.com/HDP/ubuntu14/2.x/updates/2.4.3.0', 'action': ['create'], 'components': [u'HDP', 'main'], 'repo_template': ' ', 'repo_file_name': 'HDP', 'mirror_list': None} 2016-10-04 19:40:43,983 - File['/tmp/tmp4uQgmE'] {'content': 'deb http://public-repo-1.hortonworks.com/HDP/ubuntu14/2.x/updates/2.4.3.0 HDP main'} 2016-10-04 19:40:43,984 - Writing File['/tmp/tmp4uQgmE'] because contents don't match 2016-10-04 19:40:43,985 - File['/tmp/tmp_VkOpI'] {'content': StaticFile('/etc/apt/sources.list.d/HDP.list')} 2016-10-04 19:40:43,986 - Writing File['/tmp/tmp_VkOpI'] because contents don't match 2016-10-04 19:40:43,987 - Repository['HDP-UTILS-1.1.0.20'] {'base_url': 'http://public-repo-1.hortonworks.com/HDP-UTILS-1.1.0.20/repos/ubuntu12', 'action': ['create'], 'components': [u'HDP-UTILS', 'main'], 'repo_template': ' ', 'repo_file_name': 'HDP-UTILS', 'mirror_list': None} 2016-10-04 19:40:43,988 - File['/tmp/tmpJKZpNo'] {'content': 'deb http://public-repo-1.hortonworks.com/HDP-UTILS-1.1.0.20/repos/ubuntu12 HDP-UTILS main'} 2016-10-04 19:40:43,989 - Writing File['/tmp/tmpJKZpNo'] because contents don't match 2016-10-04 19:40:43,992 - File['/tmp/tmpOBa7MZ'] {'content': StaticFile('/etc/apt/sources.list.d/HDP-UTILS.list')} 2016-10-04 19:40:43,993 - Writing File['/tmp/tmpOBa7MZ'] because contents don't match 2016-10-04 19:40:43,995 - Package['unzip'] {'retry_on_repo_unavailability': False, 'retry_count': 5} 2016-10-04 19:40:44,033 - Skipping installation of existing package unzip 2016-10-04 19:40:44,033 - Package['curl'] {'retry_on_repo_unavailability': False, 'retry_count': 5} 2016-10-04 19:40:44,063 - Skipping installation of existing package curl 2016-10-04 19:40:44,063 - Package['hdp-select'] {'retry_on_repo_unavailability': False, 'retry_count': 5} 2016-10-04 19:40:44,096 - Skipping installation of existing package hdp-select 2016-10-04 19:40:44,335 - Using hadoop conf dir: /usr/hdp/current/hadoop-client/conf 2016-10-04 19:40:44,347 - Using hadoop conf dir: /usr/hdp/current/hadoop-client/conf 2016-10-04 19:40:44,356 - Package['rpcbind'] {'retry_on_repo_unavailability': False, 'retry_count': 5} 2016-10-04 19:40:44,397 - Skipping installation of existing package rpcbind 2016-10-04 19:40:44,398 - Package['hadoop-2-4-.-client'] {'retry_on_repo_unavailability': False, 'retry_count': 5} 2016-10-04 19:40:44,421 - Installing package hadoop-2-4-.-client ('/usr/bin/apt-get -q -o Dpkg::Options::=--force-confdef --allow-unauthenticated --assume-yes install 'hadoop-2-4-.*-client'')

之所以出現此問題,是因為ambari server在控制agent安裝yarn時,由於安裝yarn超過了ambari預設的1800s導致的。

解決方案: 1.手動安裝yarn apt-get update apt-get install hadoop-2-4-.*-yarn

2.修改配置檔案 Can be solved by setting the timeout (agent.package.install.task.timeout=1800) in /etc/ambari-server/conf/ambari.properties

注意:在安裝mapreduce,spark等軟體包時,也可能出現類似的問題,請將timeout設定到合適的時間。或者根據錯誤提示,手動安裝相應的軟體包。

在啟動叢集時,遇到如下問題:

resource_management.core.exceptions.Fail: Execution of 'curl -sS -L -w '%{http_code}' -X GET 'http://node1.example.com:50070/webhdfs/v1/user/spark?op=GETFILESTATUS&user.name=hdfs' 1>/tmp/tmpR0jGl5 2>/tmp/tmp0XYJ6w' returned 7. curl: (7) Failed to connect to node1.example.com port 50070: Connection refused

原因:是因為在配置各個節點時的hostname時,沒有刪除127.0.0.1的相關內容引起的。具體操作請檢視第二節中的內容