最近在研究雲監控的相關工具,感受ganglia很有亮點,能從一個集羣總體的角度來展示數據. 但是安裝過程稍過複雜,相關依賴稍多,故寫此文章與你們分享下. php
本文不講解相關原理,若想了解請參考其餘資料. html
本文目的: 即便以前未觸過ganglia,也能按照文中步驟搭建本身的ganglia監控集羣.python
@Author duangrmysql
@Website http://my.oschina.net/duangr/blog/181585 web
Host Name | IP | OS | Arch |
duangr-1 | 192.168.56.10 | CentOS 6.4 | x86_64 |
duangr-2 | 192.168.56.11 | CentOS 6.4 | x86_64 |
duangr-3 | 192.168.56.12 | CentOS 6.4 | x86_64 |
所有主機確認:sql
iptables關閉shell
SELinux disabledapache
項 | 值 |
監控服務主節點 | duangr-1 |
被監控從節點 | duangr-2 |
Ganglia監控服務的主節點須要安裝: session
ganglia
ganglia-web
php
apache
Ganglia被監控從節點須要安裝:
ganglia
安裝路徑規劃
項 | 值 |
ganglia安裝路徑 | /usr/local/ganglia |
php安裝路徑 |
/usr/local/php |
apache安裝路徑 |
/usr/local/apache2 |
ganglia-web安裝路徑 |
/export/home/ganglia/ganglia-web-3.5.10 |
rrds數據路徑 |
/export/home/ganglia/rrds |
# rpm -q gcc glibc glibc-common rrdtool rrdtool-devel apr apr-devel expat expat-devel pcre pcre-devel dejavu-lgc-sans-mono-fonts dejavu-sans-mono-fonts gcc-4.4.7-3.el6.x86_64 glibc-2.14.1-6.x86_64 glibc-common-2.14.1-6.x86_64 rrdtool-1.3.8-6.el6.x86_64 rrdtool-devel-1.3.8-6.el6.x86_64 apr-1.3.9-5.el6_2.x86_64 apr-devel-1.3.9-5.el6_2.x86_64 expat-2.0.1-11.el6_2.x86_64 expat-devel-2.0.1-11.el6_2.x86_64 pcre-7.8-6.el6.x86_64 pcre-devel-7.8-6.el6.x86_64 dejavu-lgc-sans-mono-fonts-2.30-2.el6.noarch.rpm dejavu-sans-mono-fonts-2.30-2.el6.noarch.rpm
如有缺失,請先安裝. 可經過以下幾個鏡像網站下載相關安裝包:
rpm -ivh dejavu-lgc-sans-mono-fonts-2.30-2.el6.noarch.rpm rpm -ivh dejavu-sans-mono-fonts-2.30-2.el6.noarch.rpm
rpm -ivh rrdtool-1.3.8-6.el6.x86_64.rpm rpm -ivh rrdtool-devel-1.3.8-6.el6.x86_64.rpm
rpm -ivh apr-1.3.9-5.el6_2.x86_64.rpm rpm -ivh apr-devel-1.3.9-5.el6_2.x86_64.rpm
rpm -ivh expat-2.0.1-11.el6_2.x86_64.rpm rpm -ivh expat-devel-2.0.1-11.el6_2.x86_64.rpm
rpm -ivh pcre-7.8-6.el6.x86_64.rpm rpm -ivh pcre-devel-7.8-6.el6.x86_64.rpm
confuse-2.7 http://www.nongnu.org/confuse/
tar -zxf confuse-2.7.tar.gz cd confuse-2.7 ./configure CFLAGS=-fPIC --disable-nls make && make install
Python-2.7.3.tar.bz2 http://www.python.org/
tar -jxf Python-2.7.3.tar.bz2 ./configure --prefix=/usr/local --enable-shared make && make install
配置共享庫
vi /etc/ld.so.conf -- 增長以下內容 /usr/local/lib
啓用配置
ldconfig
檢查是否生效
ldconfig -v |grep "libpython2.7.so"
# tar -zxf ganglia-3.6.0.tar.gz # cd ganglia-3.6.0 # ./configure --prefix=/usr/local/ganglia --with-gmetad --enable-gexec --with-python=/usr/local Welcome to.. ______ ___ / ____/___ _____ ____ _/ (_)___ _ / / __/ __ `/ __ \/ __ `/ / / __ `/ / /_/ / /_/ / / / / /_/ / / / /_/ / \____/\__,_/_/ /_/\__, /_/_/\__,_/ /____/ Copyright (c) 2005 University of California, Berkeley Version: 3.6.0 Library: Release 3.6.0 0:0:0 Type "make" to compile. # make && make install
# tar -zxf ganglia-web-3.5.10.tar.gz -C /export/home/ganglia/ # cd /export/home/ganglia/ganglia-web-3.5.10 # cp conf_default.php conf.php
vi conf.php 調整爲以下內容
$conf['gweb_confdir'] = "/export/home/ganglia/ganglia-web-3.5.10"; $conf['gmetad_root'] = "/export/home/ganglia";
vi header.php
<?php session_start(); ini_set('date.timezone','PRC'); --修改時區爲本地時區 if (isset($_GET['date_only'])) { $d = date("r"); echo $d; exit(0); }
配置臨時目錄
cd /export/home/ganglia/ganglia-web-3.5.10/dwoo mkdir cache chmod 777 cache mkdir compiled chmod 777 compiled
tar -zxf httpd-2.2.23.tar.gz cd httpd-2.2.23 ./configure --prefix=/usr/local/apache2 make && make install
tar -zxf php-5.4.10.tar.gz cd php-5.4.10 ./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache2/bin/apxs --with-mysql=/usr make && make install
vi /usr/local/apache2/conf/httpd.conf
.... Listen 80 .... <IfModule dir_module> DirectoryIndex index.html index.php AddType application/x-httpd-php .php </IfModule> .... # 在文件最後增長以下內容 # ganglia Alias /ganglia "/export/home/ganglia/ganglia-web-3.5.10" <Directory "/export/home/ganglia/ganglia-web-3.5.10"> AuthType Basic Options None AllowOverride None Order allow,deny Allow from all </Directory>
啓動httpd服務
/usr/local/apache2/bin/apachectl restart
cd ganglia-3.6.0 cp ./gmetad/gmetad.init /etc/init.d/gmetad cp ./gmetad/gmetad.conf /usr/local/ganglia/etc/
vi /etc/init.d/gmetad --修改以下內容
GMETAD=/usr/local/ganglia/sbin/gmetad
vi /usr/local/ganglia/etc/gmetad.conf -- 修改以下內容
data_source "duangr-cluster" 10 duangr-1 duangr-2 duangr-3 xml_port 8651 interactive_port 8652 rrd_rootdir "/export/home/ganglia/rrds" case_sensitive_hostnames 0
修改rrds數據目錄全部者
chown -R nobody:nobody /export/home/ganglia/rrds
啓動gmetad服務,並設爲開機自動運行
service gmetad restart chkconfig --add gmetad
cd ganglia-3.6.0 cp ./gmond/gmond.init /etc/init.d/gmond ./gmond/gmond -t > /usr/local/ganglia/etc/gmond.conf
vi /etc/init.d/gmond --修改以下內容
GMOND=/usr/local/ganglia/sbin/gmond
vi /usr/local/ganglia/etc/gmond.conf -- 修改以下內容
cluster { name = "duangr-cluster" owner = "nobody" latlong = "unspecified" url = "unspecified" }
複製python module到ganglia部署目錄
mkdir /usr/local/ganglia/lib64/ganglia/python_modules cp ./gmond/python_modules/*/*.py /usr/local/ganglia/lib64/ganglia/python_modules
安裝程序ganglia-3.6.0默認提供了一些python module的配置文件,只須要部署到 /usr/local/ganglia/etc/conf.d 目錄下面便可生效
若對默認提供的這些監控腳本不太關心,能夠跳過下面這步:
cp ./gmond/python_modules/conf.d/*.pyconf /usr/local/ganglia/etc/conf.d
啓動gmond服務,並設爲開機自動運行
service gmond restart chkconfig --add gmond