天天看點

ubuntu安裝Ganglia監控Hadoop及Hbase叢集性能(安裝配置)

1 Ganglia簡介

Ganglia 是 UC Berkeley 發起的一個開源監視項目,設計用于測量數以千計的節點。每台計算機都運作一個收集和發送度量資料(如處理器速度、記憶體使用量等)的名為 gmond 的守護程序。它将從作業系統和指定主機中收集。接收所有度量資料的主機可以顯示這些資料并且可以将這些資料的精簡表單傳遞到層次結構中。正因為有這種層次結構模式,才使得 Ganglia 可以實作良好的擴充。gmond 帶來的系統負載非常少,這使得它成為在叢集中各台計算機上運作的一段代碼,而不會影響使用者性能

1.1 Ganglia元件

Ganglia 監控套件包括三個主要部分:gmond,gmetad,和網頁接口,通常被稱為ganglia-web。

Gmond :是一個守護程序,他運作在每一個需要監測的節點上,收集監測統計,發送和接受在同一個多點傳播或單點傳播通道上的統計資訊 如果他是一個發送者(mute=no)他會收集基本名額,比如系統負載(load_one),CPU使用率。他同時也會發送使用者通過添加C/Python子產品來自定義的名額。 如果他是一個接收者(deaf=no)他會聚合所有從别的主機上發來的名額,并把它們都儲存在記憶體緩沖區中。

Gmetad:也是一個守護程序,他定期檢查gmonds,從那裡拉取資料,并将他們的名額存儲在RRD存儲引擎中。他可以查詢多個叢集并聚合名額。他也被用于生成使用者界面的web前端。

Ganglia-web :顧名思義,他應該安裝在有gmetad運作的機器上,以便讀取RRD檔案。 叢集是主機和度量資料的邏輯分組,比如資料庫伺服器,網頁伺服器,生産,測試,QA等,他們都是完全分開的,你需要為每個叢集運作單獨的gmond執行個體。

一般來說每個叢集需要一個接收的gmond,每個網站需要一個gmetad。

ubuntu安裝Ganglia監控Hadoop及Hbase叢集性能(安裝配置)

Ganglia工作流如圖1所示:

左邊是運作在各個節點上的gmond程序,這個程序的配置隻由節點上/etc/gmond.conf的檔案決定。是以,在各個監視節點上都需要安裝和配置該檔案。

右上角是更加負責的中心機(通常是這個叢集中的一台,也可以不是)。在這個台機器上運作這着gmetad程序,收集來自各個節點上的資訊并存儲在RRDtool上,該程序的配置隻由/etc/gmetad.conf決定。   

右下角顯示了關于網頁方面的一些資訊。我們的浏覽網站時調用php腳本,從RRDTool資料庫中抓取資訊,動态的生成各類圖表。

1.2 Ganglia運作模式(單點傳播與多點傳播)  

Ganglia的收集資料工作可以工作在單點傳播(unicast)或多點傳播(multicast)模式下,預設為多點傳播模式。

單點傳播:發送自己收集到的監控資料到特定的一台或幾台機器上,可以跨網段。

多點傳播:發送自己收集到的監控資料到同一網段内所有的機器上,同時收集同一網段内的所有機器發送過來的監控資料。因為是以廣播包的形式發送,是以需要同一網段内。但同一網段内,又可以定義不同的發送通道。

2 環境

平台:ubuntu12.04

Hadoop: hadoop-1.0.1

Hbase: hbase-0.92.1

拓撲:

ubuntu安裝Ganglia監控Hadoop及Hbase叢集性能(安裝配置)

3 安裝部署(單點傳播)

3.1 部署方式

監測節點(gmond):slave1、slave2、slave3

主節點(gmetad、ganglia-web)master

3.2 安裝

這裡必須說明一個問題,我是在ubuntu下直接安裝的。因為涉及到版本問題,hadoop-1.0.1和hbase-0.92.1均支援ganglia3.0和ganglia3.1版本,但是在配置時加載的子產品是不一樣的。是以,我們需要知道安裝的ganglia是什麼版本。

<pre style="line-height: 20px;">#sudo apt-cache show ganglia-webfrontend ganglia-monitor
           

我們可以發現,安裝的版本是ganglia3.1.7,是以是支援的。是以在master這台主機上安裝ganglia-webfrontend和ganglia-monitor。在其他監視節點上,隻需要安裝ganglia-monitor即可。

#sudo apt-get install ganglia-webfrontend ganglia-monitor      

将ganglia的檔案連結到apache的預設目錄下

#sudo ln -s /usr/share/ganglia-webfrontend /var/www/ganglia      

Ganglia-webfrontend等同與上面所說的gmetad及ganglia-web,同時還會自動幫你安裝apache2和rrdtool,非常友善。

3.3 Ganglia配置

在各個節點上,都需要配置/etc/ganglia/gmond.conf,配置相同如下所示:

globals {                    
  daemonize = yes              #以背景的方式運作
  setuid = yes
  user = hadoop              #運作gmond的使用者
  debug_level = 0             #調試級别
  max_udp_msg_len = 1472      
  mute = no       #啞巴,本節點将不會再廣播任何自己收集到的資料在網絡上  
  deaf = no       #聾子,本節點不會再接收任何其他節點廣播的資料包      
  host_dmax = 0 /*secs */ 
  cleanup_threshold = 300 /*secs */ 
  gexec = no             #是否使用gexec
  send_metadata_interval = 10     #節點發送間隔/*secs*/
} 

/* If a cluster attribute is specified, then all gmond hosts are wrapped inside 
 * of a  tag.  If you do not specify a cluster tag, then all  will 
 * NOT be wrapped inside of a  tag. */ 
cluster { 
  name = "hadoop"   #本節點屬于哪個cluster
  owner = "unspecified"        #誰是該節點的所有者
  latlong = "unspecified"    #在地球上的坐标
  url = "unspecified" 
} 

/* The host section describes attributes of the host, like the location */ 
host { 
  location = "unspecified" 
} 

/* Feel free to specify as many udp_send_channels as you like.  Gmond 
   used to only support having a single channel */ 
udp_send_channel {    #udp包的發送通道
  host = master        #多點傳播,工作在239.2.11.71通道下。單點傳播,則指向主節點,單點傳播模式下也可以配置多個udp_send_channel
  port = 8649            #監聽端口
  ttl = 1 
} 

/* You can specify as many udp_recv_channels as you like as well. */ 
udp_recv_channel {  #接受UDP包配置
# mcast_join = 239.2.11.71
  port = 8649 
# bind = 239.2.11.71
}
      

請注意send_metadata_interval被設定為10秒。Ganglia的度量名額從他的中繼資料間隔發送得到的。中繼資料包含諸如度量分組,類型等等。假如你重新開機了接收的gmond主機,那麼中繼資料就會丢失,gmond就不知道如何處理度量資料,是以會把他們抛棄。這會導緻生成空白的圖表。在多點傳播模式下,gmonds可以和其他任意一台主機通信,在中繼資料丢失情況請求重新擷取。但這在單點傳播模式下是不可能的,是以你需要指令gmond定期的發送中繼資料。ubuntu以hadoop使用者登陸,是以user=hadoop。

在主節點上(master)上還需要配置/etc/ganglia/gmetad.conf,這裡面的名字“hadoop”和上面gmond.conf中應該是一緻的。

data_source "hadoop" master slave1 slave2 slave3

也可以以master:8649的形式寫,若不寫,ganglia預設端口為8649,也可以使用其他端口。

3.4 Hadoop配置

所有hadoop所在的節點,均需要配置hadoop-metrics2.properties,配置如下:

# syntax: [prefix].[source|sink|jmx].[instance].[options]
# See package.html for org.apache.hadoop.metrics2 for details

*.sink.file.class=org.apache.hadoop.metrics2.sink.FileSink

#namenode.sink.file.filename=namenode-metrics.out

#datanode.sink.file.filename=datanode-metrics.out

#jobtracker.sink.file.filename=jobtracker-metrics.out

#tasktracker.sink.file.filename=tasktracker-metrics.out

#maptask.sink.file.filename=maptask-metrics.out

#reducetask.sink.file.filename=reducetask-metrics.out
# Below are for sending metrics to Ganglia
#
# for Ganglia 3.0 support
# *.sink.ganglia.class=org.apache.hadoop.metrics2.sink.ganglia.GangliaSink30
#
# for Ganglia 3.1 support
*.sink.ganglia.class=org.apache.hadoop.metrics2.sink.ganglia.GangliaSink31

*.sink.ganglia.period=10

# default for supportsparse is false
*.sink.ganglia.supportsparse=true

*.sink.ganglia.slope=jvm.metrics.gcCount=zero,jvm.metrics.memHeapUsedM=both
*.sink.ganglia.dmax=jvm.metrics.threadsBlocked=70,jvm.metrics.memHeapUsedM=40

namenode.sink.ganglia.servers=master:8649

datanode.sink.ganglia.servers=master:8649

jobtracker.sink.ganglia.servers=master:8649

tasktracker.sink.ganglia.servers=master:8649

maptask.sink.ganglia.servers=master:8649

reducetask.sink.ganglia.servers=master:8649      

注意:master節點中隻去掉了namenode.sink.ganglia.servers和jobtracker.sink.ganglia.servers這兩個注釋段,如果是slave,就反之。如下:

3.5 Hbase配置

所有hbase所在的節點,均需要配置hadoop-metrics.properties,配置如下:

# See http://wiki.apache.org/hadoop/GangliaMetrics
# Make sure you know whether you are using ganglia 3.0 or 3.1.
# If 3.1, you will have to patch your hadoop instance with HADOOP-4675
# And, yes, this file is named hadoop-metrics.properties rather than
# hbase-metrics.properties because we're leveraging the hadoop metrics
# package and hadoop-metrics.properties is an hardcoded-name, at least
# for the moment.
#
# See also http://hadoop.apache.org/hbase/docs/current/metrics.html


# Configuration of the "hbase" context for null
# hbase.class=org.apache.hadoop.metrics.spi.NullContext


# Configuration of the "hbase" context for file
# hbase.class=org.apache.hadoop.hbase.metrics.file.TimeStampingFileContext
# hbase.period=10
# hbase.fileName=/tmp/metrics_hbase.log


# HBase-specific configuration to reset long-running stats (e.g. compactions)
# If this variable is left out, then the default is no expiration.
hbase.extendedperiod = 3600


# Configuration of the "hbase" context for ganglia
# Pick one: Ganglia 3.0 (former) or Ganglia 3.1 (latter)
# hbase.class=org.apache.hadoop.metrics.ganglia.GangliaContext
 hbase.class=org.apache.hadoop.metrics.ganglia.GangliaContext31
 hbase.period=10
 hbase.servers=master:8649


# Configuration of the "jvm" context for null
# jvm.class=org.apache.hadoop.metrics.spi.NullContext


# Configuration of the "jvm" context for file
# jvm.class=org.apache.hadoop.hbase.metrics.file.TimeStampingFileContext
# jvm.period=10
# jvm.fileName=/tmp/metrics_jvm.log


# Configuration of the "jvm" context for ganglia
# Pick one: Ganglia 3.0 (former) or Ganglia 3.1 (latter)
# jvm.class=org.apache.hadoop.metrics.ganglia.GangliaContext
 jvm.class=org.apache.hadoop.metrics.ganglia.GangliaContext31
 jvm.period=10
 jvm.servers=master:8649


# Configuration of the "rpc" context for null
# rpc.class=org.apache.hadoop.metrics.spi.NullContext


# Configuration of the "rpc" context for file
# rpc.class=org.apache.hadoop.hbase.metrics.file.TimeStampingFileContext
# rpc.period=10
# rpc.fileName=/tmp/metrics_rpc.log


# Configuration of the "rpc" context for ganglia
# Pick one: Ganglia 3.0 (former) or Ganglia 3.1 (latter)
# rpc.class=org.apache.hadoop.metrics.ganglia.GangliaContext
 rpc.class=org.apache.hadoop.metrics.ganglia.GangliaContext31
 rpc.period=10
 rpc.servers=master:8649      

4 啟動與檢驗

先需要重新開機hadoop和hbase 。啟動順序非常重要,再啟動主節點master的gmetad服務,在啟動各個節點上的gmond服務,否則圖表不顯示。

#sudo service gmetad start      
#sudo service ganglia-monitor start      

可以通過master/ganglia來檢視。

ubuntu安裝Ganglia監控Hadoop及Hbase叢集性能(安裝配置)

可以看到hadoop相關屬相:

ubuntu安裝Ganglia監控Hadoop及Hbase叢集性能(安裝配置)

以及hbase相關屬性:

ubuntu安裝Ganglia監控Hadoop及Hbase叢集性能(安裝配置)

5 參考資料

 http://www.uml.org.cn/sjjm/201305171.asp

1、http://ganglia.sourceforge.net/

2、http://linuxjcq.blog.51cto.com/3042600/759008

3、http://cryinstall.com/?p=180

4、https://wiki.freebsdchina.org/howto/g/gangliainit

5、http://abloz.com/2012/09/19/ganglia-monitoring-hadoop.html

6、http://www.ibm.com/developerworks/wikis/display/wikiptype/ganglia

繼續閱讀