Ganglia的扩展插件非常好写,无论用何种语言(shell,php,pyton)都可以写,只要把最终结果传给gmetric就可以,这样在web上就可以看到对应的数据。
最新的ganglia版本为3.2.0,但是我推荐安装ganglia3.0.3,因为这个版本安装比较简单,依赖包只有rrdtool。而新版本依赖包太多。
官方网站:http://ganglia.info
ganglia的下载地址 http://sourceforge.net/projects/ganglia
windows版windows客户端版和ganglia 源包:
:http://www.sajinet.com.pe/ganglia/
http://sourceforge.net/project/showfiles.php?group_id=43021&package_id=35280
ganglia的安装分为服务端和客户端和web端安装
文档帮助: http://ganglia.sourceforge.net/docs/
1) 服务端依赖包
Ganglia里的gmetad
Rrdtool(这个依赖很多包,ganglia对于rrdtool的版本不敏感,最好选择比较好安装的版本安装)
2) 客户端
ganglia里的gmond
3) Web端:
Apache,php,rrdtool,php-gd(可不用装,不装的话只是看不到一张饼图,不影响使用)
服务端的服务为gmetad,安装前需要先安装RRDTool(数据库和绘图工具,服务端收集的客户端信息由其来保存),因为要绘制曲线图,所以安装RRDTool前,还必须安装好libpng,freetype,zlib这些库(也是php的gd库需要的),下载地址http://www.rrdtool.org/ 。
安装完了RRDTool,就可以安装gmetad了
点击(此处)折叠或打开
- tar –zxvf ganglia3.0.3.tar.gz
- cd ganglia3.0.3
- ./configure --with-gmetad --sysconfdir=/etc/ganglia --with-librrd=/usr/local/rrdtool --prefix=/usr/local/ganglia
- make
- make install
将gmetad.init文件拷贝到 /etc/init.d/:
点击(此处)折叠或打开
- cd ganglia-3.0.3/gmetad
- cp gmetad.init /etc/init.d/gmetad #若是ganglia安装在别的目录,则修改gmetad.init里的gmetad路径
- chkconfig --add gmetad
- chkconfig gmetad on
- chkconfig --list gmetad
- GMETAD 0:off 1:off 2:on 3:on 4:on 5:on 6:off
创建rrd数据存储的文件夹, 修改属性拥有者为: "nobody":
点击(此处)折叠或打开
- mkdir /var/lib/ganglia/rrds
- chown nobody:nobody /var/lib/ganglia/rrds
启动gmetad:
点击(此处)折叠或打开
- service gmetad start
- Starting GANGLIA gmetad: [ OK ]
修改 /etc/gmetad.conf文件:
点击(此处)折叠或打开
- data_source "taskcenter" 1.2.3.4 #所要监控的客户端 可以写多个
- setuid_username "root" #可改为其他安全用户
- # default: "/data/ganglia/rrds" #定义该客户端的数据保存的路径
- # rrd_rootdir "/some/other/place"
- rrd_rootdir "/data/ganglia/rrds"
重新启动gmetad:
点击(此处)折叠或打开
- service gmetad start
- Starting GANGLIA gmetad: [ OK ]
验证gmetad正常工作:
点击(此处)折叠或打开
- telnet localhost 8651
就可以得到监控的各个主机的状态。
在每台需要监控的机器上,安装gmond
安装ganglia:
点击(此处)折叠或打开
- tar zxvf ganglia-3.0.3.tar.gz
- cd ganglia-3.0.3
- ./configure --prefix=/usr/local/ganglia --sysconfdir=/etc/ganglia --enable-gexec
- make;
- make install
- cd gmond
- mkdir /etc/ganglia
- ./gmond –t | tee /etc/ganglia/gmond.conf
点击(此处)折叠或打开
- vi gmond.init
- 修改里面的GMOND 改为GMOND=/usr/local/ganglia/sbin/gmond
- # cp gmond.init /etc/init.d/gmond
- # chkconfig --add gmond
- # chkconfig --list gmond
- # chkconfig gmond on
- gmond 0:off 1:off 2:on 3:on 4:on 5:on 6:off
- # service gmond start
- Starting GANGLIA gmond: [ OK ] #若不成功的话,就用/usr/local/ganglia/sbin/gmond手动启动
启动失败有可能是因为多播地址没有路由
点击(此处)折叠或打开
- route add -host 239.2.11.71 dev eth0
验证gmond正常工作:
点击(此处)折叠或打开
- telnet localhost 8649
就可以获取机群内运行gmond的主机的信息
vi /etc/ganglia/gmond.conf
配置gmond.conf:
点击(此处)折叠或打开
- /etc/gmond.conf:
- globals
- {
- setuid = no
- user = nobody
- cleanup_threshold = 300 /*secs */
- }
- #修改监控组名称
- cluster
- {
- name = "taskcenter"
- .......}
配置完成后重新启动gmond
web端用于通过web来查看监控状态。
因为web端程序是php写的,所以需要安装apache。同时需要编译php的gd库。web端需要和服务器端在一块。
#yum install httpd
#yum install python
# cp -a ganglia-3.0.3/web /var/www/html/ganglia
确定web server支持PHP4
对apache来说,php模块mod_php的状态应该是enabled,貌似默认就是的^_^
配制文件是/var/www/html/ganglia/conf.php
点击(此处)折叠或打开
- # Where gmetad stores the rrd archives.
- $gmetad_root = "/data/ganglia";
- $rrds = "$gmetad_root/rrds"; #数据源路径
- # Leave this alone if rrdtool is installed in $gmetad_root,
- # otherwise, change it if it is installed elsewhere (like /usr/bin)
- define("RRDTOOL", "/usr/local/rrdtool-1.0.50/bin/rrdtool"); # rrdtool执行路径
- #
- # If you want to grab data from a different ganglia source specify it here.
- # Although, it would be strange to alter the IP since the Round-Robin
- # databases need to be local to be read.
- #
- $ganglia_ip = "localhost";
- $ganglia_port = 8652;
- #$ganglia_port = 8649;
在浏览器地址栏输入http://localhost/ganglia/应该可以看到有页面显示了。
访问web出现图片画不出来的原因:
1) rrdtool没有安装,或者conf.php里没有配置
2) gemtad没有启动
3) 没有客户端数据
4) Selinux限制apache执行rrdtool
data_source "Datanode" 192.168.1.27:8649
data_source "Portal" 192.168.1.43:8650
data_source "Collector" 192.168.1.35:8651
data_source "DB" 192.168.1.51:8652
gridname "Hadoop"
rrd_rootdir "/data/ganglia/rrds"
#配置rrd数据保存文件的路径,给web界面用的,这个是固定的,最好放在web文件夹下,并赋予正确的权限
case_sensitive_hostnames 0
name = "Portal"
#对应gmetad中的Portal,名称一定要写对。
owner = "unspecified"
latlong = "unspecified"
url = "unspecified"
}
/* Feel free to specify as many udp_send_channels as you like. Gmond
used to only support having a single channel */
udp_send_channel {
#bind_hostname = yes # Highly recommended, soon to be default.
# This option tells gmond to use a source address
# that resolves to the machine's hostname. Without
# this, the metrics may appear to come from any
# interface and the DNS names associated with
# those IPs will be used to create the RRDs.
mcast_join = 239.2.11.71
port = 8650
#gmetad中的Portal所分配的端口号。
ttl = 1
}
/* You can specify as many udp_recv_channels as you like as well. */
udp_recv_channel {
mcast_join = 239.2.11.71
port = 8650
bind = 239.2.11.71
}
/* You can specify as many tcp_accept_channels as you like to share
an xml description of the state of the cluster */
tcp_accept_channel {
port = 8650
}
name = "DB"
owner = "unspecified"
latlong = "unspecified"
url = "unspecified"
}
/* The host section describes attributes of the host, like the location */
host {
location = "unspecified"
}
/* Feel free to specify as many udp_send_channels as you like. Gmond
used to only support having a single channel */
udp_send_channel {
#bind_hostname = yes # Highly recommended, soon to be default.
# This option tells gmond to use a source address
# that resolves to the machine's hostname. Without
# this, the metrics may appear to come from any
# interface and the DNS names associated with
# those IPs will be used to create the RRDs.
mcast_join = 239.2.11.71
port = 8652
ttl = 1
}
/* You can specify as many udp_recv_channels as you like as well. */
udp_recv_channel {
mcast_join = 239.2.11.71
port = 8652
bind = 239.2.11.71
}
/* You can specify as many tcp_accept_channels as you like to share
an xml description of the state of the cluster */
tcp_accept_channel {
port = 8652
}
通过web方式访问ganglia不需要密码,所以我们通过apache设置密码达到安全目的。
①
htpasswd -c /etc/httpd/conf.d/passwords {your_name}
②
vi /etc/httpd/conf/httpd.conf
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
修改为:
<Directory />
Options None
AllowOverride None
Order allow,deny
Allow from all
AuthName "Ganglia Access"
AuthType Basic
AuthUserFile /etc/httpd/conf.d/passwords
Require valid-user
</Directory>