在 CentOS上安裝配置 Ganglia-3.4.0

CentOS上安裝配置 Ganglia-3.4.0

1Ganglia簡介:
GangliaUC Berkeley發起的一個開源集羣監視項目,設計用於測量數以千計的節點。Ganglia的核心包含gmondgmetad以及一個Web前端。主要是用來監控系統性能,如:cpu mem、硬盤利用率、 I/O負載、網絡流量情況等,通過曲線很容易見到每個節點的工作狀態,對合理調整、分配系統資源,提高系統整體性能起到重要作用。
2Ganglia進程介紹:
每臺計算機都運行一個收集和發送度量數據的名爲 gmond 的守護進程。接收所有度量數據的主機可以顯示這些數據並且可以將這些數據的精簡表單傳遞到層次結構中。正因爲有這種層次結構模式,才使得 Ganglia 可以實現良好的擴展。gmond 帶來的系統負載非常少,這使得它成爲在集羣中各臺計算機上運行的一段代碼,而不會影響用戶性能。所有這些數據多次收集會影響節點性能。網絡中的抖動發生在大量小消息同時出現時,可以通過將節點時鐘保持一致,來避免這個問題。
gmetad可以部署在集羣內任一臺節點或者通過網絡連接到集羣的獨立主機,它通過單播路由的方式與gmond通信,收集區域內節點的狀態信息,並以XML數據的形式,保存在數據庫中。
RRDTool工具處理數據,並生成相應的的圖形顯示,以Web方式直觀的提供給客戶端。
3、安裝配置ganglia的過程:
1)安裝前的準備工作
2)安裝服務器端
3)客戶端的安裝
4web前端的安裝
5)安裝成功後的測試工作
4、安裝前的準備工作:
由於ganglia有許多依賴的軟件,所以要事先安裝一下,安裝過程如下
5、服務器端的安裝:
由於ganglia監控是通過httpd的,所以要先編譯httpd服務,而且還要編譯php支持gd模塊,即:--with-gd
1httpd安裝:
# cd /opt
# 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
# 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了,下面開始:
# 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
#  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 ..
# 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
# 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
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*
 

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的各種狀態:
 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章