Ganglia是UC Berkeley发起的一个开源集群监视项目,设计用于测量数以千计的节点。Ganglia的核心包含gmond、gmetad以及一个Web前端。主要是用来监控系统性能,如:cpu 、mem、硬盘利用率, I/O负载、网络流量情况等,通过曲线很容易见到每个节点的工作状态,对合理调整、分配系统资源,提高系统整体性能起到重要作用。
Ganglia包括如下几个程序,他们之间通过XDR(xml的压缩格式)或者XML格式传递监控数据,达到监控效果。集群内的节点,通过运行gmond收集发布节点状态信息,然后gmetad周期性的轮询gmond收集到的信息,然后存入rrd数据库,通过web服务器可以对其进行查询展示。
gmetad:定期从gmond获取数据,并将数据存储到RRD存储引擎中。
gmond:被监控端代理程序,用于收集监控信息,并发送给gmetad。
ganglia-web:WEB前端,RRD绘图后通过PHP展示。
一。CentOS7 YUM源自带epel网络源,直接安装
先安装依赖
# 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*
# yum install epel-release
# yum install ganglia-web ganglia-gmetad ganglia-gmond
二。配置监控端
【1】配置监控程序
# vi /etc/ganglia/gmetad.conf #修改以下两项
data_source "hadoop_name" *.*.*.* *.*.*.* 192.*.*.*
case_sensitive_hostnames 1
参数说明:
第一个是数据源,Hadoop是集群名字,后跟IP是集群中被监控节点地址。
第二个意思是是否区分主机名大小写,默认是0,修改为1,否则节点中主机名有大写的将保存为小写,写到/var/lib/ganglia/rrds/Hadoop中,导致图形无数据。
【2】关联Apache,因为Ganglia自创建的配置ganglia.conf有问题,所以先删除,再创建个软连接到Apache根目录下。
# rm /etc/httpd/conf.d/ganglia.conf
# ln -s /usr/share/ganglia /var/www/html/ganglia
【3】PHP程序需要依赖Apache来运行。启动Apache和Ganglia,并设置开机启动
# systemctl start httpd
# systemctl start gmetad
# systemctl enable httpd
# systemctl enable gmetad
三。安装与配置被监控端
【1】安装与配置代理程序
# yum install ganglia-gmond
# vi /etc/ganglia/gmond.conf
……
cluster{
name = "hadoop_name" #集群名,和上面那个一样
owner = "unspecified"
latlong = "unspecified"
url = "unspecified"
}
/* Thehost 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 asource address
# that resolves to themachine's hostname. Without
# this, the metrics mayappear to come from any
# interface and the DNSnames associated with
# those IPs will be usedto create the RRDs.
#mcast_join = 239.2.11.71 #关闭多播
host = *.*.*.* #添加发送IP/主机名
port = 8649 #默认端口
ttl = 1
}
/* Youcan specify as many udp_recv_channels as you like as well. */
udp_recv_channel{
#mcast_join = 239.2.11.71
port = 8649
bind = *.*.*.* #接收地址
retry_bind = true
# Size of the UDP buffer. If you are handlinglots of metrics you really
# should bump it up to e.g. 10MB or evenhigher.
# buffer = 10485760
}
……
【2】将修改好的gmond.conf配置scp到其他节点
# scp /etc/ganglia/gmond.conf slave1:/etc/ganglia/gmond.conf
【3】启动代理程序,并设置开机启动
# systemctl start gmond
# systemctl enable gmond
【4】添加Hadoop被Ganglia监控,去掉文件中以***释并修改
# vi */hadoop/etc/hadoop/hadoop-metrics2.properties
*.sink.ganglia.class=org.apache.hadoop.metrics2.sink.ganglia.GangliaSink31
*.sink.ganglia.period=10
*.sink.ganglia.supportsparse=true
*.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=*.*.*.*:8649 #当有多个ganglia监控系统时,以逗号分隔
datanode.sink.ganglia.servers=*.*.*.*:8649 #都指定ganglia服务器
resourcemanager.sink.ganglia.servers=*.*.*.*:8649
nodemanager.sink.ganglia.servers=*.*.*.*:8649
【5】添加HBase被Ganglia监控
修改hbase配置文件hadoop-metrics2-hbase.properties
*.sink.ganglia.class=org.apache.hadoop.metrics2.sink.ganglia.GangliaSink31
*.sink.ganglia.period=10
hbase.sink.ganglia.period=10
hbase.sink.ganglia.servers=*.*.*.*:8649
【6】重启Hadoop和HBase
【7】通过WEB查看性能监控数据
访问http://*.*.*.*/ganglia
感谢原文作者李振良https://yq.aliyun.com/articles/38824