简单化的ganglia安装脚本
支持rhel5.x (centos5.x)和rhel6.x:
#!/bin/bash
function UsageHelp()
{
echo
echo “Usage: $1 [-h][<[server][client]>]”
echo “example: $1 server”
echo
echo “Install ganglia to host.”
echo
echo “-h: Show help information.”
echo “server: Install server to host.”
echo “client: Install client to host.”
echo
}
if [ $# -gt 1 ] ; then
UsageHelp $0
exit 0
fi
if [ $# -lt 1 ] ; then
UsageHelp $0
exit 0
fi
type=$1
if [ “$type” != “server” ] ; then
if [ “$type” != “client” ] ; then
UsageHelp $0
exit 0
fi
fi
#################### GCC ######################################
yesOrNo=”y”
read -t 5 -p ” ===> gcc installed? (y/n, default is ‘y’) ” yesOrNo
if [ $? -ne 0 ] ; then
yesOrNo=”y”
fi
if [ “$yesOrNo” == “” ] ; then
yesOrNo=”y”
fi
if [ “$yesOrNo” == “n” ] ; then
echo “ERROR: gcc isn’t installed.”
exit -1
fi
#################### X11 ######################################
if [ “$type” == “server” ] ; then
yesOrNo=”y”
read -t 5 -p ” ===> X11 installed? (y/n, default is ‘y’) ” yesOrNo
if [ $? -ne 0 ] ; then
yesOrNo=”y”
fi
if [ “$yesOrNo” == “” ] ; then
yesOrNo=”y”
fi
if [ “$yesOrNo” == “n” ] ; then
echo “ERROR: X11 isn’t installed.”
exit -1
fi
fi
sleep 2
#################### APR ######################################
echo “Install APR ==========================================>”
if [ ! -f “/usr/local/apr/bin/apr-1-config” ] ; then
if [ -f “apr-1.4.5.tar.gz” ] ; then
set -x
tar -zxvf apr-1.4.5.tar.gz
cd apr-1.4.5
./configure
make clean
make
make install
cd ..
set +x
else
echo “ERROR: apr-1.4.5.tar.gz doesn’t exist.”
cd ..
exit -1
fi
sleep 5
fi
#################### APR-UTIL ######################################
echo “Install APR-UTIL ==========================================>”
if [ ! -f “/usr/local/apr/bin/apu-1-config” ] ; then
if [ -f “apr-util-1.3.12.tar.gz” ] ; then
set -x
tar -zxvf apr-util-1.3.12.tar.gz
cd apr-util-1.3.12
./configure –with-apr=/usr/local/apr/bin/apr-1-config
make clean
make
make install
cd ..
set +x
else
echo “ERROR: apr-util-1.3.12.tar.gz doesn’t exist.”
cd ..
exit -1
fi
sleep 5
fi
#################### CONFUSE ######################################
echo “Install CONFUSE ==========================================>”
if [ ! -f “/usr/local/include/confuse.h” ] ; then
if [ -f “confuse-2.7.tar.gz” ] ; then
set -x
tar -zxvf confuse-2.7.tar.gz
cd confuse-2.7
./configure –with-pic
make clean
make
make install
cd ..
set +x
else
echo “ERROR: confuse-2.7.tar.gz doesn’t exist.”
cd ..
exit -1
fi
sleep 5
fi
#################### EXPAT ######################################
echo “Install EXPAT ==========================================>”
if [ ! -f “/usr/local/include/expat.h” ] ; then
if [ -f “expat-2.0.1.tar.gz” ] ; then
set -x
tar -zxvf expat-2.0.1.tar.gz
cd expat-2.0.1
./configure
make clean
make
make install
cd ..
set +x
else
echo “ERROR: expat-2.0.1.tar.gz doesn’t exist.”
cd ..
exit -1
fi
sleep 5
fi
#################### XML-PARSER ######################################
echo “Install XML-PARSER ==========================================>”
if [ ! -d “/usr/local/lib64/perl5/XML/Parser” ] ; then
if [ ! -d “/usr/lib64/perl5/site_perl/5.8.8/x86_64-linux-thread-multi/auto/XML/Parser” ] ; then
if [ -f “XML-Parser-2.41.tar.gz” ] ; then
set -x
tar -zxvf XML-Parser-2.41.tar.gz
cd XML-Parser-2.41
perl Makefile.PL
make
make install
cd ..
set +x
else
echo “ERROR: XML-Parser-2.41.tar.gz doesn’t exist.”
cd ..
exit -1
fi
sleep 5
fi
fi
#################### INTLTOOL ######################################
echo “Install INTLTOOL ==========================================>”
if [ ! -f “/usr/local/bin/intltoolize” ] ; then
if [ -f “intltool-0.40.6.tar.gz” ] ; then
set -x
tar -zxvf intltool-0.40.6.tar.gz
cd intltool-0.40.6
./configure
make clean
make
make install
cd ..
set +x
else
echo “ERROR: intltool-0.40.6.tar.gz doesn’t exist.”
cd ..
exit -1
fi
sleep 5
fi
#################### RRDTOOL ######################################
if [ “$type” == “server” ] ; then
echo “Install RRDTOOL ==========================================>”
if [ ! -f “/usr/bin/rrdtool” ] ; then
if [ -f “rrdtool-1.4.5.tar.gz” ] ; then
set -x
tar -zxvf rrdtool-1.4.5.tar.gz
cd rrdtool-1.4.5
./configure –prefix=/usr/
make clean
make
make install
which rrdtool
ldconfig
cd ..
set +x
else
echo “ERROR: rrdtool-1.4.5.tar.gz doesn’t exist.”
cd ..
exit -1
fi
sleep 5
fi
fi
#################### PCRE ######################################
echo “Install PCRE ==========================================>”
if [ ! -f “/usr/local/bin/pcregrep” ] ; then
if [ -f “pcre-8.12.tar.gz” ] ; then
set -x
tar -zxvf pcre-8.12.tar.gz
cd pcre-8.12
./configure
make clean
make
make install
cd ..
set +x
else
echo “ERROR: pcre-8.12.tar.gz doesn’t exist.”
cd ..
exit -1
fi
sleep 5
fi
#################### PYTHON ######################################
echo “Install PYTHON ==========================================>”
if [ ! -f “/usr/local/python/lib/libpython2.7.so” ] ; then
if [ -f “Python-2.7.2.tgz” ] ; then
set -x
rm -f /usr/local/lib/libpython2.7.a
tar -zxvf Python-2.7.2.tgz
cd Python-2.7.2
./configure –enable-shared –prefix=/usr/local/python
make clean
make
make install
echo /usr/local/python/lib > /etc/ld.so.conf.d/libpython.conf
ldconfig
ldconfig -p|grep libpython
ldconfig -v|grep libpython
sed -i “s/PATH=/PATH=\/usr\/local\/python\/bin:/” ~/.bash_profile
. ~/.bash_profile
rm -f /usr/local/lib/libpython2.7.a
cp libpython2.7.a /usr/lib/
cd ..
set +x
else
echo “ERROR: Python-2.7.2.tgz doesn’t exist.”
cd ..
exit -1
fi
sleep 5
fi
#################### GANGLIA ######################################
echo “Install GANGLIA ==========================================>”
if [ ! -f “/usr/bin/ganglia-config” ] ; then
if [ -f “ganglia-3.1.7.tar.gz” ] ; then
set -x
service gmetad stop
service gmond stop
rm -rf /var/lib/ganglia/rrds/*
tar -zxvf ganglia-3.1.7.tar.gz
cd ganglia-3.1.7
if [ “$type” == “server” ] ; then
./configure –with-gmetad –enable-gexec –with-libapr=/usr/local/apr/bin/apr-1-config –sysconfdir=/etc/ganglia –with-python=/usr/local/python
else
./configure –with-libapr=/usr/local/apr/bin/apr-1-config –sysconfdir=/etc/ganglia –with-python=/usr/local/python
fi
make clean
sed -i ‘s/LIBS =/LIBS = -lm -lutil /’ gmond/modules/python/Makefile
make
make install
mkdir /etc/ganglia
if [ “$type” == “server” ] ; then
cd gmetad
cp gmetad.init /etc/rc.d/init.d/gmetad
cp gmetad.conf /etc/ganglia/gmetad.conf
chkconfig –add gmetad
chkconfig –list | grep gmetad
mkdir -p /var/lib/ganglia/rrds
chown nobody:nobody /var/lib/ganglia/rrds
sed -i “s/data_source \”my cluster\” localhost/data_source \”CLOUD\” 10 localhost/” /etc/ganglia/gmetad.conf
sed -i “s/# gridname \”MyGrid\”/gridname \”Hanborq\”/” /etc/ganglia/gmetad.conf
service gmetad start
sleep 1
telnet localhost 8651 | grep “HOST NAME”
cd ..
fi
cd gmond
gmond -t > /etc/ganglia/gmond.conf
cp gmond.init /etc/rc.d/init.d/gmond
chkconfig –add gmond
chkconfig –list gmond | grep gmond
sed -i “s/user = nobody/user = root/” /etc/ganglia/gmond.conf
sed -i “s/name = \”unspecified\”/name = \”CLOUD\”/” /etc/ganglia/gmond.conf
service gmond start
sleep 1
telnet localhost 8649
cd ..
cd ..
set +x
else
echo “ERROR: ganglia-3.1.7.tar.gz doesn’t exist.”
cd ..
exit -1
fi
sleep 5
fi
if [ “$type” == “server” ] ; then
#################### OPENSSL ######################################
echo “Install OPENSSL ==========================================>”
if [ ! -f “/usr/local/ssl/lib/libcrypto.so” ] ; then
if [ -f “openssl-1.0.0d.tar.gz” ] ; then
set -x
tar -zxvf openssl-1.0.0d.tar.gz
cd openssl-1.0.0d
./config -fPIC enable-shared
make clean
make
make install
echo /usr/local/ssl/lib > /etc/ld.so.conf.d/libssl.conf
ldconfig
ldconfig -p|grep libssl
ldconfig -v|grep libssl
cd ..
set +x
else
echo “ERROR: openssl-1.0.0d.tar.gz doesn’t exist.”
cd ..
exit -1
fi
sleep 5
fi
#################### APACHE ######################################
echo “Install APACHE ==========================================>”
if [ ! -f “/usr/local/httpd/bin/httpd” ] ; then
if [ -f “httpd-2.2.19.tar.gz” ] ; then
set -x
tar -zxvf httpd-2.2.19.tar.gz
cd httpd-2.2.19
./configure –prefix=/usr/local/httpd –with-apr=/usr/local/apr/bin/apr-1-config –with-apr-util=/usr/local/apr/bin/apu-1-config –with-ssl=/usr/local/ssl –enable-modules=so –enable-dav –enable-ssl –enable-maintainer-mode –enable-rewrite
make clean
make
make install
sed -i ‘/# LoadModule foo_module/a\LoadModule php5_module modules/libphp5.so\nAddType application/x-httpd-php .php .php4 .php3 .phtml\nAddType application/x-httpd-php-source .phps’ /usr/local/httpd/conf/httpd.conf
sed -i “s/DirectoryIndex index.html/DirectoryIndex index.html index.php/” /usr/local/httpd/conf/httpd.conf
cd ..
set +x
else
echo “ERROR: httpd-2.2.19.tar.gz doesn’t exist.”
cd ..
exit -1
fi
sleep 5
fi
#################### PHP ######################################
echo “Install PHP ==========================================>”
if [ ! -f “/usr/local/php/bin/php” ] ; then
if [ -f “php-5.3.6.tar.gz” ] ; then
set -x
tar -zxvf php-5.3.6.tar.gz
cd php-5.3.6
./configure –prefix=/usr/local/php –with-config-file-path=/usr/local/php –with-apxs2=/usr/local/httpd/bin/apxs –with-openssl=/usr/local/ssl
make clean
make
make install
cp php.ini-production /usr/local/php/php.ini
sed -i “s/;date.timezone =/date.timezone = PRC/” /usr/local/php/php.ini
cp libs/libphp5.so /usr/local/httpd/modules/
cd ..
set +x
else
echo “ERROR: php-5.3.6.tar.gz doesn’t exist.”
cd ..
exit -1
fi
sleep 5
fi
#################### Ganglia WEB ######################################
echo “Install Ganglia WEB ==========================================>”
set -x
cd ganglia-3.1.7
mkdir /usr/local/httpd/htdocs/ganglia
cp -a web/* /usr/local/httpd/htdocs/ganglia/
cd ..
set +x
#################### START APACHE ######################################
echo “Start APACHE ==========================================>”
set -x
/usr/local/httpd/bin/apachectl stop
sleep 3
/usr/local/httpd/bin/apachectl start
set +x
fi
#################### SELF Ganglia_io.py ######################################
echo “Install SELF Ganglia_io.py ==========================================>”
set -x
mkdir /usr/lib64/ganglia/python_modules
\cp -f ganglia_io.py /usr/lib64/ganglia/python_modules/
\cp -f ganglia_hadoop_proc.py /usr/lib64/ganglia/python_modules/
\cp -f ganglia_hbase_proc.py /usr/lib64/ganglia/python_modules/
\cp -f ganglia_onest_proc.py /usr/lib64/ganglia/python_modules/
mkdir /etc/ganglia/conf.d
\cp -f ganglia_io.pyconf /etc/ganglia/conf.d/
\cp -f ganglia_hadoop_proc.pyconf /etc/ganglia/conf.d/
\cp -f ganglia_hbase_proc.pyconf /etc/ganglia/conf.d/
\cp -f ganglia_onest_proc.pyconf /etc/ganglia/conf.d/
service gmond stop
sleep 3
service gmond start
set +x
echo “>>>>>>>>>>>>>>>>>> Ganglia Installing Finished <<<<<<<<<<<<<<<<<<<<<<<<“