前言:Ganglia是UC Berkeley發起的一個開源集羣監視項目,設計用於測量數以千計的節點。Ganglia的核心包含gmond、gmetad以及一個Web前端。主要是用來監控系統性能,如:cpu 、mem、硬盤利用率, I/O負載、網絡流量狀況等,經過曲線很容易見到每一個節點的工做狀態,對合理調整、分配系統資源,提升系統總體性能起到重要做用。php
規劃:html
使用一臺ganglia機器監控兩個集羣前端
ganglia-server(gmetad):10.64.8.10 centos6.5
python
ganglia-agent(gmond):xdhadoop、sjselklinux
集羣xdhadoop:c++
master一、master二、slave一、slave二、slave3web
集羣sjselk:apache
es-master一、es-master二、es-master三、es-master四、es-master5vim
一:準備工做centos
(1)修改主機名,並將監控機名寫入hosts
10.10.1.10
#hostname ganglia && echo ganglia >/etc/hostname #cat >> /etc/hosts << EOF 10.10.1.1 master1 10.10.1.2 master2 10.10.1.3 slave1 10.10.1.4 slave2 10.10.1.5 slave3 10.10.0.1 es-master1 10.10.0.2 es-master2 10.10.0.3 es-master3 10.10.0.4 es-master4 10.10.0.5 es-master5 10.10.1.10 ganglia EOF
(2)關閉selinux和防火牆
#setenforce 0&& service iptables stop &&chkconfig iptables off
二:ganglia-server環境安裝
ganglia
(1)web環境
安裝apache
#yum install httpd #vim /etc/httpd/conf/httpd.conf User nobody Group nobody
安裝php,並編輯測試頁面。
#yum install php #vim /var/www/html/info.php <?php phpinfo(); ?>
啓動httpd
#service httpd restart
打開瀏覽器訪問10.64.8.10/info.php測試,出現下圖說明apache與php聯動成功。
(2)安裝依賴
# yum install -y apr-devel apr-util check-devel cairo-devel pango-devel libxml2-devel rpm-build glib2-devel dbus-devel freetype-devel fontconfig-devel gcc-c++ expat-devel python-devel libXrender-devel
(3)安裝libconfuse
#wget http://download.savannah.gnu.org/releases/confuse/confuse-2.7.tar.gz #tar confuse-2.7.tar.gz #cd confuse-2.7 # ./configure CFLAGS=-fPIC --disable-nls # make&&make install
(4)安裝pcre
#tar xf pcre-8.12.tar.bz2 #cd pcre-8.12 #./configure && make && make install #echo "/usr/local/lib" >> /etc/ld.so.conf # ldconfig
(5)安裝rrdTool
1:下載tar包,編譯安裝rrdTool
#cd /opt #wget http://oss.oetiker.ch/rrdtool/pub/rrdtool-1.3.1.tar.gz #tar xf rrdtool-1.3.1.tar.gz #cd rrdtool-1.3.1 #./configure --prefix=/usr/local #make && make install
rrd安裝後:lib庫文件 /usr/local/lib bin可執行文件 /usr/local/bin/rrdtool
2:將rrdtool 因此拷到/usr/bin下(方便後面ganglia調用),並加入庫文件。
#cp /usr/local/bin/rrdtool /usr/bin/rrdtool #echo "/usr/local/lib" >> /etc/ld.so.conf # ldconfig
3:驗證rrdtool是否安裝成功,利用examples下的示例,渲染一個示例圖
#rrdtool -V #cd /usr/local/share/rrdtool/examples/ #./stripes.pl #cp stripes.png /var/www/html/
在瀏覽器訪問http://ganglia/stripes.png,,以下圖說明rrd安裝正常。
三:ganglia-server(gmetad)安裝
ganglia
(1)編譯安裝ganglia
#wget http://120.52.73.45/jaist.dl.sourceforge.net/project/ganglia/ganglia%20monitoring%20core/3.7.2/ganglia-3.7.2.tar.gz #tar xf ganglia-3.7.2.tar.gz #cd ganglia-3.7.2 # ./configure --prefix=/usr/local/ganglia --with-gmetad --with-librrd=/usr/local/lib --sysconfdir=/etc/ganglia --with-libpcre=no #make && make install
(2)cpoy啓動腳本
# 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 #vim /etc/init.d/gmetad 改 GMETAD=/usr/sbin/gmetad 爲 GMETAD=/usr/local/ganglia/sbin/gmetad #vim /etc/init.d/gmond 改 GMETAD=/usr/sbin/gmond 爲 GMETAD=/usr/local/ganglia/sbin/gmond
複製python_modules
#mkdir /usr/local/ganglia/lib64/ganglia/python_modules #cp ./gmond/python_modules/*/*.py /usr/local/ganglia/lib64/ganglia/python_modules
(3)安裝ganglia前端
#wget http://120.52.73.47/jaist.dl.sourceforge.net/project/ganglia/ganglia-web/3.7.1/ganglia-web-3.7.1.tar.gz #tar xf ganglia-web-3.7.1.tar.gz #cd ganglia-web-3.7.1 #vim Makefile #改爲實際的目錄 ########################################################## # User configurables: ########################################################## # Location where gweb should be installed to (excluding conf, dwoo dirs). #ganglia的web發佈目錄 GDESTDIR = /var/www/html/ganglia # Location where default apache configuration should be installed to. #ganglia-web的配置文件目錄 GCONFDIR = /etc/ganglia-web # Gweb statedir (where conf dir and Dwoo templates dir are stored) GWEB_STATEDIR = /var/lib/ganglia-web # Gmetad rootdir (parent location of rrd folder) GMETAD_ROOTDIR = /usr/local/ganglia #httpd的用戶 APACHE_USER = nobody #make install
(4)啓動server端gmetad
# service gmetad start
Starting GANGLIA gmetad: [ OK ]
瀏覽器訪問:http://ganglia/ganglia 以下圖,gmetad正常,可是尚未加入機器,因此是空白的。
四:ganglia-agent(gmond)安裝
xdhadoop全部機器、sjselk全部機器
(1)安裝依賴
# yum install -y apr-devel apr-util check-devel cairo-devel pango-devel libxml2-devel rpm-build glib2-devel dbus-devel freetype-devel fontconfig-devel gcc-c++ expat-devel python-devel libXrender-devel
(2)安裝libconfuse
#wget http://download.savannah.gnu.org/releases/confuse/confuse-2.7.tar.gz #tar confuse-2.7.tar.gz #cd confuse-2.7 # ./configure CFLAGS=-fPIC --disable-nls # make&&make install
(3)安裝pcre
#tar xf pcre-8.12.tar.bz2 #cd pcre-8.12 #./configure && make && make install #echo "/usr/local/lib" >> /etc/ld.so.conf # ldconfig
(4)安裝
#tar xf ganglia-3.7.2.tar.gz #cd ganglia-3.7.2 # ./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 #vim /etc/init.d/gmond 改 GMETAD=/usr/sbin/gmond 爲 GMETAD=/usr/local/ganglia/sbin/gmond
複製python_modules
#mkdir /usr/local/ganglia/lib64/ganglia/python_modules #cp ./gmond/python_modules/*/*.py /usr/local/ganglia/lib64/ganglia/python_modules
安裝完畢,其實agent安裝和server安裝幾乎同樣,只是server端咱們用的是gmetad(也會安裝gmond),agent端,咱們只用gmond就好了。
五:配置gmetad和gmond
(1)配置gmond.conf(sjselk集羣,組播)
sjselk
#vim /etc/ganglia/gmond.conf cluster { name = "sjselk" #集羣名 owner = "nobody" #運行gmond用戶名 latlong = "unspecified" url = "unspecified" } host { location = "unspecified" } udp_send_channel { mcast_join = 239.2.11.71 #默認組播地址 port = 8649 #gmond端口 ttl = 1 } udp_recv_channel { mcast_join = 239.2.11.71 port = 8649 bind = 239.2.11.71 retry_bind = true } tcp_accept_channel { port = 8649 gzip_output = no }
添加路由到組播地址
# ip route add 239.2.11.71 dev eth0
(2)配置gmond.conf(xdhadoop集羣,單播)
xdhadoop
#vim /etc/ganglia/gmond.conf cluster { name = "xdhadoop" #集羣名 owner = "nobody" #運行gmond的用戶 latlong = "unspecified" url = "unspecified" } host { location = "unspecified" } udp_send_channel { # mcast_join = 239.2.11.71 #使用單播,註釋組播地址 host = 10.10.1.10 #使用單播,寫gmond的IP port = 8653 #設置端口 ttl = 1 } udp_recv_channel { # mcast_join = 239.2.11.71 #使用單播,註釋組播地址 port = 8653 #設置端口 # bind = 239.2.11.71 #使用單播,註釋組播地址 bind = 10.10.0.1 #寫本身的IP retry_bind = true } tcp_accept_channel { port = 8653 gzip_output = no }
(3)配置gmetad.conf
ganglia
#vim /etc/gmetad.conf #組播只寫一個ip便可,能夠寫兩個,防止一臺機器掛了後,收不到數據。單播須要寫上全部機器。 data_source "sjselk" es-master1:8649 es-master2:8649 data_source "xdhadoop" master1:8653 master2:8653 slave1:8653 slave2:8653 slave3:8653
添加路由到組播地址
# ip route add 239.2.11.71 dev eth0
五:啓動gmetad和gmond
ganglia
[root@ganglia ~]# service gmetad start Starting GANGLIA gmetad: [ OK ]
sjselk、xdhadoop
[root@ganglia ~]# service gmond start Starting GANGLIA gmond: [ OK ]
訪問http://ganglia/ganglia