使用ganglia監控hadoop及hbase集羣

1、Ganglia簡介php

Ganglia 是 UC Berkeley 發起的一個開源監視項目,設計用於測量數以千計的節點。每臺計算機都運行一個收集和發送度量數據(如處理器速度、內存使用量等)的名爲 gmond 的守護進程。它將從操做系統和指定主機中收集。接收全部度量數據的主機能夠顯示這些數據而且能夠將這些數據的精簡表單傳遞到層次結構中。正由於有這種層次結構模式,才使得 Ganglia 能夠實現良好的擴展。gmond 帶來的系統負載很是少,這使得它成爲在集羣中各臺計算機上運行的一段代碼,而不會影響用戶性能html

1.1 Ganglia組件前端

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

Gmond :是一個守護進程,他運行在每個須要監測的節點上,收集監測統計,發送和接受在同一個組播或單播通道上的統計信息 若是他是一個發送者(mute=no)他會收集基本指標,好比系統負載(load_one),CPU利用率。他同時也會發送用戶經過添加C/Python模塊來自定義的指標。 若是他是一個接收者(deaf=no)他會聚合全部從別的主機上發來的指標,並把它們都保存在內存緩衝區中。web

Gmetad:也是一個守護進程,他按期檢查gmonds,從那裏拉取數據,並將他們的指標存儲在RRD存儲引擎中。他能夠查詢多個集羣並聚合指標。他也被用於生成用戶界面的web前端。數據庫

Ganglia-web :顧名思義,他應該安裝在有gmetad運行的機器上,以便讀取RRD文件。 集羣是主機和度量數據的邏輯分組,好比數據庫服務器,網頁服務器,生產,測試,QA等,他們都是徹底分開的,你須要爲每一個集羣運行單獨的gmond實例。apache

通常來講每一個集羣須要一個接收的gmond,每一個網站須要一個gmetad。服務器

 

圖1 ganglia工做流app

Ganglia工做流如圖1所示:frontend

左邊是運行在各個節點上的gmond進程,這個進程的配置只由節點上/etc/gmond.conf的文件決定。因此,在各個監視節點上都須要安裝和配置該文件。

右上角是更加負責的中心機(一般是這個集羣中的一臺,也能夠不是)。在這個臺機器上運行這着gmetad進程,收集來自各個節點上的信息並存儲在RRDtool上,該進程的配置只由/etc/gmetad.conf決定。   

右下角顯示了關於網頁方面的一些信息。咱們的瀏覽網站時調用php腳本,從RRDTool數據庫中抓取信息,動態的生成各種圖表。

1.2 Ganglia運行模式(單播與多播)  

Ganglia的收集數據工做能夠工做在單播(unicast)或多播(multicast)模式下,默認爲多播模式。

單播:發送本身收集到的監控數據到特定的一臺或幾臺機器上,能夠跨網段。

多播:發送本身收集到的監控數據到同一網段內全部的機器上,同時收集同一網段內的全部機器發送過來的監控數據。由於是以廣播包的形式發送,所以須要同一網段內。但同一網段內,又能夠定義不一樣的發送通道。

 

2、安裝ganglia

一、拓撲說明
3臺主機,分別爲:

[plain]  view plain copy 在CODE上查看代碼片 派生到個人代碼片
 
  1. 10.171.29.191 master  
  2. 10.171.94.155  slave1  
  3. 10.251.0.197 slave3  


其中master將gmeta及web,三臺機都做gmon
如下步驟均使用root用戶執行

二、master上安裝gmeta及web

[plain]  view plain copy 在CODE上查看代碼片 派生到個人代碼片
 
  1. yum install ganglia-web.x86_64  
  2. yum install ganglia-gmetad.x86_64  


三、在三臺機上都安撫gmond

[plain]  view plain copy 在CODE上查看代碼片 派生到個人代碼片
 
  1. yum install ganglia-gmond.x86_64  


四、在三臺機器上配置/etc/ganglia/gmond.conf,修改如下內容:

[plain]  view plain copy 在CODE上查看代碼片 派生到個人代碼片
 
  1. udp_send_channel {  
  2.   #bind_hostname = yes # Highly recommended, soon to be default.  
  3.                        # This option tells gmond to use a source address  
  4.                        # that resolves to the machine's hostname.  Without  
  5.                        # this, the metrics may appear to come from any  
  6.                        # interface and the DNS names associated with  
  7.                        # those IPs will be used to create the RRDs.  
  8.   mcast_join = 10.171.29.191  
  9.   port = 8649  
  10.   ttl = 1  
  11. }  
  12. /* You can specify as many udp_recv_channels as you like as well. */  
  13. udp_recv_channel {  
  14.   #mcast_join = 239.2.11.71  
  15.   port = 8649  
  16.   #bind = 239.2.11.71  
  17. }  


即將默認的多播地址改成master地址,將udp_recv_channel 的2個IP註釋掉。

五、在master上修改/etc/ganglia/gmetad.conf
修改data_source,改爲:

[plain]  view plain copy 在CODE上查看代碼片 派生到個人代碼片
 
  1. data_source "my cluster」 10.171.29.191  


六、ln -s /usr/share/ganglia /var/www/ganglia
如有問題,能夠將/usr/share/ganglia的內容直接複製到/var/www/ganglia

七、修改/etc/httpd/conf.d/ganglia.conf,改爲:

[plain]  view plain copy 在CODE上查看代碼片 派生到個人代碼片
 
  1. #  
  2.   # Ganglia monitoring system php web frontend  
  3.   #  
  4.    
  5.   Alias /ganglia /usr/share/ganglia  
  6.   
  7.   <Location /ganglia>  
  8.     Order deny,allow  
  9.     Allow from all  
  10.     Allow from 127.0.0.1  
  11.     Allow from ::1  
  12.     # Allow from .example.com  
  13.   </Location>  

即將    Deny from all 改成    Allow from all,不然在頁面訪問時有權限問題。

八、啓動

[plain]  view plain copy 在CODE上查看代碼片 派生到個人代碼片
 
  1. service gmetad start  
  2. service gmond start  
  3. /usr/sbin/apachectl start  


九、從頁面上訪問
http://ip/ganglia

一些注意問題:
一、gmetad收集到的信息被放到/var/lib/ganglia/rrds/

二、能夠經過如下命令檢查是否有數據在傳輸

[plain]  view plain copy 在CODE上查看代碼片 派生到個人代碼片
 
  1. tcpdump port 8649  



3、配置hadoop與hbase

一、配置hadoop

hadoop-metrics2.properties

 

[plain]  view plain copy 在CODE上查看代碼片 派生到個人代碼片
 
  1. # syntax: [prefix].[source|sink|jmx].[instance].[options]  
  2. # See package.html for org.apache.hadoop.metrics2 for details  
  3.   
  4. *.sink.file.class=org.apache.hadoop.metrics2.sink.FileSink  
  5.   
  6. #namenode.sink.file.filename=namenode-metrics.out  
  7.   
  8. #datanode.sink.file.filename=datanode-metrics.out  
  9.   
  10. #jobtracker.sink.file.filename=jobtracker-metrics.out  
  11.   
  12. #tasktracker.sink.file.filename=tasktracker-metrics.out  
  13.   
  14. #maptask.sink.file.filename=maptask-metrics.out  
  15.   
  16. #reducetask.sink.file.filename=reducetask-metrics.out  
  17. # Below are for sending metrics to Ganglia  
  18. #  
  19. # for Ganglia 3.0 support  
  20. # *.sink.ganglia.class=org.apache.hadoop.metrics2.sink.ganglia.GangliaSink30  
  21. #  
  22. # for Ganglia 3.1 support  
  23. *.sink.ganglia.class=org.apache.hadoop.metrics2.sink.ganglia.GangliaSink31  
  24.   
  25. *.sink.ganglia.period=10  
  26.   
  27. # default for supportsparse is false  
  28. *.sink.ganglia.supportsparse=true  
  29.   
  30. *.sink.ganglia.slope=jvm.metrics.gcCount=zero,jvm.metrics.memHeapUsedM=both  
  31. *.sink.ganglia.dmax=jvm.metrics.threadsBlocked=70,jvm.metrics.memHeapUsedM=40  
  32. menode.sink.ganglia.servers=10.171.29.191:8649  
  33.   
  34. datanode.sink.ganglia.servers=10.171.29.191:8649  
  35.   
  36. jobtracker.sink.ganglia.servers=10.171.29.191:8649  
  37. tasktracker.sink.ganglia.servers=10.171.29.191:8649  
  38.   
  39. maptask.sink.ganglia.servers=10.171.29.191:8649  
  40.   
  41. reducetask.sink.ganglia.servers=10.171.29.191:8649  

 

 

二、配置hbase

hadoop-metrics.properties

 

[plain]  view plain copy 在CODE上查看代碼片 派生到個人代碼片
 
  1. # See http://wiki.apache.org/hadoop/GangliaMetrics  
  2. # Make sure you know whether you are using ganglia 3.0 or 3.1.  
  3. # If 3.1, you will have to patch your hadoop instance with HADOOP-4675  
  4. # And, yes, this file is named hadoop-metrics.properties rather than  
  5. # hbase-metrics.properties because we're leveraging the hadoop metrics  
  6. # package and hadoop-metrics.properties is an hardcoded-name, at least  
  7. # for the moment.  
  8. #  
  9. # See also http://hadoop.apache.org/hbase/docs/current/metrics.html  
  10. # GMETADHOST_IP is the hostname (or) IP address of the server on which the ganglia   
  11. # meta daemon (gmetad) service is running  
  12.   
  13. # Configuration of the "hbase" context for NullContextWithUpdateThread  
  14. # NullContextWithUpdateThread is a  null context which has a thread calling  
  15. # periodically when monitoring is started. This keeps the data sampled  
  16. # correctly.  
  17. hbase.class=org.apache.hadoop.metrics.spi.NullContextWithUpdateThread  
  18. hbase.period=10  
  19.   
  20. # Configuration of the "hbase" context for file  
  21. # hbase.class=org.apache.hadoop.hbase.metrics.file.TimeStampingFileContext  
  22. # hbase.fileName=/tmp/metrics_hbase.log  
  23.   
  24. # HBase-specific configuration to reset long-running stats (e.g. compactions)  
  25. # If this variable is left out, then the default is no expiration.  
  26. hbase.extendedperiod = 3600  
  27.   
  28. # Configuration of the "hbase" context for ganglia  
  29. # Pick one: Ganglia 3.0 (former) or Ganglia 3.1 (latter)  
  30. # hbase.class=org.apache.hadoop.metrics.ganglia.GangliaContext  
  31. hbase.class=org.apache.hadoop.metrics.ganglia.GangliaContext31  
  32. hbase.period=10  
  33. hbase.servers=10.171.29.191:8649  
  34.   
  35. # Configuration of the "jvm" context for null  
  36. jvm.class=org.apache.hadoop.metrics.spi.NullContextWithUpdateThread  
  37. jvm.period=10  
  38.   
  39. # Configuration of the "jvm" context for file  
  40. # jvm.class=org.apache.hadoop.hbase.metrics.file.TimeStampingFileContext  
  41. # jvm.fileName=/tmp/metrics_jvm.log  
  42.   
  43. # Configuration of the "jvm" context for ganglia  
  44. # Pick one: Ganglia 3.0 (former) or Ganglia 3.1 (latter)  
  45. # jvm.class=org.apache.hadoop.metrics.ganglia.GangliaContext  
  46. jvm.class=org.apache.hadoop.metrics.ganglia.GangliaContext31  
  47. jvm.period=10  
  48. jvm.servers=10.171.29.191:8649  
  49.   
  50. # Configuration of the "rpc" context for null  
  51. rpc.class=org.apache.hadoop.metrics.spi.NullContextWithUpdateThread  
  52. rpc.period=10  
  53.   
  54. # Configuration of the "rpc" context for file  
  55. # rpc.class=org.apache.hadoop.hbase.metrics.file.TimeStampingFileContext  
  56. # rpc.fileName=/tmp/metrics_rpc.log  
  57.   
  58. # Configuration of the "rpc" context for ganglia  
  59. # Pick one: Ganglia 3.0 (former) or Ganglia 3.1 (latter)  
  60. # rpc.class=org.apache.hadoop.metrics.ganglia.GangliaContext  
  61. rpc.class=org.apache.hadoop.metrics.ganglia.GangliaContext31  
  62. rpc.period=10  
  63. rpc.servers=10.171.29.191:8649  
  64.   
  65. # Configuration of the "rest" context for ganglia  
  66. # Pick one: Ganglia 3.0 (former) or Ganglia 3.1 (latter)  
  67. # rest.class=org.apache.hadoop.metrics.ganglia.GangliaContext  
  68. rest.class=org.apache.hadoop.metrics.ganglia.GangliaContext31  
  69. rest.period=10  
  70. rest.servers=10.171.29.191:8649  

重啓hadoop與hbase。

相關文章
相關標籤/搜索