#!/bin/bash

#

#

#this is for install keepalived bash

#

#

check_network()

{

ping www.baidu.com -c 5 >/dev/null 2>&1

ret=$?

if [ $ret -ne 0 ]; then

return $ret;

else

    echo "network is ok!"

fi

}

check_build()

{

yum install gcc gcc-c++ autoconf automake wget openssl-devel kernel-devel popt-devel -y

rpm -qa gcc gcc-c++ autoconf automake wget openssl-devel kernel-devel popt-devel

echo "The necessary components is ok!!!"

}

wget_install_keepalived()

{

keepalived_dir=/usr/local/keepalived

tar_dir=/usr/src

kernel=$(uname -r)

cd

ls keepalived-*.tar.gz

        ret=$?

        if [ $ret -ne 0 ];then

       wget http://www.keepalived.org/software/keepalived-1.1.20.tar.gz

        else

return $ret;

fi

tar -zxf keepalived-*.tar.gz -C $tar_dir

cd /usr/src/keepalived-*

./configure --prefix=$keepalived_dir --sysconf=/etc --with-kernel-dir=/usr/src/kernels/$kernel*

make && make install

if [ $? -eq 0 ];then

echo "keepalived install is ok!!!"

else

echo "keepalived install is no!!!"

            exit

        fi

}

check_network

check_build

wget_install_keepalived

echo "last configure"

cp /usr/local/keepalived/sbin/keepalived /usr/sbin

echo "cp /usr/local/keepalived/sbin/keepalived /usr/sbin"

echo "/etc/init.d/keepalived restart"

/etc/init.d/keepalived restart