CentOS6下安装ganglia集群监控

前面的话

ganglia是一个用于监控Linux系统集群环境的主机各项性能的开源软件,使用广泛。
装这个东西竟然花了我几天的时间,实在觉得有点浪费了。所以先和大家说,最好不要去解压ganglia某个版本的包和依赖图形软件rrdtool的包,因为他们对版本环境什么的都有各种要求,装起来比较麻烦,并且最后还会出现一些未知的问题,就是我踩过的各种坑。现在给大家贴一个简单的安装方法,全程yum,主要是快而且不容易出问题,也留给以后的自己。

环境结构说明

我现在有十二台服务器,需要搭建几个集群环境,我以主机名为HDP-01为主节点,采用多播(省内存,且更快)的方式集群监控各机器运行情况。
首先,在HDP-01的hosts中配置了主机信息,目的是为了读取各机器的主机名而不是ip,不配也可以。
# vi /etc/hosts
配置信息如下:

192.168.1.11    HDP-01
192.168.1.12    HDP-02
192.168.1.13    HDP-03
192.168.1.14    HDP-04
192.168.1.15    HDP-05
192.168.1.16    HDP-06
192.168.1.17    HDP-09
192.168.1.18    HDP-10
192.168.1.19    HDP-11
192.168.1.20    HDP-12
192.168.1.21    HDP-13
192.168.1.22    HDP-14

软件安装

root模式下进行所有操作。
# sudo su root
安装gmetad(服务器端)
# yum install -y ganglia-gmetad ganglia-devel
安装gmond(客户端)
# yum install -y ganglia-gmond
安装依赖图形软件rrdtool,先确认已卸载旧版本
# yum erase rrdtool -y
# yum install -y rrdtool
安装httpd服务器(用于搭建php网页服务器)
# yum install -y httpd
安装ganglia-webphp
yum install -y ganglia-web php

软件安装目录说明

  • ganglia配置文件目录:/etc/ganglia
  • rrd数据库存放目录:/var/lib/ganglia/rrds
  • httpd主站点目录:/var/www/html
  • ganglia-web安装目录:/usr/share/ganglia
  • ganglia-web配置目录:/etc/httpd/conf.d/ganglia.conf

配置服务端(gmetad)

将ganglia-web的站点目录连接到httpd主站点目录
# ln -s /usr/share/ganglia/ /var/www/html/
修改httpd主站点目录下ganglia站点目录的访问权限
将ganglia站点目录访问权限改为apache:apache
# chown -R apache:apache /var/www/html/ganglia/
# chmod -R 755 /var/www/html/ganglia/
修改rrd数据库存放目录访问权限
将rrd数据库存放目录访问权限改为ganglia:ganglia,这个是默认权限,也可以在gmetad中修改为root或nobody,这边做相应修改
# chown -R ganglia:ganglia /var/lib/ganglia/rrds/
修改ganglia-web的访问权限:
# vi /etc/httpd/conf.d/ganglia.conf

Alias /ganglia /usr/share/ganglia
<Location /ganglia>
  Order deny,allow
  # Deny from all
  # Allow from 127.0.0.1
  # Allow from ::1
  Allow from all
  # Allow from .example.com
</Location>

配置 /etc/ganglia/gmetad.conf
data_source "cluster_yuan" 1 HDP-01:8649

每个data_source由3个字段组成。第一个字段为唯一标识data_source的字符串;第二个字段为指定轮询间隔(单位:秒)的数字;第三个字段为以空格分开的所要轮询数据的主机列表,这些地址以IP地址或DNS主机名的形式指定,并可能添加“:端口号”形式的后缀,该端口号指明gmond的tcp_accept_channel所在位置。如果未指明端口号,gmetad将尝试连接tcp/8649。
注意: gmetad会依次检测指定主机,并从第一台响应主机开始收集状态数据,所以无需在data_source定义里指定集群内的所有主机。假若有节点失效,通常指定两三个主机也就足够保证数据的收集。

case_sensitive_hostnames 1

这个也可以不配置。在gmetad之前版本中,RRD文件区分主机名大小写,但是现在已经有所改变。如果希望继续使用Ganglia 3.2之前版本创建的RRD文件,将该值设置为1。从Ganglia 3.2开始,该值默认设置为0。

配置客户端(gmond)

# vi /etc/ganglia/gmetad.conf
多播模式下

cluster {
name = "cluster_yuan"
owner = "unspecified"
latlong = "unspecified"
url = "unspecified"
}
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
#host = 172.16.1.11
port = 8649
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 = 8649
  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 = 8649
}

单播模式下:

cluster {
name = "cluster_yuan"
owner = "unspecified"
latlong = "unspecified"
url = "unspecified"
}
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
host = 192.168.1.11
port = 8649
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 = 8649
  #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 = 8649
}

如果你修改了rrd数据文件夹的读写权限,下面两处也需要修改一下,假如权限组为nobody

globals {
daemonize = yes
setuid = yes
user = nobody
debug_level = 0
max_udp_msg_len = 1472
mute = no
deaf = no
allow_extra_data = yes
host_dmax = 0 /*secs */
cleanup_threshold = 300 /*secs */
gexec = no
send_metadata_interval = 0 /*secs */
}
cluster {
name = "cluster_yuan"
owner = "nobody"
latlong = "unspecified"
url = "unspecified"
}

集群效果图

《CentOS6下安装ganglia集群监控》 首页图
《CentOS6下安装ganglia集群监控》 单机性能图

可能会遇到的相关错误

  1. 如果出现错误:There was an error collecting ganglia data (127.0.0.1:8652): fsockopen error: Permission denied
  • 可能原因1:SELINUX配置问题
    关闭selinux,vi /etc/selinux/config,把SELINUX=enforcing改成SELINUX=disable;该方法需要重启机器。
    可以使用命令setenforce 0来关闭selinux而不需要重启,刷新页面,即可访问;不过此法只是权宜之计,如果想永久修改selinux设置,还是要使用第一种方法
  • 可能原因2:rrds目录的访问权限未正确配置
    给/var/lib/ganglia/rrds目录赋予nobody:nobody的可访问权限
  1. 如果出现错误:/ganglia无法访问,但同时,httpd server可以正常访问,则说明是/ganglia站点的访问权限或相关目录的权限配置有问题
  • 可能原因1:/etc/httpd/conf.d/ganglia.conf配置文件未修改正确
    注释掉其他内容,添加“Allow from all”
  • 可能原因2:/var/www/html/ganglia目录没有赋予正确的访问权限
    hown -R apache:apache /var/www/html/ganglia chmod -R 755 /var/www/html/ganglia

参考

开始入坑的时候看了太多太多博客和论坛..感觉列举不来,本文主要参考
Ganglia的安装与配置

    原文作者:syncwt
    原文地址: https://www.jianshu.com/p/be4761ed15df
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞