一.Ganglia介绍:
Ganglia是一个监控服务器、集群的开源软件,能够用曲线图表现最近一个小时,最近一天,最近一周,最近一月,最近一年的服务器或者集群的cpu负载,内存,网络,硬盘等指标。Ganglia的强大在于:ganglia服务端能够通过一台客户端收集到同一个网段的所有客户端的数据,ganglia集群服务端能够通过一台服务端收集到它下属的所有客户端数据。这个体系设计表示一台服务器能够通过不同的分层能够管理上万台机器。这个功能是其他mrtg,nagios,cacti所不能比拟。
官方网站:
ganglia的下载地址
windows版windows客户端版和ganglia 源码包:
二.Ganglia的安装:
ganglia的安装分为服务端和客户端和web端安装。一般情况下将web端和服务端安装在同一机器上即可,本文采用此方式安装。
安装ganglia前需安装以下依赖包:
zlib,freetype,libart,libpng,rrdtool,apr,apr-util,expat,confuse,pcre
web端采apache或nginx,另外需要php支持。
1. 安装前准备:
关闭iptables、和selinux
如果监控信息中采用主机名,请先在在/etc/hosts文件配置地址解析。
配置yum源,用于安装一些rpm包。
2. 安装路径规划:
3. 软件包版本:
httpd-2.2.27.tar.gz
php-5.5.16.tar.gzlibiconv-1.14.tar.gz #php依赖ganglia-3.6.0.tar.gzganglia-web-3.5.10.tar.gzexpat-2.0.1.tar.gzconfuse-2.7.tar.gzapr-1.5.1.tar.gzapr-util-1.5.3.tar.gzpcre-8.33.tar.gz4. 安装依赖包:
通过以下命令检查系统是否已经安装相应的包,如果没有安装,使用rpm或yum进行安装:
rpm –qa|grep zlib
rpm –qa|grep freetyperpm –qa|grep libartrpm –qa|grep libpng4.1 安装rrdtool:
tar zxf rrdtool-1.4.5.tar.gz
cd rrdtool-1.4.5./configure -prefix=/usr/local/rrdtoolmakemake install验证是否安装成功:
运行命令/usr/local/rrdtool/bin/rrdtool
如果出现以下文字说明安装成功:
RRDtool 1.4.5 Copyright 1997-2010 by Tobias Oetiker<tobi@oetiker.ch>
Compiled Jul 26 2011 18:27:11
.......
configure 时报错:
configure: error: Please fix the library issues listed above and try again.解决办法:
yum -y install libart_lgpl-devel pango-devel cairo-devel4.2 安装expat:
tar zxf expat-2.0.1.tar.gz
cd expat-2.0.1./configure --prefix=/usr/local/expatmakemake installmkdir /usr/local/expat/lib64
cp -a /usr/local/expat/lib/* /usr/local/expat/lib64/#32系统不需要执行以下两步4.3 安装apr和apr-util
tar -zxf apr-1.5.1.tar.gzcd apr-1.5.1./configure --prefix=/usr/local/aprmakemake installtar zxf apr-util-1.5.3.tar.gz
cd apr-util-1.5.3./configure -with-apr=/usr/local/apr -with-expat=/usr/local/expatmakemake installcp /usr/local/apr/include/apr-1/* /usr/local/apr/include/ #此步要非常注意,不然编译ganglia的时候报apr的include文件找不到
mkdir /usr/local/apr/lib64
cp -a /usr/local/apr/lib/* /usr/local/apr/lib64/# 32位操作系统不用做上面两步4.4安装confuse
tar -zxf confuse-2.7.tar.gzcd confuse-2.7./configure CFLAGS=-fPIC --disable-nls --prefix=/usr/local/confusemakemake installmkdir /usr/local/confuse/lib64
cp -a /usr/local/confuse/lib/* /usr/local/confuse/lib64/# 32位操作系统不用做上面两步4.5 安装pcre
tar -zxf pcre-8.33.tar.gzcd pcre-8.33./configure makemake install 5. 安装ganglia服务端相关软件:ganglia监控服务的主节点需要安装:ganglia、ganglia-web、php、apache5.1安装apache
tar -zxf httpd-2.2.27.tar.gzcd httpd-2.2.27./configure --prefix=/app/sinova/apache --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util/ --enable-ssl --enable-so --enable-mods-shared=allmakemake install5.3 安装libiconv
tar -zxf libiconv-1.14.tar.gzcd libiconv-1.14./configure --prefix=/usr/local/libiconv makemake install5.4 安装php
tar -zxf php-5.5.16.tar.gzcd php-5.5.16./configure --prefix=/usr/local/php5/ --with-apxs2=/app/sinova/apache/bin/apxs --with-iconv=/usr/local/libiconv makemake install5.5安装ganglia
tar -zxf ganglia-3.6.0.tar.gzcd ganglia-3.6.0./configure --prefix=/usr/local/ganglia --with-librrd=/usr/local/rrdtool --with-libapr=/usr/local/apr --with-libexpat=/usr/local/expat --with-libconfuse=/usr/local/confuse --with-gmetad --enable-gexec --enable-status --sysconfdir=/etc/ganglia makemake install为rrdtool创建数据存放目录(此目录可自行定义,但需要注意的是ganglia配置文件中默认的是/var/lib/ganglia/rrds,如果定义其它目录,需要修改配置文件)
mkdir -p /var/lib/ganglia/rrdschown -R nobody:nobody /var/lib/ganglia/rrds将gmetad添加到系统服务cp {ganglia解压目录}/gmetad/gmetad.init /etc/init.d/gmetad将gmetad命令加入到/usr/sbin/目录
cp /usr/local/ganglia/sbin/gmetad /usr/sbin/gmetad给 chkconfig托管
chkconfig --add gmetad启动gmetad服务
service gmetad start启动gmetad服务如遇以下错误:
Starting GANGLIA gmetad: /usr/sbin/gmetad: error while loading shared libraries: libpcre.so.1: cannot open shared object file: No such file or directory [FAILED]解决办法: ln -s /usr/local/lib/libpcre.so.1 /lib645.6 安装并配置ganglia-web
tar zxf ganglia-web-3.5.10.tar.gz -C /app/sinova/apache/htdocs/cd /app/sinova/apache/htdocs/ganglia-web-3.5.10cp conf_default.php conf.php编辑conf.php文件,修改如下参数:
$conf['gweb_confdir'] = "/app/sinova/apache/htdocs/ganglia-web-3.5.10";$conf['gmetad_root'] = " /usr/local/ganglia";$conf['rrdtool']="/usr/local/rrdtool/bin/rrdtool" ;$conf['rrds'] = "/var/lib/ganglia/rrds";编辑 header.php 文件,添加或修改如下参数:
<?phpsession_start();ini_set('date.timezone','Asia/Shanghai'); --修改时区为本地时区if (isset($_GET['date_only'])) { $d = date("r"); echo $d; exit(0);}配置临时目录:
cd /app/sinova/apache/htdocs/ganglia-web-3.5.10/dwoomkdir cachemkdir compiledchmod 777 cachechmod 777 compiled5.7配置ganglia:vi /etc/ganglia/gmetad.conf #修改gmetad.conf配置文件data_source "Eivll0m" 10 localhost 192.168.0.103rrd_rootdir "/var/lib/ganglia/rrds"重启gmetad服务:
service gmetad restart5.8使用apache发布ganglia-web
编辑 /app/sinova/apache/conf/httpd.conf文件,添加或修改如下内容:
ServerName 192.168.0.105:80Listen 80User sinovaGroup sinova<IfModule dir_module>
DirectoryIndex index.html index.php AddType application/x-httpd-php .php</IfModule># 在文件最后增加如下内容#gangliaAlias /ganglia "/app/sinova/apache/htdocs/ganglia-web-3.5.10"<Directory "/app/sinova/apache/htdocs/ganglia-web-3.5.10"> AuthType Basic Options None AllowOverride None Order allow,deny Allow from all</Directory>启动httpd服务
/app/sinova/apache/bin/apachectl start 以上为ganglia服务端配置,如果ganglia需要监控自身,需要配置gmond(客户端):将gmond加入系统服务cp {ganglia解压目录}/gmond/gmond.init /etc/init.d/gmond将gmond命令加入到/usr/sbin/目录cp /usr/local/ganglia/sbin/gmond /usr/sbin/生成gmond的默认配置文件gmond --default_config > /etc/ganglia/gmond.conf执行以上步骤上时遇到以下错误:
gmond: error while loading shared libraries: libpcre.so.1: cannot open shared object file: No such file or directory解决办法:ln -s /usr/local/lib/libpcre.so.1 /lib64 将gmond给 chkconfig托管chkconfig --add gmond修改gmond配置文件/etc/ganglia/gmond.conf globals { daemonize = yes setuid = yes user = nobody debug_level = 0 max_udp_msg_len = 1472 mute = no deaf = no…..省略}cluster {
name = "Eivll0m" owner = "nobody" latlong = "unspecified" url = "unspecified"}开启gmond服务
service gmond start访问ganglia web监控页面:
http://192.168.0.105/ganglia可以发现ganglia目前监控的的主机只有它自己:
接下来我们继续在另外一台主机上安装ganglia客户端:
6.安装ganglia客户端(gmond)
安装之前先安装上述依赖包,此处不再赘述。tar zxf ganglia-3.6.0.tar.gz
./configure --prefix=/usr/local/ganglia --prefix=/usr/local/ganglia --with-librrd=/usr/local/rrdtool --with-libapr=/usr/local/apr --with-libexpat=/usr/local/expat --with-libconfuse=/usr/local/confuse --enable-gexec -enable-status --sysconfdir=/etc/ganglia#比gmetad时少“–with-gmetad”参数makemake install将gmond加入系统服务
cp {ganglia解压目录}/gmond/gmond.init /etc/init.d/gmond将gmond命令加入到/usr/sbin/目录
cp /usr/local/ganglia/sbin/gmond /usr/sbin/生成gmond的默认配置文件
gmond --default_config > /etc/ganglia/gmond.conf报错:gmond --default_config >/etc/ganglia/gmond.confgmond: error while loading shared libraries: libpcre.so.1: cannot open shared object file: No such file or directory解决办法:ln -s /usr/local/lib/libpcre.so.1 /lib64将gmond给 chkconfig托管
chkconfig --add gmond修改gmond配置文件/etc/ganglia/gmond.conf
cluster { name = "Eivll0m" #设置服务端主机名owner = "nobody"latlong = "unspecified"url = "unspecified"}开启gmond服务
service gmond start再来刷新一下监控页面:
可以看到现在监控的主机为2台:
至此ganglia监控搭建完毕,监控节点可以随意增加,只要进行安装配置即可。