在 CentOS上安装配置 Ganglia-3.4.0

CentOS上安装配置 Ganglia-3.4.0

1Ganglia简介:
Ganglia UC Berkeley 发起的一个开源集群监视项目,设计用于测量数以千计的节点。 Ganglia 的核心包含 gmond gmetad 以及一个 Web 前端。主要是用来监控系统性能,如: cpu mem 、硬盘利用率、 I/O 负载、网络流量情况等,通过曲线很容易见到每个节点的工作状态,对合理调整、分配系统资源,提高系统整体性能起到重要作用。
2Ganglia进程介绍:
每台计算机都运行一个收集和发送度量数据的名为 gmond 的守护进程。接收所有度量数据的主机可以显示这些数据并且可以将这些数据的精简表单传递到层次结构中。正因为有这种层次结构模式,才使得 Ganglia 可以实现良好的扩展。 gmond 带来的系统负载非常少,这使得它成为在集群中各台计算机上运行的一段代码,而不会影响用户性能。所有这些数据多次收集会影响节点性能。网络中的抖动发生在大量小消息同时出现时,可以通过将节点时钟保持一致,来避免这个问题。
gmetad 可以部署在集群内任一台节点或者通过网络连接到集群的独立主机,它通过单播路由的方式与 gmond 通信,收集区域内节点的状态信息,并以 XML 数据的形式,保存在数据库中。
RRDTool 工具处理数据,并生成相应的的图形显示,以 Web 方式直观的提供给客户端。
3、安装配置ganglia的过程:
1 )安装前的准备工作
2 )安装服务器端
3 )客户端的安装
4 web 前端的安装
5 )安装成功后的测试工作
4、安装前的准备工作:
由于 ganglia 有许多依赖的软件,所以要事先安装一下,安装过程如下
 
# yum install –y gcc gcc-c++ libpng freetype zlib libdbi apr.* apr-util ibxml2-devel pkg-config glib pixman pango pango-devel freetye-devel fontconfig cairo cairo-devel libart_lgpl libart_lgpl-devel
5、服务器端的安装:
由于 ganglia 监控是通过 httpd 的,所以要先编译 httpd 服务,而且还要编译 php 支持 gd 模块,即: --with-gd
1httpd安装:
# cd /opt
# wget http://mirror.bit.edu.cn/apache/httpd/httpd-2.2.22.tar.gz
# tar -xvf httpd-2.2.22.tar.gz
# cd httpd-2.2.22
# ./configure --prefix=/usr/local/apache2 --sysconfdir=/etc/httpd --enable-so --enable-ssl --enable-cgi --enable-rewrite --with-zlib
# make && make install
编辑 httpd 的配置文件, /etc/httpd/httpd.conf ,添加如下行即可:
# vi /etc/httpd/httpd.conf
PidFile "/var/run/httpd.pid"
提供 httpd SysV 服务脚本 /etc/rc.d/init.d/httpd ,内容如下:
#!/bin/bash
# httpd Startup script for the Apache HTTP Server
# chkconfig: - 85 15
# description: Apache is a World Wide Web server. It is used to serve \
# HTML files and CGI.
# processname: httpd
# config: /etc/httpd/conf/httpd.conf
# config: /etc/sysconfig/httpd
# pidfile: /var/run/httpd.pid
# Source function library.
. /etc/rc.d/init.d/functions
if [ -f /etc/sysconfig/httpd ]; then
. /etc/sysconfig/httpd
fi
# Start httpd in the C locale by default.
HTTPD_LANG=${HTTPD_LANG-"C"}
# This will prevent initlog from swallowing up a pass-phrase prompt if
# mod_ssl needs a pass-phrase from the user.
INITLOG_ARGS=""
# Set HTTPD=/usr/sbin/httpd.worker in /etc/sysconfig/httpd to use a server
# with the thread-based "worker" MPM; BE WARNED that some modules may not
# work correctly with a thread-based MPM; notably PHP will refuse to start.
# Path to the apachectl script, server binary, and short-form for messages.
apachectl=/usr/local/apache2/bin/apachectl
httpd=${HTTPD-/usr/local/apache2/bin/httpd}
prog=httpd
pidfile=${PIDFILE-/var/run/httpd.pid}
lockfile=${LOCKFILE-/var/lock/subsys/httpd}
RETVAL=0
start() {
echo -n $"Starting $prog: "
LANG=$HTTPD_LANG daemon --pidfile=${pidfile} $httpd $OPTIONS
RETVAL=$?
echo
[ $RETVAL = 0 ] && touch ${lockfile}
return $RETVAL
}
stop() {
echo -n $"Stopping $prog: "
killproc -p ${pidfile} -d 10 $httpd
RETVAL=$?
echo
[ $RETVAL = 0 ] && rm -f ${lockfile} ${pidfile}
}
reload() {
echo -n $"Reloading $prog: "
if ! LANG=$HTTPD_LANG $httpd $OPTIONS -t >&/dev/null; then
RETVAL=$?
echo $"not reloading due to configuration syntax error"
failure $"not reloading $httpd due to configuration syntax error"
else
killproc -p ${pidfile} $httpd -HUP
RETVAL=$?
fi
echo
}
# See how we were called.
case "$1" in
start)
start
;;
stop)
stop
;;
status)
status -p ${pidfile} $httpd
RETVAL=$?
;;
restart)
stop
start
;;
condrestart)
if [ -f ${pidfile} ] ; then
stop
start
fi
;;
reload)
reload
;;
graceful|help|configtest|fullstatus)
$apachectl $@
RETVAL=$?
;;
*)
echo $"Usage: $prog {start|stop|restart|condrestart|reload|status|fullstatus|graceful|help|configtest}"
exit 1
esac
exit $RETVAL
 
而后为此脚本赋予执行权限:
# chmod +x /etc/rc.d/init.d/httpd
加入服务列表:
# chkconfig --add httpd
开机自动启动:
# chkconfig httpd on
接下来就可以启动服务进行测试了。
# service httpd start // 启动 httpd 服务
2)安装配置php
# cd /opt
# wget http://cn.php.net/distributions/php-5.3.15.tar.gz
# cd php-5.3.15
#./configure --prefix=/usr/local/php5 --with-mysql=/usr/local/mysql5 --with-apxs2=/usr/local/apache2/bin/apxs --with-config-file-path=/usr/local/php5/etc --with-gd
# make && make install
php 提供配置文件:
# cp php.ini-production /usr/local/php/etc/php.ini
编辑 apache 配置文件 httpd.conf ,使 apache 支持 php
# vim /etc/httpd/httpd.conf
   添加如下二行
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
   定位至 DirectoryIndex index.html
修改为:
DirectoryIndex index.php index.html
   测试 php 安装是否成功。
# cd /usr/local/apache2/htdocs
# mv index.html index.php
# vim index.php
<?php
phpinfo();
?>
保存退出后,将 httpd 服务重新启动: service httpd restart 或者 reload 让其重新载入配置文件即可测试 php 是否已经可以正常使用。
3)结合phpmysql
①重新编辑 /usr/local/apache/htdocs/index.php 文件,如下所示:
<?php
$link=mysql_connect('localhost','root',''); // mysql 数据库连接
if ($link)
echo "Successful!";
else
echo "Failure...";
mysql_close(); // 关闭数据库连接
?>
②而后重新启动 httpd ,并且重新启动 mysqld 服务。
这时输入 ip 地址查看信息。
 

        

4)安装配置 rrdtool
# cd /opt
#wget http://down1.chinaunix.net/distfiles/rrdtool-1.4.5.tar.gz
# tar xvf rrdtool-1.4.5.tar.gz
# cd rrdtool-1.4.5
# ./configure –prefix=/usr/local/rrdtool –enable-shared
# make && make install
rrdtool 的命令加入配置环境下:
# vi /etc/profile
export PATH=$PATH:/usr/local/rrdtool/bin
#source /etc/profile
5)安装配置其他所要依赖的包:
# yum install -y expat expat-devel pcre pcre-devel
# cd /opt
# wget http://mirror.bit.edu.cn/apache/apr/apr-1.4.6.tar.gz
#tar zxf apr-1.4.6.tar.gz
#cd apr-1.4.6
# ./configure;make;make install
#cd ..
# wget http://download.savannah.gnu.org/releases/confuse/confuse-2.7.tar.gz
# tar zxf confuse-2.7.tar.gz
# cd confuse-2.7
# ./configure CFLAGS=-fPIC --disable-nls ;make;make install
# cd ..
6Ganglia的安装
好了,终于要安装 ganglia 了,下面开始:
#wget http://nchc.dl.sourceforge.net/project/ganglia/ganglia%20monitoring%20core/3.4.0/ganglia-3.4.0.tar.gz
# tar zxf ganglia-3.4.0.tar.gz
# cd ganglia-3.4.0
# ./configure --prefix=/opt/modules/ganglia --with-static-modules --enable-gexec --enable-status --with-gmetad --with-python=/usr --with-librrd=/usr/local/rrdtool --with-libexpat=/usr --with-libconfuse=/usr/local --with-libpcre=/usr/local

       


# make && make install
# cd gmetad
# cp gmetad.conf /opt/modules/ganglia/etc/
# cp gmetad.init /etc/init.d/gmetad
打开 gmetad 的配置文件,修改如下内容:
# vi /etc/init.d/gmetad
GMETAD=/usr/bin/gmetad
  改为 GMETAD=/opt/modules/ganglia/sbin/gmetad
# chkconfig --add gmetad
# route add -host 239.2.11.71 dev eth0
# mkdir –p /var/lib/ganglia/rrds
# chown nobody:nobody /var/lib/ganglia/
#vi /opt/modules/ganglia/etc/gmetad.conf
data_source "ling" 10.100.10.10
在最后添加如下内容:
setuid_username "root"
rrd_rootdir "/usr/local/rrdtool"
说明:这里的 ”ling” 表示的是集群的名称,后面的内容是这个集群中所包含的主机信息,也就是要监控的主机 ip
# service gmetad start
# netstat –tnlp |grep gmetad
tcp        0      0 0.0.0.0:8651                0.0.0.0:*                   LISTEN      29583/gmetad       
tcp        0      0 0.0.0.0:8652                0.0.0.0:*                   LISTEN      29583/gmetad  
6、客户端的安装与配置:
1)准备工作:
# yum install –y gcc gcc-c++ libpng freetype zlib libdbi apr.* apr-util ibxml2-devel pkg-config glib pixman pango pango-devel freetye-devel fontconfig cairo cairo-devel libart_lgpl libart_lgpl-develexpat expat-devel pcre pcre-devel apr*
# cd /opt
# wget http://mirror.bit.edu.cn/apache/apr/apr-1.4.6.tar.gz
# tar zxf apr-1.4.6.tar.gz
# cd apr-1.4.6
# ./configure;make;make install
# cd ..
#wget http://download.savannah.gnu.org/releases/confuse/confuse-2.7.tar.gz
# tar zxf confuse-2.7.tar.gz
# cd confuse-2.7
# ./configure CFLAGS=-fPIC --disable-nls ;make;make install
# cd ..
2)安装配置 rrdtool
# cd /opt
# wget http://down1.chinaunix.net/distfiles/rrdtool-1.4.5.tar.gz
#  tar xvf rrdtool-1.4.5.tar.gz
# cd rrdtool-1.4.5
# ./configure  --prefix=/usr/local/rrdtool  --enable-shared
# make && make install
# vi /etc/profile
export PATH=$PATH:/usr/local/rrdtool/bin
#source /etc/profile
# cd ..
3)安装 ganglia
#wget http://nchc.dl.sourceforge.net/project/ganglia/ganglia%20monitoring%20core/3.4.0/ganglia-3.4.0.tar.gz
# tar zxf ganglia-3.4.0.tar.gz
# cd ganglia-3.4.0
# ./configure --prefix=/opt/modules/ganglia --enable-gexec --enable-status --with-python=/usr --with-libapr=/usr/local/apr/bin/apr-1-config --with-libconfuse=/usr/local --with-libexpat=/usr --with-libpcre=/usr
    

     


    # make && make install
# mkdir /opt/modules/ganglia/etc
#cd gmond
# ./gmond –t > /opt/modules/ganglia/etc/gmond.conf
# cp gmond.init /etc/init.d/gmond
    # vi /etc/init.d/gmond
GMETAD=/usr/bin/gmond
  改为 GMETAD=/opt/modules/ganglia/sbin/gmond
 
# chkconfig --add gmond
# route add -host 239.2.11.71 dev eth0
# service gmond start
 
7Web前端配置:
As of version 3.4.0, the web interface is a separate distribution tarballand maintained in a separate source code repository. Please download from http://ganglia.info
在服务器端进行:
# cd /opt
wget http://nchc.dl.sourceforge.net/project/ganglia/ganglia-web/3.5.2/
ganglia-web-3.5.2.tar.gz
# tar xvf ganglia-web-3.5.2.tar.gz
# cd ganglia-web-3.5.2
# vi conf.php
$conf['gmetad_root'] = "/var/lib/ganglia";
$conf['rrds'] = "${conf['gmetad_root']}/rrds";
$conf['rrdtool'] = "/usr/local/rrdtool/bin/rrdtool";
$conf['ganglia_ip'] = "127.0.0.1";
$conf['ganglia_port'] = 8652;
# vi Makefile
GDESTDIR = /var/www/html/ganglia
APACHE_USER = apache
改为
GDESTDIR = /usr/local/apache2/htdocs/ganglia
APACHE_USER = nobody
# make install
# service httpd restart
# service gmetad restart
如果打开浏览器,出现乱码的问题,查看 httpd 的错误日志,内容如下:
(process:3530): Pango-WARNING **: failed to choose a font, expect ugly output. engine-type='PangoRenderFc', script='latin'
 
(process:3531): Pango-WARNING **: failed to choose a font, expect ugly output. engine-type='PangoRenderFc', script='common'
 
(process:3531): Pango-WARNING **: failed to choose a font, expect ugly output. engine-type='PangoRenderFc', script='latin'
 
(process:3532): Pango-WARNING **: failed to choose a font, expect ugly output. engine-type='PangoRenderFc', script='common'
 
(process:3532): Pango-WARNING **: failed to choose a font, expect ugly output. engine-type='PangoRenderFc', script='latin'
 
(process:3536): Pango-WARNING **: failed to choose a font, expect ugly output. engine-type='PangoRenderFc', script='common'
 
(process:3536): Pango-WARNING **: failed to choose a font, expect ugly output. engine-type='PangoRenderFc', script='latin'
 
(process:3538): Pango-WARNING **: failed to choose a font, expect ugly output. engine-type='PangoRenderFc', script='common'
可能是 apache 不支持字体的原因,解决问题的方法是安装 liberation-fonts-ttf
# yum list all |grep liberation
# yum install –y liberation*
此时,打开 http://10.100.10.12/ganglia ,查看 web 界面:
 

8、用ganglia监控mysql数据库
在网上搜索了一下,发现了一个监控 mysql 的脚本,就下载下来试一试,感觉结果不是很满意,不过可以借鉴一下:
   在被监控的机器上( 10.100.10.10
# vim gmetric-mysql.sh
 
#! /bin/bash
# Config
declare -r GMETRIC=/opt/ganglia-3.4.0/gmetric/gmetric
declare -r NEW_DATA_FILE=/tmp/mysql-stats.new
declare -r OLD_DATA_FILE=/tmp/mysql-stats.old
declare -r MYSQL_USER="root"    /* 连接mysql 数据库的用户和密码*/
declare -r MYSQL_PASSWORD=""
# Sanity checks
if test -z "$GMETRIC" ; then
    printf "The command $GMETRIC is not available";
    exit 192
fi
# Function for submiting metrics
function record_value {
    if [ $# -lt 1 ]; then
        printf "You must specify a look-up value\n"
        exit 192
    fi
    LOOKUP_VAR=$1
     GANGLIA_NAME=${2-unspecified}
    GANGLIA_TYPE=${3-float}
    GANGLIA_UNITS=${4-units}
    GANGLIA_VALUE=`grep "$LOOKUP_VAR[^_]" "$NEW_DATA_FILE" | awk '{print $2}'`
    printf " * $GANGLIA_NAME: $GANGLIA_VALUE\n"
}
# Function for submitting delta metrics
function record_value_rate {
    if [ $# -lt 1 ]; then
        printf "You must specify a look-up value\n"
        exit 192
    fi
    MYSQL_VAR=$1
    GANGLIA_NAME=${2-unspecified}
    GANGLIA_TYPE=${3-float}
    GANGLIA_UNITS=${4-"per second"}
    # Get values from old and new files
    PREVIOUS_VALUE=`grep "$MYSQL_VAR[^_]" "$OLD_DATA_FILE" | awk '{print $2}'`
    NEW_VALUE=`grep "$MYSQL_VAR[^_]" "$NEW_DATA_FILE" | awk '{print $2}'`
    DELTA_VALUE=$(( $NEW_VALUE-$PREVIOUS_VALUE ))
    PREVIOUS_TIMESTAMP=`date -r "$OLD_DATA_FILE" +%s`
    NEW_TIMESTAMP=`date -r "$NEW_DATA_FILE" +%s`
    DELTA_TIMESTAMP=$(( $NEW_TIMESTAMP-$PREVIOUS_TIMESTAMP ))
    if [ $DELTA_VALUE -lt 0 ] || [ $DELTA_TIMESTAMP -lt 0 ]; then
        # Something strange here - MYSQL may just have started. Ignore for now
        printf "Weird data value - skipping\n"
    else
        # Need to pipe to bc to perform floating point operations
        DELTA_RATE=`echo "scale=4; $DELTA_VALUE/$DELTA_TIMESTAMP" | bc -l`
        printf " * $GANGLIA_NAME -- Previous value: $PREVIOUS_VALUE, new value: $NEW_VALUE, delta: $DELTA_VALUE, previous timestamp: $PREVIOUS_TIMESTAMP, new timestamp: $NEW_TIMESTAMP, delta: $DELTA_TIMESTAMP, $DELTA_RATE per second\n"
        $GMETRIC --type "$GANGLIA_TYPE" --name "$GANGLIA_NAME" --value $DELTA_VALUE --unit "$GANGLIA_UNITS"
    fi
}
# Read MySQL statistics into a temporary file
mysql --user=$MYSQL_USER --password=$MYSQL_PASSWORD --execute "SHOW GLOBAL STATUS" > "$NEW_DATA_FILE"
# Submit metrics
record_value_rate "Connections" "MYSQL_CONNECTIONS" "float" "Connections/sec"
record_value_rate "Com_update" "MYSQL_UPDATE_QUERIES" "float" "Queries/sec"
record_value_rate "Com_select" "MYSQL_SELECT_QUERIES" "float" "Queries/sec"
record_value_rate "Com_insert" "MYSQL_INSERT_QUERIES" "float" "Queries/sec"
record_value_rate "Com_delete" "MYSQL_DELETE_QUERIES" "float" "Queries/sec"
record_value_rate "Created_tmp_tables" "MYSQL_CREATED_TMP_TABLES" "float" "Tables created/sec"
record_value_rate "Slow_queries" "MYSQL_SLOW_QUERIES" "float" "Queries/sec"
record_value_rate "Qcache_hits" "MYSQL_QUERY_CACHE_HITS" "float" "Hits/sec"
record_value "Qcache_queries_in_cache" "MYSQL_QUERIES_IN_CACHE" "float" "Queries"
record_value_rate "Questions" "MYSQL_QUESTIONS" "float" "Questions/sec"
record_value_rate "Threads_connected" "MYSQL_THREADS_CONNECTED" "float" "Threads connected/sec"
record_value "Threads_running" "MYSQL_THREADS_RUNNING" "float" "Threads running"
# Copy data
cp "$NEW_DATA_FILE" "$OLD_DATA_FILE"
   #chmod +x gmetric-mysql.sh
   crond 执行此脚本:
crontab –e
* * * * * /root/gmetric-mysql.sh > /dev/null 2>&1  
重启 gmetad 服务( 10.100.10.12
# service gmetad restart
此时打开浏览器,查看 mysql 的各种状态:
 

 

你可能感兴趣的:(mysql,rrdtool,ganglia)