分布式监控系统ganglia
1.简介:
ganglia是一款为HPC(高性能计算)集群而设计的可扩展的分布式监控系统,它可以监控和显示集群中cpu,内存,磁盘利用率,i/o负载,网络流量等情况
优点:良好的扩展性,负载开销低,支持高并发。广泛支持各种操作系统和cpu架构,支持虚拟机

2.组成:
gmond:用于收集本节点的信息并发送到其他节点,同时也接收其他节点发送过来的数据,默认端口为8649
gmetad:运行在一个数据汇聚节点,定期检查每个节点的gmond进程,并从哪里获取数据,然后将数据 存储在本地rrd引擎中
webfrontend:基于web的图形化监控界面,和gmetad安装在一个节点上,读取数据,并通过rrdtool生成图表

3.工作原理
node:单台服务器
cluster:一个服务器集群
grid:表示一个网格,由多个集群组成

4.数据走向:
gmond:收集本地的监控数据,发送到其他机器上。他们之间用udp协议通信,文件格式为xdl,传输方式支持单播点对点和多播传送
gmetad:周期性的到gmond节点或gmetad节点上获取数据。用tcp协议通信,文件格式为xml
gmetad:将获取到的数据更新到rrds数据库中
通过web界面,从gmetad取数据,并且读取rrds数据库,生成图片显示出来

5.工作模式:单播和多播,默认采用多播
单播:监控节点发送本机数据到指定的一台或几台机器上,单播可以跨越不同的网段
多播:监控节点发送本机数据到同意网段内的所有机器上,同时也接收同一网段内所有机器发过来的监控数据。

环境:centos6.5

ganglia_gmetad 192.168.32.200  ganglia_gmond:192.168.32.202
6.ganglia的安装
yum安装
安装第三方源:epel
ganglia安装飞卫两个部分:gmetad(管理端)和gmond(客户端)
yum -y install ganglia-gmetad
yum -y install ganglia-gmond

源码安装
安装依赖
服务器的安装
yum -y install expat expat-devel pcre pcre-devel zlib cairo-devel libxml2-devel devel libxml2-develpango-devel pango libpng-devel libpng freetype
 freetype-devel libart-lgpl-devel apr-devel
 yum -y install pango-devel
 yum -y install perl-ExtUtils-MakeMaker
 安装apr,confuse,rrdtool
 tar zxvf apr-1.4.6.tar.gz
 cd apr-1.4.6
 ./configure
 make && make install
 
 tar zxvf confuse-2.7.tar.gz
 cd confuse-2.7
 ./configure CFLAGS=-fPIC --disable-nls
 make && make install
 tar zxvf rrdtool-1.4.7.tar.gz
  ./configure --disable-tcl --prefix=/usr/local/rrdtool
  cd rrdtool-1.4.7
  make && make install
 
  tar zxvf ganglia-3.4.0.tar.gz
  cd ganglia-3.4.0
 ./configure --prefix=/usr/local/ganglia --with-static-modules --enable-gexec --enable-status --with-gmetad --with-python=/usr --with-librrd=/usr/local/rrdtool/
 --with-libexpat=/usr/ --with-libconfuse=/usr/local/ --with-libpcre=/usr/local/
 make && make install
 
 cp gmetad.conf /usr/local/ganglia/etc/
 cp gmetad.init /etc/init.d/gmetad
  cd /etc/init.d/
  vim gmetad
  GMETAD=/usr/local/ganglia/sbin/gmetad
  chkconfig --add gmetad
  service gmetad start
  ip route add 239.2.11.71 dev eth1
 
[root@ganglia_gmetad gmetad]# /etc/init.d/gmetad status
gmetad 已死,但是 subsys 被锁
解决办法
[root@ganglia_gmetad gmetad]# mkdir -p /var/lib/ganglia/rrds
[root@ganglia_gmetad gmetad]# chown nobody:nobody /var/lib/ganglia/rrds/
[root@ganglia_gmetad gmetad]# /etc/init.d/gmetad start
Starting GANGLIA gmetad: [确定]
netstat -tunpl
tcp        0      0 0.0.0.0:8651                0.0.0.0:*                   LISTEN      43524/gmetad       
tcp        0      0 0.0.0.0:8652                0.0.0.0:*                   LISTEN      43524/gmetad

安装ganglia的web

yum -y  install  php-fpm
vim /etc/httpd/conf/httpd.conf
AddType application/x-httpd-php .php .phtml
DirectoryIndex index.html index.php
/etc/php-fpm  start
/etc/init.d/httpd  start

tar zxvf ganglia-web-3.5.7.tar.gz
mv ganglia-web-3.5.7/conf_default.php /var/www/html/ganglia/
cd /var/www/html/ganglia/
cp conf_default.php conf.php 
mkdir /var/www/html/ganglia/dwoo/cache
mkdir /var/www/html/ganglia/dwoo/compiled
chmod 777 /var/www/html/ganglia/dwoo/cache
chmod 777 /var/www/html/ganglia/dwoo/compiled
vim conf.php
$conf['gweb_confdir'] = "/var/www/html/ganglia";    #ganglia的web目录
$conf['gmetad_root'] = "/usr/local/ganglia";        #ganglia的安装目录
$conf['rrds'] = "/var/lib/ganglia/rrds";            #rrd数据库路径
$conf['dwoo_compiled_dir'] = "${conf['gweb_confdir']}/dwoo/compiled";   #需要777权限
$conf['dwoo_cache_dir'] = "${conf['gweb_confdir']}/dwoo/cache";         #需要777权限
$conf['rrdtool'] = "/usr/local/rrdtool/bin/rrdtool";                    #rrdtool路径
$conf['graphdir']= $conf['gweb_root'] . '/graph.d';                     #生成图形模板目录
$conf['ganglia_ip'] = "127.0.0.1";           #gmetad服务器的地址
$conf['ganglia_port'] = 8652;           #gmetad服务器的交互式提供监控数据端口发布


 浏览器访问http://192.168.32.200/ganglia/
 
 
客户端配置
安装依赖
yum -y install expat expat-devel pcre pcre-devel zlib cairo-devel libxml2-devel devel libxml2-develpango-devel pango libpng-devel libpng freetype
 freetype-devel libart-lgpl-devel apr-devel
 yum -y install pango-devel
 yum -y install perl-ExtUtils-MakeMaker
 安装apr,confuse,rrdtool
 tar zxvf apr-1.4.6.tar.gz
 cd apr-1.4.6
 ./configure
 make && make install
 
 tar zxvf confuse-2.7.tar.gz
 cd confuse-2.7
 ./configure CFLAGS=-fPIC --disable-nls
 make && make install
 tar zxvf rrdtool-1.4.7.tar.gz
  cd rrdtool-1.4.7
   ./configure --disable-tcl --prefix=/usr/local/rrdtool
  make && make install
 
  tar zxvf ganglia-3.4.0.tar.gz
  cd ganglia-3.4.0
  ./configure --prefix=/usr/local/gnaglia --enable-gexec --enable-status --with-python=/usr/ \
> --with-libapr=/usr/local/apr/bin/apr-1-config --with-libconfuse=/usr/local/ --with-gmetad-libexpat=/usr/ --with-libpcre=/usr/

  cd gmond/
   ./gmond -t >/usr/local/gnaglia/etc/gmond.conf
   cp gmond.init /etc/init.d/gmond
   vim /etc/init.d/gmond
   /usr/local/gnaglia/sbin/gmond
   chkconfig --add gmond
    /etc/init.d/gmond start
 ip route add 239.2.11.71 dev eth1
    netstat -tunpl         
tcp        0      0 0.0.0.0:8649                0.0.0.0:*                   LISTEN      54754/gmond           
udp        0      0 239.2.11.71:8649            0.0.0.0:*                               54754/gmond  

gmetad配置
vim /usr/local/ganglia/etc/gmetad.comf
data_source "cluster" 192.168.32.202   #后面可以跟主机名
其他的配置都是默认的
/etc/init.d/gmetad restart

gmond配置
cd /usr/local/gnaglia/etc
vim gmond.conf
cluster {
  name = "cluster"
  owner = "unspecified"
  latlong = "unspecified"
  url = "unspecified"
}
 mcast_join = 239.2.11.71
  port = 8650
  ttl = 1
  udp_recv_channel {
  mcast_join = 239.2.11.71
  port = 8650
  bind = 239.2.11.71
  retry_bind = true
}
tcp_accept_channel {
  port = 8650
}
/etc/init.d/gmond  restart