Ambari安裝及自定義service初步實現(xiàn)
Ambari安裝
1 Ambari簡介
Apache Ambari項目的目的是通過開發(fā)軟件來配置、監(jiān)控和管理hadoop集群,以使hadoop的管理更加簡單。同時,ambari也提供了一個基于它自身RESTful接口實現(xiàn)的直觀、簡單易用的web管理界面。
Ambari允許系統(tǒng)管理員進行以下操作:
1. 提供安裝管理hadoop集群;
2. 監(jiān)控一個hadoop集群;
3. 擴展ambari管理自定義服務(wù)功能.
2 集群所需基礎(chǔ)條件
2.1 操作系統(tǒng)的需求
? Red Hat Enterprise Linux (RHEL) 版本5.x 或者 6.x (64位) ;
? CentOS版本5.x、6.x (64位) 或7.x;
? Oracle Linux版本5.x 或者6.x (64位) ;
本文檔選擇的是CentOS版本 6.5 (64位) ;
2.2 系統(tǒng)基礎(chǔ)軟件的需求
在每一臺主機上都要安裝以下軟件:
(1) yum和rpm (RHEL/CentOS/Oracle Linux);
(2)zypper(SLES);
(3)scp,curl,wget;
2.3 JDK的需求
Oracle JDK 1.7.0_79 64-bit (默認)
OpenJDK 7 64-bit (SLES不支持)
3 安裝各項軟件前的先決條件
3.1 ambari和監(jiān)控軟件所需條件
安裝ambari之前,為了保證ambari各項服務(wù)和各項監(jiān)控服務(wù)的正常運行,根據(jù)操作系統(tǒng)的不同,需要確定一些已經(jīng)安裝的軟件的版本,以下列出的軟件版本必須符合要求。即:如果現(xiàn)有的系統(tǒng)上有以下軟件,版本必須與下面列出的版本完全一致,如果沒有的話安裝程序會自行安裝。
圖表3-1軟件先決配置表
3.2 Ambari與HDP版本兼容性
由于軟件版本的升級,各版本之間由于版本之間的兼容性可能會導(dǎo)致一些問題。
表格 3-2 版本兼容性
4 安裝實例說明
本文所選擇的系統(tǒng)與軟件版本,如下表所示:
表格 4-1系統(tǒng)與軟件版本
4.1 安裝Ambari前的操作系統(tǒng)準備
4.1.1 配置主機名
Ambari配置集群信息的時候是通過全限定主機名來確定集群中的機器信息的,所以必須確保主機名無誤。
4.1.2 配置集群信息
在每一臺機器的hosts文件上都要做映射配置,命令如下:
# vi /etc/hosts
然后添加如下內(nèi)容:
表格 4-2 ip映射信息表
4.1.3 配置ssh免密碼互通
首先,在主節(jié)點和其他節(jié)點上都執(zhí)行以下命令,以確保每臺機器都可產(chǎn)生公鑰。
然后一路回車即可.然后將每個節(jié)點的公鑰組成一個新的authorized_keys文件,然后將其分發(fā)到每個節(jié)點中.從而,完成了各個節(jié)點的免密登錄操作.
4.1.4 配置NTP時間同步
首先在主節(jié)點上做如下操作:
(1) 安裝時間服務(wù)器ntp:
#yum install ntp
(2) 修改ntpd配置文件
(3) 開啟時間同步服務(wù)器
#sevrice ntpd start
(4) 在其他各個從節(jié)點做相同操作,至此ntp同步完成
4.1.5關(guān)閉selinux
永久關(guān)閉SELinux
# vi /etc/selinux/config
將SELINUX=enforcing改為SELINUX=disabled
重啟生效,重啟命令為:
# reboot
4.1.6關(guān)閉iptables防火墻
永久關(guān)閉(需要重啟)
# chkconfig iptables off
暫時關(guān)閉防火墻服務(wù)(需要重啟防火墻)
service iptables stop
查看防火墻狀態(tài)
# chkconfig –list|grep iptables
提示:Linux下的其它服務(wù)都可以用以上命令執(zhí)行開啟和關(guān)閉操作
重啟生效,重啟命令為:
# reboot
4.2 創(chuàng)建yum本地源
首先檢驗主節(jié)點是否安裝httpd服務(wù)器,命令如下:
rpm -qa |grep httd
若沒有,則安裝,命令如下:
#yum install httpd
啟動httpd
#service httpd start
chkconfig httpd on
對文件夾與子文件夾內(nèi)所有文件授予同一權(quán)限,命令如下:
chmod –R ugo+rX /var/www/html
打開網(wǎng)絡(luò)
vim /etc/sysconfig/network-script/ifcfg-eth0
修改為onboot=yes
安裝成功之后,Apache工作目錄默認在/var/www/html。
配置:
檢查端口是否占用,Apache http服務(wù)使用80端口
[root@master ~]$ netstat -nltp | grep 80
如果有占用情況,安裝完畢之后需要修改Apache http服務(wù)的端口號:
[root@ master ~]$ vi /etc/httpd/conf/httpd.conf
修改監(jiān)聽端口,Listen 80為其他端口。
將所下載的安裝文件放在/etc/www/html下,然后啟動
[root@ master ~]$ service httpd start
可以在瀏覽器中查看http://master 看到Apache server的一些頁面信息,表示啟動成功。
5 完全離線安裝Ambari前的準備
離線安裝跟在線安裝的區(qū)別在于yum所使用的倉庫的位置不同,即把遠程的倉庫中的安裝包等資源拷貝一份兒放在本地,然后在yum倉庫包文件夾中創(chuàng)建這些資源的本地倉庫包,即可按照在線安裝的方式進行安裝就行了。不過離線安裝需要先解決Ambari的rpm包的依賴性問題,即首先要確保已經(jīng)安裝了postgresql8.4.3,或者有本地postgresql8.4.3倉庫。
5.1 先決條件
Ambari的離線安裝,需要使用yum,如果是新安裝的操作系統(tǒng),可能缺少很多必要的條件,以下表格按照從前往后的順序,依次說明,如果已經(jīng)實現(xiàn)了某些條件,跳過那些條件即可。
因操作系統(tǒng)中本身自帶軟件的復(fù)雜性,如在安裝中提示有其他所需軟件或提示現(xiàn)有軟件升級,按照提示解決即可.
5.2 建立本地資源庫
在集群內(nèi)部某臺機器上安裝http服務(wù)即可,然后將提供的tar包或者rpm包放置到那臺機器上的/var/www/html目錄(Apache默認目錄)下解壓即可,最好在這個目錄下新建一個目錄,將所有的ambari的tar包和HDP及HDPUTIL的tar包都放置進去并解壓,如果機器沒有手動安裝PostgreSQL,將提供的上述軟件的軟件包一并放入到本地資源庫中即可。
5.3 設(shè)置yum不檢查gpg密鑰
經(jīng)檢測離線安裝Hadoop集群時會因為yum檢查要安裝的軟件的gpg密鑰而導(dǎo)致錯誤,此時可通過關(guān)閉系統(tǒng)的yum gpg檢查來規(guī)避錯誤
# vi /etc/yum.conf
設(shè)置gpgcheck屬性值為0即可
gpgcheck=0
5.4 安裝ambari服務(wù)
# yum –install ambari-server
5.5 ambari設(shè)置
# ambari-server setup
運行過后則會出現(xiàn)是否進入ambari-server守護進程,選擇jdk,配置數(shù)據(jù)庫等信息,可根據(jù)系統(tǒng)自身需要進行選擇.
當(dāng)出現(xiàn)“Ambari Server ‘setup’ completed successfully”,則說明Ambari-server配置成功。需要說明的是,此次安裝選擇的數(shù)據(jù)庫是PostgreSQL數(shù)據(jù)庫,其中用戶、數(shù)據(jù)庫等都是提前默認好的;若選擇MySQL數(shù)據(jù)庫,則需要在安裝Ambari-server之前建好用戶、賦予權(quán)限、建好數(shù)據(jù)庫等等操作。
然后啟動ambari-server,最后根據(jù)需要安裝hadoop生態(tài)中的各項服務(wù).
自定義service服務(wù)
1 ambari自定義擴展service
從第一部分可知,ambari具有進行二次開發(fā)的功能,主要工作就是將自研的組件等集成到ambari中,并對其進行管理監(jiān)控.本文主要以集成redis為例進行講述.
首先,由于service都是隸屬于stack的,所以要決定自定義一個service屬于哪個stack.,又因為已經(jīng)安裝了HDP2.5.0具有stack,所以,本文將自定的service放置在HDP2.5.0的stack下.新建service名為:redis-service,其中包含結(jié)構(gòu)圖如下圖所示:
其中configurate中的xml文件主要安裝完成配置該模塊的調(diào)用,package中主要問控制service生命周期的python文件,metainfo.xml文件則主要問定義service的一些屬性,metrics.json與widgets.json控制著service的界面圖表顯示.
其中metainfo.xml實例如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 | <?xml version="1.0"?> <metainfo> <schemaVersion>2.0</schemaVersion> <services> <service> <name>REDIS-SERVICE</name> <displayName>Reids</displayName> <comment>My Service</comment> <version>1.0</version> <components> <component> <name>MASTER</name> <displayName>Master</displayName> <category>MASTER</category> <timelineAppid>redis</timelineAppid> <cardinality>1</cardinality> <commandScript> <script>scripts/master.py</script> <scriptType>PYTHON</scriptType> <timeout>5000</timeout> </commandScript> </component> <component> <name>SALVE</name> <displayName>Slave</displayName> <category>SLAVE</category> <cardinality>1+</cardinality> <commandScript> <script>scripts/slave.py</script> <scriptType>PYTHON</scriptType> <timeout>5000</timeout> </commandScript> </component> </components> <osSpecifics> <osSpecific> <osFamily>any</osFamily> </osSpecific> </osSpecifics> </service> </services> </metainfo> |
其次,需要創(chuàng)建 Service 的生命周期控制腳本master.py 和 slave.py。這里需要保證腳本路徑和上一步中 metainfo.xml 中的配置路徑是一致的。這兩個 Python 腳本是用來控制 Master 和 Slave 模塊的生命周期。腳本中函數(shù)的含義也如其名字一樣:install 就是安裝調(diào)用的接口;start、stop 分別就是啟停的調(diào)用;Status 是定期檢查 component 狀態(tài)的調(diào)用。其中master.py與slave.py的模板為:
Master.py
1 2 3 4 5 6 7 8 9 10 11 12 13 | class Master(Script): def install(self, env): print "Install Redis Master" def configure(self, env): print "Configure Redis Master" def start(self, env): print "Start Redis Master" def stop(self, env): print "Stop Redis Master" def status(self, env): print "Status..." if __name__ == "__main__": Master().execute() |
Slave.py
1 2 3 4 5 6 7 8 9 10 11 12 13 | class Slave(Script): def install(self, env): print "Install Redis Slave" def configure(self, env): print "Configure Redis Slave" def start(self, env): print "Start Redis Slave" def stop(self, env): print "Stop Redis Slave" def status(self, env): print "Status..." if __name__ == "__main__": Slave().execute() |
再次,將redis的rpm安裝文件放入到HDP安裝包的/var/www/html/ambari/HDP/centos6/目錄下.
再次,重啟ambari-server, 因為 Ambari Server 只有在重啟的時候才會讀取 Service 和 Stack 的配置。命令行執(zhí)行:ambari-server restart.
最后,登錄 Ambari 的 GUI,點擊左下角的 Action,選擇 Add Service。如下圖:
此時就可以在安裝service列表中看到Redis服務(wù)了.然后檢驗該服務(wù)是否安裝成功.
2 ambari實現(xiàn)自定義擴展service界面顯示
在第二章的第一節(jié)中service自定義中提及metircs.json與widget.json時, 其中Widget 也就是 Ambari Web 中呈現(xiàn) Metrics 的圖控件,它會根據(jù) Metrics 的數(shù)值,做出一個簡單的聚合運算,最終呈現(xiàn)在圖控件中。Widget 則進一步提升了 Ambari 的易用性,以及可配置化。Widget 是顯示 AMS 收集的 Metrics 屬性.
此處緊接著上節(jié),其中metrics.json模板為:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | { "REDIS-MASTER": { "Component": [ { "type": "ganglia", "metrics": { "default": { "metrics/total_connections_received": { "metric": "total_connections_received", "pointInTime": true, "temporal": true }, "metrics/total_commands_processed": { "metric": "total_commands_processed", "pointInTime": true, "temporal": true }, "metrics/used_cpu_sys": { "metric": "used_cpu_sys", "pointInTime": true, "temporal": true }, "metrics/used_cpu_sys_children": { "metric": "used_cpu_sys_children", "pointInTime": true, "temporal": true } } } } ] } } |
widget.json為:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | { "layouts": [ { "layout_name": "default_redis_dashboard", "display_name": "Standard REDIS Dashboard", "section_name": "REDIS_SUMMARY", "widgetLayoutInfo": [ { "widget_name": "Redis info", "description": "Redis info", "widget_type": "GRAPH", "is_visible": true, "metrics": [ { "name": "total_connections_received", "metric_path": "metrics/total_connections_received", "service_name": "REDIS", "component_name": "REDIS-MASTER" } ], "values": [ { "name": "total_connections_received", "value": "${total_connections_received}" } ], "properties": { "graph_type": "LINE", "time_range": "1" } } } |
至此,重啟ambari-service,命令如下:
1 | ambari-server restart |
3 數(shù)據(jù)采集及發(fā)送
利用shell腳本將redis運行信息數(shù)據(jù)采集并一次性發(fā)送到metrics collector中,腳本如下所示:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | #!/bin/sh url=http://$1:6188/ws/v1/timeline/metrics while [ 1 ] do total_connections_received=$(redis-cli info |grep total_connections_received:| awk -F ':' '{print $2}') total_commands_processed=$(redis-cli info |grep total_commands_processed:| awk -F ':' '{print $2}') millon_time=$(( $(date +%s%N) / 1000000 )) json="{ \"metrics\": [ { \"metricname\": \"total_connections_received\", \"appid\": \"redis\", \"hostname\": \"localhost\", \"timestamp\": ${millon_time}, \"starttime\": ${millon_time}, \"metrics\": { \"${millon_time}\": ${total_connections_received} } }, { \"metricname\": \"total_commands_processed\", \"appid\": \"redis\", \"hostname\": \"localhost\", \"timestamp\": ${millon_time}, \"starttime\": ${millon_time}, \"metrics\": { \"${millon_time}\": ${total_commands_processed} } } ] }" echo $json | tee -a /root/my_metric.log curl -i -X POST -H "Content-Type: application/json" -d "${json}" ${url} sleep 3 done |
運行如下命令(這里要注意的是參數(shù) 1 是 Metrics Collector 的所在機器,并不是 Ambari Server所在的機器):
./metric_sender.sh ambari_collector_host total_connections_received redis
如果過程不出意外,等待2-4分鐘界面上即有數(shù)據(jù)顯示.通過上面的操作,可以實現(xiàn)將ambari沒有納入到監(jiān)控管理的軟件進行管理監(jiān)控。