首先強調一下,Ganglia採用組播模式(多播模式)進行數據請求。gmetad發送一個請求到一個組播地址(239.2.11.71),由於是組播地址,所以gmetad只需發送一次請求包即可完成對所有gmond的輪詢。gmond收到請求後將採集到的數據返回給gmetad。
而單播模式下,Ganglia需要向每臺服務器均發送一次輪詢請求,這樣的話,集羣數量多了,主服務器光發送就會佔用不小的帶寬。但是單播模式也有其好處,在服務器分組,或跨網段的情況下,必須用單播模式。我早期的一篇博文《Ganglia分組監控》提到過個事情。
SERVER端安裝:
apache:
wget http://labs.mop.com/apache-mirror//apr/apr-1.4.6.tar.gz wget http://labs.mop.com/apache-mirror//apr/apr-util-1.5.1.tar.gz wget http://www.fayea.com/apache-mirror/httpd/httpd-2.2.23.tar.gz tar -xf apr-1.4.6.tar.gz && cd apr-1.4.6 ./configure --prefix=/usr/local/apr && make && make install tar -xf apr-util-1.5.1.tar.gz && cd apr-util-1.5.1 ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr make && make install tar -xf httpd-2.2.23.tar.gz && cd httpd-2.2.23 ./configure --prefix=/usr/local/apache2 --enable-so --enable-mods-shared=most --with-included-apr --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util make && make install echo '/usr/local/apache2/bin/apachectl start' >>/etc/rc.d/rc.local 啓動 /usr/local/apache2/bin/apachectl start
php:
ganglia-web需要PHP JSON模塊,該模塊包含在PHP 5.2及其以上版本。PHP 5.1需要自行安裝JSON模塊,非常的麻煩。
wget http://www.php.net/get/php-5.3.18.tar.gz/from/cn2.php.net/mirror tar -xf php-5.3.18.tar.gz && cd php-5.3.18 ./configure --prefix=/usr/local/php-5.3 --with-apxs2=/usr/local/apache2/bin/apxs make && make install
vim /usr/local/apache2/conf/httpd.conf,添加如下內容:
<FilesMatch \.php$> SetHandler application/x-httpd-php </FilesMatch> <FilesMatch "\.ph(p[2-6]?|tml)$"> SetHandler application/x-httpd-php </FilesMatch> <FilesMatch "\.phps$"> SetHandler application/x-httpd-php-source </FilesMatch>
找到<IfModule dir_module>配置段,添加index.php
重啓apache,寫一個index.php文件,進行測試訪問:
http://SERVER/index.php
安裝ganglia依賴:
libconfuse:
官方網站下載失敗,下載了版本稍舊一點rpm包:ttp://pkgs.repoforge.org/libconfuse/
wget http://pkgs.repoforge.org/libconfuse/libconfuse-2.6-2.el5.rf.x86_64.rpm wget http://pkgs.repoforge.org/libconfuse/libconfuse-devel-2.6-2.el5.rf.x86_64.rpm rpm -ivh libconfuse-*
pcre:
wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.31.tar.gz tar -xf pcre-8.31.tar.gz && cd pcre-8.31 ./configure && make && make install echo '/usr/local/lib' >/etc/ld.so.conf.d/libpcre.conf ldconfig -v
其它依賴:
yum -y install apr-devel apr-util check-devel cairo-devel pango-devel libxml2-devel rpmbuild glib2-devel dbus-devel freetype-devel fontconfig-devel gcc-c++ expat-devel python-devel libXrender-devel
rrdtool:
wget http://oss.oetiker.ch/rrdtool/pub/rrdtool-1.4.7.tar.gz tar -xf rrdtool-1.4.7.tar.gz && cd rrdtool-1.4.7 ./configure --prefix=/usr/local make && make install echo '/usr/local/lib' >/etc/ld.so.conf.d/librrd.conf ldconfig -v
ganglia:
wget http://sourceforge.net/projects/ganglia/files/ganglia%20monitoring%20core/3.4.0/ganglia-3.4.0.tar.gz/download tar -xf ganglia-3.4.0.tar.gz && cd ganglia-3.4.0 ./configure --prefix=/usr/local/ganglia --with-gmetad --with-librrd=/usr/local/lib --sysconfdir=/etc/ganglia make && make install cp gmond/gmond.init /etc/rc.d/init.d/gmond cp gmetad/gmetad.init /etc/rc.d/init.d/gmetad chkconfig --add gmond && chkconfig gmond on chkconfig --add gmetad && chkconfig gmetad on 修改/etc/rc.d/init.d/gmetad和/etc/rc.d/init.d/gmond,分別指定如下參數: GMETAD=/usr/local/ganglia/sbin/gmetad GMOND=/usr/local/ganglia/sbin/gmond
mkdir -p /var/lib/ganglia/rrds chown nobody:nobody /var/lib/ganglia/rrds gmond -t |tee /etc/ganglia/gmond.conf vim /etc/ganglia/gmetad.conf,修改內容: data_source "Hadoop Cluster" $SERVER:8649 //把$SERVER替換成自己的被監控服務器IP gridname "Hadoop" vim /etc/ganglia/gmond.conf,修改cluster配置段內容: name = "Hadoop Cluster"
ganglia-web:
早期版本ganglia-web組件是集成在ganglia安裝包裏的,一個名爲web的目錄;新版本的ganglia把兩者分開了。
wget http://sourceforge.net/projects/ganglia/files/ganglia-web/3.5.4/ganglia-web-3.5.4.tar.gz/download tar -xf ganglia-web-3.5.4.tar.gz cp -r ganglia-web-3.5.4 /usr/local/apache2/htdocs/ganglia cd /usr/local/apache2/htdocs/ganglia vim Makefile,修改參數GDESTDIR和APACHE_USER,然後執行make install進行安裝: GDESTDIR=/usr/local/apache2/htdocs/ganglia APACHE_USER=daemon make install cp conf_default.php conf.php
vim conf.php,修改如下參數:
$conf['gmetad_root'] = "/var/lib/ganglia"; $conf['rrds'] = "${conf['gmetad_root']}/rrds"; $conf['rrdtool'] = "/usr/local/bin/rrdtool"; $conf['external_location'] = "http://SERVER/ganglia"; //把SERVER替換成自己的g $conf['case_sensitive_hostnames'] = false;
啓動並訪問:
service gmetad start service gmond start http://SERVER/ganglia/ //把SERVER替換成自己的ganglia服務器IP
CLIENT端安裝:
比較簡單,只需要安裝gmond及其依賴即可,其它apache、php、rrdtool等都不需要安裝。
tar -xf ganglia-3.4.0.tar.gz && cd ganglia-3.4.0 ./configure --prefix=/usr/local/ganglia --sysconfdir=/etc/ganglia make && make install cp gmond/gmond.init /etc/rc.d/init.d/gmond chkconfig --add gmond && chkconfig gmond on 修改/etc/rc.d/init.d/gmond,指定如下參數: GMOND=/usr/local/ganglia/sbin/gmond 複製配置文件到客戶端,然後啓動客戶端: scp SERVER:/etc/ganglia/gmond.conf /etc/ganglia
CLIENT端的簡單配置:
最主要是修改cluster配置段中的name屬性,要和gmetad.conf中的datasource裏的名稱一致;如果是分組監控,還要修改udp_send_channel、udp_recv_channel和tcp_accept_channel三個部分裏的port。我在以前的ganglia 3.1.7安裝配置及分組監控中都有說明。
但是這次3.4的安裝遇到了一點問題。ganglia server只能抓取到配有外網網卡的節點的數據,抓取不到僅配置內網網卡的的數據。最後參考了:http://www.howtocn.org/ganglia_how_to, 把239.2.11.71綁定到內網網卡上才解決了問題。
gmond節點安裝完成後,運行命令:ip route add 239.2.11.71 dev eth1
遇到的錯誤:
重啓apache時報錯:httpd: Syntax error on line 140 of /usr/local/apache2/conf/httpd.conf: Cannot load modules/mod_dir.so into server: /usr/local/apache2/modules/mod_dir.so: undefined symbol: apr_array_clear
解決:apache編譯時需要指定參數--with-included-apr
ganglia web頁面顯示錯誤:It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function.
解決:
vim /etc/php.ini,修改如下參數:
date.timezone = PRC
vim /usr/local/apache2/htdocs/ganglia/header.php,在第二行添加:
date_default_timezone_set("PRC");