西数超哥博客
运维经验教程分享的博客

【原创】centos下自动安装lvs调度器shell脚本

#!/bin/bash
#Auto install  director of LVS
#author  swh
echo "Now system  will  install Director of LVS, please wait:"
rpm  -qa  | grep  ipvsadm
ret=$?
if [ $ret -eq 0 ]
	then
	echo  "ipvsadm has be installed,now next step: "
		elif [ $ret -ne 0 ]
		then
		echo "ipvsadm not installed,now installing:"
		yum  -y install  ipvsadm
	else
	echo "error,please check"
fi
kernel_dir="/usr/src/kernels/`uname -r`/"
ln  -s $kernel_dir  /usr/src/linux
echo  -e " kerneldie is :\n$kernel_dir"
mkdir  /home/keepalived
yum  -y install  gcc gcc-c++  openssl openssl-devel
yum  -y install gcc make openssl-devel openssl net-snmp net-snmp-devel popt popt-devel
echo "Now install keepalived:"
wget -c http://www.keepalived.org/software/keepalived-1.2.19.tar.gz
tar zxvf keepalived-1.2.19.tar.gz
cd keepalived-1.2.19
./configure  --prefix=/home/keepalived  --with-kernel-dir=$kernel_dir
make
make install
cd ..
chkconfig  keepalived on
service keepalived start
service keepalived status

ret=$?
if [ $ret -eq 0 ]
then
	cp /home/keepalived/etc/rc.d/init.d/keepalived /etc/rc.d/init.d/
	cp /home/keepalived/etc/sysconfig/keepalived /etc/sysconfig/
	mkdir /etc/keepalived
	ln -s /home/keepalived/etc/keepalived/keepalived.conf /etc/keepalived/
	ln -s /home/keepalived/sbin/keepalived /usr/sbin/
	echo  "config keepalived vip and  rip:";
        sed -i '14,$d' /etc/keepalived/keepalived.conf
	echo "`pwd`"
        vip=`cat vip.ip`;	echo "VIP is $vip"
        sed  's/vipaddress/'$vip'/g' vipinstance.conf  >>/etc/keepalived/keepalived.conf
        cat rip.ip |while read rip
        do
        sed 's/ripserver/'$rip'/g' ripserver.conf >>/etc/keepalived/keepalived.conf
        done
        echo  "}" >> /etc/keepalived/keepalived.conf
	echo -e "RIP is :\n `cat  rip.ip`"
	chkconfig  keepalived  on
	service  keepalived start
	ret=$?
	if [ $ret -eq 0 ]
		then
		echo "keepalived install success."
	else
		echo "keepalived install failed"
	fi
else
	echo "keepalived install failed,please check."
fi

下载以后解压执行sh lvsDirector.sh即可 。 注意该脚本基于DR模式,测试平台在centos 6.5 上边。经测试不适合于centos 7安装配置。
swhlvs

转载请注明:西数超哥博客www.ysidc.top» 【原创】centos下自动安装lvs调度器shell脚本

https://www.ysidc.top 西数超哥博客,数据库,西数超哥,虚拟主机,域名注册,域名,云服务器,云主机,云建站,ysidc.top

赞(0) 打赏
声明:本站发布的内容(图片、视频和文字)以原创、转载和分享网络内容为主,若涉及侵权请及时告知,将会在第一时间删除。本站原创内容未经允许不得转载:西数超哥 » 【原创】centos下自动安装lvs调度器shell脚本

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏