Hadoop--Ganglia集群监控

  Ganglia 是 UC Berkeley 发起的一个开源监视项目,设计用于测量数以千计的节点。每台计算机都运行一个收集和发送度量数据(如处理器速度、内存使用量等)的名为 gmond 的守护进程,gmond 带来的系统负载非常少,不会影响用户性能。

Ganglia简介

  • Ganglia 监控套件包括个主要部分:gmetadgmond,和网页接口(ganglia-web)
  • Gmetad :也是一个守护进程,他定期检查gmonds,从那里拉取数据,并将他们的指标存储在RRD存储引擎中。他可以查询多个集群并聚合指标。
  • Gmond :是一个守护进程,他运行在每一个需要监测的节点上发送和接受在同一个组播或单播通道上的统计信息发送-收集基本指标,比如系统负载、CPU利用率等。 接收者-聚合所有从别的主机上发来的指标,并把它们都保存在内存缓冲区中。
  • Ganglia-web :安装在有gmetad运行的机器上,以便读取RRD文件。
  • 一般集群中每个节点需要一个接收的gmond,每个网站需要一个gmetad

安装

  • 一、安装依赖
    1
    2
    ############## 注:建议使用超级用户安装
    [root@xxo04 ~]# 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依赖

1
2
3
4
5
6
[root@xxo04 ~]# cd /root
[root@xxo04 ~]# wget http://jaist.dl.sourceforge.net/project/expat/expat/2.1.0/expat-2.1.0.tar.gz
[root@xxo04 ~]# tar -xf expat-2.1.0.tar.gz && cd expat-2.1.0 && ./configure --prefix=/usr/local/expat && make && make install && cd ..

###### 对于64位操作系统,需要手动的拷贝下动态链接库到lib64下 ######
[root@xxo04 ~]# mkdir /usr/local/expat/lib64 && cp -a /usr/local/expat/lib/* /usr/local/expat/lib64/

四、安装confuse

1
2
3
4
5
[root@xxo04 ~]# wget http://ftp.twaren.net/Unix/NonGNU//confuse/confuse-2.7.tar.gz
[root@xxo04 ~]# tar -xf confuse-2.7.tar.gz && cd confuse-2.7 && ./configure CFLAGS=-fPIC --disable-nls --prefix=/usr/local/confuse && make && make install && cd ..

####### 64bit机器需要拷贝动态链接库: #########################
[root@xxo04 ~]# mkdir -p /usr/local/confuse/lib64 && cp -a -f /usr/local/confuse/lib/* /usr/local/confuse/lib64/

五、安装ganglia

1
2
[root@xxo04 ~]# wget http://jaist.dl.sourceforge.net/project/ganglia/ganglia%20monitoring%20core/3.6.0/ganglia-3.6.0.tar.gz
[root@xxo04 ~]# 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 && cd ..

六、服务端配置

1
2
3
4
5
6
7
8
9
10
11
12
13
14
########创建rrdtool数据目录,看$ganglia-3.2.0/web/conf.php里面的gmetad_root变量######
[root@xxo04 ~]# mkdir -p /var/lib/ganglia/rrds && mkdir -p /var/lib/ganglia/dwoo && chown -R root:root /var/lib/ganglia

########配置一个数据源,修改/etc/ganglia/gmetad.conf文件,同时将运行用户设置为rrdtool的目录权限用户,例如root用户
data_source "Hadoop" xxo04:8649 #### 44行
setuid_username "root" #### 102行
说明:这里的 " hadoop " 表示的是集群的名称,后面的内容是这个集群中所包含的主机信息,也就是要监控的主机(ip或主机名)。

########添加自启动脚本
[root@xxo04 ~]# cp -f ganglia-3.6.0/gmetad/gmetad.init /etc/init.d/gmetad && cp -f /usr/local/ganglia/sbin/gmetad /usr/sbin/gmetad && chkconfig --add gmetad

########启动gmetad服务
[root@xxo04 ~]# service gmetad start
Starting GANGLIA gmetad: [ OK ] ##代表运行正常

七、客户端配置(gmond节点)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
[root@xxo04 ~]# cp -f ganglia-3.6.0/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

###############修改 /etc/ganglia/gmond.conf ######################
globals {
user = root ### 6行 运行Ganglia的用户
host_dmax = 120 ### 12行 secs
send_metadata_interval = 15 ###21行 /*发送数据的时间间隔*/
}

cluster {
name = "Hadoop" ### 30行 /*集群名称*/
owner = "root" ### 31行 /*运行Ganglia的用户*/
}

udp_send_channel {
# mcast_join = 239.2.11.71 ### 50行 /*注释掉组播*/
host = xxo04 ### 51行 新增行/*发送给安装gmetad的机器*/
}

udp_recv_channel { #接受UDP包配置
# mcast_join = 239.2.11.71 ### 58行 /*注释掉*/
# bind = 239.2.11.71 ### 60行 /*注释掉*/
}

############### 开启服务 #####################################
[root@xxo04 ~]# service gmond start
Starting GANGLIA gmond: [ OK ] ##成功

八、服务端的WEB配置

1
2
3
################ PHP程序需要依赖Apache来运行,因此需要安装如下依赖
[root@xxo04 ~]# yum -y install php httpd
[root@xxo04 ~]# service httpd start ####启动httpd 服务

九、生成了ganglia-web目录

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
[root@xxo04 ~]# cd /root
[root@xxo04 ~]# wget http://jaist.dl.sourceforge.net/project/ganglia/ganglia-web/3.5.10/ganglia-web-3.5.10.tar.gz
[root@xxo04 ~]# tar -xf ganglia-web-3.5.10.tar.gz && cd ganglia-web-3.5.10 && make install && cd ..
rsync --exclude "rpmbuild" --exclude "*.gz" --exclude "Makefile" --exclude "*debian*" --exclude "ganglia-web-3.5.10" --exclude ".git*" --exclude "*.in" --exclude "*~" --exclude "#*#" --exclude "ganglia-web.spec" -a . ganglia-web-3.5.10
mkdir -p //var/lib/ganglia-web/dwoo/compiled && \
mkdir -p //var/lib/ganglia-web/dwoo/cache && \
mkdir -p //var/lib/ganglia-web && \
rsync -a ganglia-web-3.5.10/conf //var/lib/ganglia-web && \
mkdir -p //var/www/html/ganglia && \
rsync --exclude "conf" -a ganglia-web-3.5.10/* //var/www/html/ganglia && \
chown -R apache:apache //var/lib/ganglia-web

################### 这样 在/var/www/html/下 生成了 ganglia 目录
注: Ganglia访问失败:
There was an error collecting ganglia data (127.0.0.1:8652): fsockopen error: Permission denied
解决:
1. 需要关闭selinux:vi /etc/selinux/config,把SELINUX=enforcing改成SELINUX=disabled;需要重启(永久)。
2. 命令setenforce 0来关闭selinux;不需要重启(临时) 

#################### 重启httpd服务器
[root@xxo04 ~]# service httpd restart

监控hadoop集群

在博客Hadoop2.0集群中我们搭建了hadoop集群,分别是xxo04xxo05xxo06上述中我们已经在xx04安装好了ganglia的gmetad、gmond和web
如果我们要监控xxo04、xxo05、xxo06的状态,所以还需要在xxo05、xxo06中安装gmond注意:只需要安装gmond,请重复上述步骤(不需要第六、第八、第九步骤)。

  • 启动

    1
    2
    3
    4
    [root@xxo04 ~]# service httpd status
    httpd is stopped
    [root@xxo04 ~]# service httpd start
    Starting httpd: httpd: Could not reliably determine the server's fully qualified domain name, using 192.168.33.69 for ServerName
  • 查看ganglia集群监控:http://xxo04/ganglia/
    运行Apache

当前网速较慢或者你使用的浏览器不支持博客特定功能,请尝试刷新或换用Chrome、Firefox等现代浏览器