Ganglia 是 UC Berkeley 发起的一个开源监视项目,设计用于测量数以千计的节点。每台计算机都运行一个收集和发送度量数据(如处理器速度、内存使用量等)的名为 gmond 的守护进程。它将从操作系统和指定主机中收集。接收所有度量数据的主机可以显示这些数据并且可以将这些数据的精简表单传递到层次结构中。正因为有这种层次结构模式,才使得 Ganglia 可以实现良好的扩展。gmond 带来的系统负载非常少,这使得它成为在集群中各台计算机上运行的一段代码,而不会影响用户性能。
一、Ganglia组件
Ganglia 监控套件包括三个主要部分:gmond,gmetad,和网页接口,通常被称为ganglia-web。
Gmond :是一个守护进程,他运行在每一个需要监测的节点上,收集监测统计,发送和接受在同一个组播或单播通道上的统计信息 如果他是一个发送者(mute=no)他会收集基本指标,比如系统负载(load_one),CPU利用率。他同时也会发送用户通过添加C/Python模块来自定义的指标。 如果他是一个接收者(deaf=no)他会聚合所有从别的主机上发来的指标,并把它们都保存在内存缓冲区中。
Gmetad:也是一个守护进程,他定期检查gmonds,从那里拉取数据,并将他们的指标存储在RRD存储引擎中。他可以查询多个集群并聚合指标。他也被用于生成用户界面的web前端。
Ganglia-web :顾名思义,他应该安装在有gmetad运行的机器上,以便读取RRD文件。 集群是主机和度量数据的逻辑分组,比如数据库服务器,网页服务器,生产,测试,QA等,他们都是完全分开的,你需要为每个集群运行单独的gmond实例。
一般来说每个集群需要一个接收的gmond,每个网站需要一个gmetad。
Ganglia工作流如图所示:
右上角是更加负责的中心机(通常是这个集群中的一台,也可以不是)。在这个台机器上运行这着gmetad进程,收集来自各个节点上的信息并存储在rrdtool上,该进程的配置只由/etc/gmetad.conf决定。
右下角显示了关于网页方面的一些信息。我们的浏览网站时调用php脚本,从RRDTool数据库中抓取信息,动态的生成各类图表。
二、安装依赖
注:建议使用超级用户安装
#yum install –y gcc gcc-c++ libpng freetype zlib libdbi apr* libxml2-devel pkg-config glib pixman \ pango pango-devel freetye-devel fontconfig cairo cairo-devel libart_lgpl libart_lgpl-devel pcre* rrdtool*三、安装expat依赖
#cd /home/aaron #wget http://jaist.dl.sourceforge.net/project/expat/expat/2.1.0/expat-2.1.0.tar.gz #tar -xf expat-2.1.0.tar.gz #cd expat-2.1.0 #./configure --prefix=/usr/local/expat #make #make install
对于64位操作系统,需要手动的拷贝下动态链接库到lib64下
#mkdir /usr/local/expat/lib64 #cp -a /usr/local/expat/lib/* /usr/local/expat/lib64/
四、安装confuse
#cd /home/aaron #wget http://ftp.twaren.net/Unix/NonGNU//confuse/confuse-2.7.tar.gz #tar -xf confuse-2.7.tar.gz #cd confuse-2.7 #./configure CFLAGS=-fPIC --disable-nls --prefix=/usr/local/confuse #make #make install64bit机器需要拷贝动态链接库:
#mkdir -p /usr/local/confuse/lib64 #cp -a -f /usr/local/confuse/lib/* /usr/local/confuse/lib64/五、安装ganglia
#cd /home/aaron #wget http://jaist.dl.sourceforge.net/project/ganglia/ganglia%20monitoring%20core/3.6.0/ganglia-3.6.0.tar.gz #tar -xf ganglia-3.6.0.tar.gz #cd ganglia-3.6.0 #./configure --with-gmetad --enable-gexec --with-libconfuse=/usr/local/confuse --with-libexpat=/usr/local/expat --prefix=/usr/local/ganglia --sysconfdir=/etc/ganglia #make #make install六、服务端配置
#mkdir -p /var/lib/ganglia/rrds #mkdir -p /var/lib/ganglia/dwoo #chown -R root:root /var/lib/ganglia配置一个数据源,修改/etc/ganglia/gmetad.conf文件,同时将运行用户设置为rrdtool的目录权限用户,例如apache用户
data_source "hadoop" 192.168.1.108:8649 setuid_username "root"说明:这里的 " hadoop " 表示的是集群的名称,后面的内容是这个集群中所包含的主机信息,也就是要监控的主机ip。
#cp -f gmetad/gmetad.init /etc/init.d/gmetad #cp -f /usr/local/ganglia/sbin/gmetad /usr/sbin/gmetad #chkconfig --add gmetad启动gmetad服务
#service gmetad start看见Starting GANGLIA gmetad: [ OK ]就代表运行正常了。 通过telnet localhost 8651验证gmetad是否正常
#cp -f gmond/gmond.init /etc/init.d/gmond #cp -f /usr/local/ganglia/sbin/gmond /usr/sbin/gmond #chkconfig --add gmond #gmond --default_config > /etc/ganglia/gmond.conf对于生成的默认配置文件需要做适当的修改
globals { daemonize = yes setuid = yes user = root /*运行Ganglia的用户*/ debug_level = 0 max_udp_msg_len = 1472 mute = no deaf = no host_dmax = 120 /*secs */ cleanup_threshold = 300 /*secs */ gexec = no send_metadata_interval = 15 /*发送数据的时间间隔*/ } cluster { name = "hadoop" /*集群名称*/ owner = "root" /*运行Ganglia的用户*/ latlong = "unspecified" url = "unspecified" } udp_send_channel { # mcast_join = 239.2.11.71 /*注释掉组播*/ host = 192.168.1.108/*发送给安装gmetad的机器*/ port = 8649 ttl = 1 } udp_recv_channel { #接受UDP包配置 # mcast_join = 239.2.11.71 port = 8649 # bind = 239.2.11.71 }其中name是将要在服务端进行的分组,是服务端的数据源。接下来开启服务
#service gmond start看见Starting GANGLIA gmetad: [ OK ]代表启动成功。如果有失败,可以讲gmond.conf中的debug从0改为100,看更多的日志,然后进行排查。
八、服务端的WEB配置
PHP程序需要依赖Apache来运行,因此需要安装如下依赖
# yum -y install php httpd # service httpd start //启动httpd 服务
九、测试安装是否成功
# vi /var/www/html/index.php输入:
<?php phpinfo(); ?>保存,然后浏览器 master/index.php
#cd /home/ruifeng.shan #wget http://jaist.dl.sourceforge.net/project/ganglia/ganglia-web/3.5.10/ganglia-web-3.5.10.tar.gz #tar -xf ganglia-web-3.5.10.tar.gz #cd ganglia-web-3.5.10 #make install这样 在/var/www/html/下 生成了 ganglia 目录
#service httpd restart使用http://master/ganglia查看对应的ganglia信息。(注:master为运行gmetad的主机的hostname)
Hadoop和HBase社区一直使用它作为监控集群的业界标准方案。在maste上安装gmetad,在master、node、slave上安装gmond。为了监控Hadoop和HBase,需要对它们做一些配置。这里Hadoop使用的是2.2.0版本,HBase使用的是0.96.0这个版本。这里监控的分布式集群也是文章《Ubuntu和CentOS中分布式配置Hadoop-2.2.0》和《CentOS分布式环境安装HBase-0.96.0》中布置的hadoop和hbase。
为了能让ganglia监控hadoop,Hadoop2.2.0需要配置hadoop-2.2.0/etc/hadoop/目录下的hadoop-metrics.properties和hadoop-metrics2.properties文件。其中,hadoop-metrics.properties配置如下:
# Configuration of the "dfs" context for null dfs.class=org.apache.hadoop.metrics.spi.NullContext # Configuration of the "dfs" context for file #dfs.class=org.apache.hadoop.metrics.file.FileContext #dfs.period=10 #dfs.fileName=/tmp/dfsmetrics.log # Configuration of the "dfs" context for ganglia # Pick one: Ganglia 3.0 (former) or Ganglia 3.1 (latter) # dfs.class=org.apache.hadoop.metrics.ganglia.GangliaContext # dfs.class=org.apache.hadoop.metrics.ganglia.GangliaContext31 # dfs.period=10 # dfs.servers=localhost:8649 # Configuration of the "mapred" context for null mapred.class=org.apache.hadoop.metrics.spi.NullContext # Configuration of the "mapred" context for file #mapred.class=org.apache.hadoop.metrics.file.FileContext #mapred.period=10 #mapred.fileName=/tmp/mrmetrics.log # Configuration of the "mapred" context for ganglia # Pick one: Ganglia 3.0 (former) or Ganglia 3.1 (latter) # mapred.class=org.apache.hadoop.metrics.ganglia.GangliaContext # mapred.class=org.apache.hadoop.metrics.ganglia.GangliaContext31 # mapred.period=10 # mapred.servers=localhost:8649 # Configuration of the "jvm" context for null #jvm.class=org.apache.hadoop.metrics.spi.NullContext # Configuration of the "jvm" context for file #jvm.class=org.apache.hadoop.metrics.file.FileContext #jvm.period=10 #jvm.fileName=/tmp/jvmmetrics.log # Configuration of the "jvm" context for ganglia # jvm.class=org.apache.hadoop.metrics.ganglia.GangliaContext # jvm.class=org.apache.hadoop.metrics.ganglia.GangliaContext31 # jvm.period=10 # jvm.servers=localhost:8649 # Configuration of the "rpc" context for null rpc.class=org.apache.hadoop.metrics.spi.NullContext # Configuration of the "rpc" context for file #rpc.class=org.apache.hadoop.metrics.file.FileContext #rpc.period=10 #rpc.fileName=/tmp/rpcmetrics.log # Configuration of the "rpc" context for ganglia # rpc.class=org.apache.hadoop.metrics.ganglia.GangliaContext # rpc.class=org.apache.hadoop.metrics.ganglia.GangliaContext31 # rpc.period=10 # rpc.servers=localhost:8649 # Configuration of the "ugi" context for null ugi.class=org.apache.hadoop.metrics.spi.NullContext # Configuration of the "ugi" context for file #ugi.class=org.apache.hadoop.metrics.file.FileContext #ugi.period=10 #ugi.fileName=/tmp/ugimetrics.log # Configuration of the "ugi" context for ganglia # ugi.class=org.apache.hadoop.metrics.ganglia.GangliaContext # ugi.class=org.apache.hadoop.metrics.ganglia.GangliaContext31 # ugi.period=10 # ugi.servers=localhost:8649
hadoop-metrics2.properties文件配置如下:
# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. # The ASF licenses this file to You under the Apache License, Version 2.0 # (the "License"); you may not use this file except in compliance with # the License. You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # # syntax: [prefix].[source|sink].[instance].[options] # See javadoc of package-info.java for org.apache.hadoop.metrics2 for details ##############一定要注释掉原来的这块,否则会监控不到######### #*.sink.file.class=org.apache.hadoop.metrics2.sink.FileSink # default sampling period, in seconds #*.period=10 ############################################################# # The namenode-metrics.out will contain metrics from all context #namenode.sink.file.filename=namenode-metrics.out # Specifying a special sampling period for namenode: #namenode.sink.*.period=8 #datanode.sink.file.filename=datanode-metrics.out # the following example split metrics of different # context to different sinks (in this case files) #jobtracker.sink.file_jvm.context=jvm #jobtracker.sink.file_jvm.filename=jobtracker-jvm-metrics.out #jobtracker.sink.file_mapred.context=mapred #jobtracker.sink.file_mapred.filename=jobtracker-mapred-metrics.out #tasktracker.sink.file.filename=tasktracker-metrics.out #maptask.sink.file.filename=maptask-metrics.out #reducetask.sink.file.filename=reducetask-metrics.out *.sink.ganglia.class=org.apache.hadoop.metrics2.sink.ganglia.GangliaSink31 *.sink.ganglia.period=10 *.sink.ganglia.slope=jvm.metrics.gcCount=zero,jvm.metrics.memHeapUsedM=both *.sink.ganglia.dmax=jvm.metrics.threadsBlocked=70,jvm.metrics.memHeapUsedM=40 namenode.sink.ganglia.servers=master:8649 resourcemanager.sink.ganglia.servers=master:8649 datanode.sink.ganglia.servers=master:8649 nodemanager.sink.ganglia.servers=master:8649 maptask.sink.ganglia.servers=master:8649 reducetask.sink.ganglia.servers=master:8649为了让ganglia监控hbase,需要配置hbase-0.96.0目录下的conf目录中的hadoop-metrics2-hbase.properties文件。内容如下:
# syntax: [prefix].[source|sink].[instance].[options] # See javadoc of package-info.java for org.apache.hadoop.metrics2 for details ##############一定要注释掉原来的这块,否则会监控不到######### #*.sink.file*.class=org.apache.hadoop.metrics2.sink.FileSink # default sampling period #*.period=10 ############################################################# # Below are some examples of sinks that could be used # to monitor different hbase daemons. # hbase.sink.file-all.class=org.apache.hadoop.metrics2.sink.FileSink # hbase.sink.file-all.filename=all.metrics # hbase.sink.file0.class=org.apache.hadoop.metrics2.sink.FileSink # hbase.sink.file0.context=hmaster # hbase.sink.file0.filename=master.metrics # hbase.sink.file1.class=org.apache.hadoop.metrics2.sink.FileSink # hbase.sink.file1.context=thrift-one # hbase.sink.file1.filename=thrift-one.metrics # hbase.sink.file2.class=org.apache.hadoop.metrics2.sink.FileSink # hbase.sink.file2.context=thrift-two # hbase.sink.file2.filename=thrift-one.metrics # hbase.sink.file3.class=org.apache.hadoop.metrics2.sink.FileSink # hbase.sink.file3.context=rest # hbase.sink.file3.filename=rest.metrics *.sink.ganglia.class=org.apache.hadoop.metrics2.sink.ganglia.GangliaSink31 *.sink.ganglia.period=10 hbase.sink.ganglia.period=10 hbase.sink.ganglia.servers=master:8649