HAproxyKeepalived一键安装脚本

#!/bin/bash
##################################
haproxy_path=/usr/local/haproxy
haproxy_conf=/usr/local/haproxy/conf/haproxy.cfg
#############haproxy-install#####################
cd /tmp
tar xvf haproxy-1.4.*.tar.gz
if [ $? -eq 0 ];then
echo "haproxy tar ok"
else
echo "haproxy tar no"
exit
fi
sleep 5
yum install gcc openssl openssl-devel make kernel-devel popt-devel openssl -y
cd /tmp/haproxy-*
make TARGET=linux26 PREFIX=$haproxy_path install
if [ $? -eq 0 ];then
echo "haproxy install ok"
else
echo "haproxy install no"
exit
fi
cd $haproxy_path
mkdir conf logs
touch $haproxy_path/conf/haproxy.cfg
#################haproxy.cfg#########################
echo -e "global\n\tlog 127.0.0.1 local0\n\tmaxconn 65535\n\tchroot $haproxy_path\n\tuser nobody\n\tgroup nobody\n\tdaemon\n\tnbproc 8\n\tpidfile $haproxy_path/haproxy.pid\n" > $haproxy_conf
echo -e "\ndefaults\n\tlog 127.0.0.1 local3\n\tmode http\n\toption httplog\n\toption dontlognull\n\toption redispatch\n\tretries 2\n\tmaxconn 2000\n\tcontimeout 5000\n\tclitimeout 50000\n\tsrvtimeout 50000" >> $haproxy_conf
echo -e "\nlisten web 0.0.0.0:80\n\tmode http\n\tbalance roundrobin\n\tcookie SERVERID insert indirect nocache\n\toption httplog\n\tlog global\n\toption httpchk HEAD /index.html HTTP/1.0" >> $haproxy_conf
read -p "Requires several server " server
for ((i=1;i<=$server;i++))
do
read -p "server ip " ip
echo -e "server server$i $ip:80 cookie $i check inter 2000 rise 2 fall 5" >> $haproxy_conf
done
###########################keepalived###############################
mandir=/usr/local/src/man
kernel=$(uname -r)
keepalived_conf=/etc/keepalived/keepalived.conf
################################
cd /tmp
tar -xvf keepalived*.tar.gz
cd /tmp/keepalived-*
#############keepalived make##################
./configure --prefix=/ --mandir=$mandir --with-kernel-dir=/usr/src/kernels/$kernel*
if [ $? -eq 0 ];then
make
if [ $? -eq 0 ];then
make install
if [ $? -eq 0 ];then
echo "keepalived ok"
else
echo "keepalived no"
exit
fi
else
echo "keeplaived make no"
exit
fi
else
echo "keelalived make no"
fi

touch /etc/keepalived/keepalived.conf
########################################################
read -p "$read_p NIC binding " network
####################keepalived.conf#####################
#############Global configuration#######################
echo -e " ! Configuration File for keepalived\nglobal_defs {\n\tnotification_email {\n\[email protected]\n\t}\n\tnotification_email_from [email protected]\n\tsmtp_server 127.0.0.1\n\tsmtp_connect_timeout 30\n\trouter_id HAproxy\n}" > $keepalived_conf
############Virtual IP Configuration####################
read -p "Requires several server " server
for ((a=1;a<=$server;a++))
do
read -p "$read_p MASTER of BACKUP " states
read -p "$read_p priority " priority
read -p "$read_p vip address " vip
echo -e "vrrp_instance VI_$a {\n\tstate $states\n\tinterface $network\n\tvirtual_router_id 52\n\t priority $priority\n\tadvert_int 1\n\tauthentication {\n\tauth_type PASS\n\tauth_pass tdoa\n\t}\n\tvirtual_ipaddress {\n\t$vip/24 dev $network\n\t}\n}" >> $keepalived_conf
done
#######################################################
/usr/local/haproxy/sbin/haproxy -f $haproxy_conf
/etc/rc.d/init.d/keepalived restart
#########################haproxy-keepalived.sh##############################
touch /etc/rc.d/haproxy-keepalived.sh
echo -e '#!/bin/bash\nwhile\t:\ndo\n haproxypid=`ps -C haproxy --no-header | wc -l`\n\tif [ $haproxypid -eq 0 ];then\n\t\t/usr/local/haproxy/sbin/haproxy -f /usr/local/haproxy/conf/haproxy.cfg\n\t\tsleep 5\n\thapropid=`ps -C haproxy --no-header | wc -l`\n\t\tif [ $hapropid -eq 0 ];then\n\t\t\t\t/etc/init.d/keepalived stop\n\t\tfi\n\tfi\n\tsleep 5\n proxypid=`ps -C haproxy --no-header | wc -l`\n\tif (($proxypid!= 0));then\n\t\t/etc/init.d/keepalived start\n\tfi\n\tsleep 5\ndone' > /etc/rc.d/haproxy.sh
#############################################################################
chmod +x /etc/rc.d/haproxy.sh
/usr/bin/nohup /etc/rc.d/haproxy.sh &
rc_local=/etc/rc.local
echo '/usr/local/haproxy/sbin/haproxy -f /usr/local/haproxy/conf/haproxy.cfg' >> $rc_local
echo '/etc/rc.d/init.d/keepalived start' >> $rc_local
echo '/usr/bin/nohup /etc/rc.d/haproxy.sh &' >> $rc_local
############################################################################

本文出自 “此身 此时 此地” 博客,请务必保留此出处http://jqbash.blog.51cto.com/7172316/1315722

更多相关文章
  • win10激活工具一键激活方法2则大家可以来了解一下,今日小编还将提供win10一键激活工具下载,下文提到的两种方法都是免费的哦 win10激活工具一键激活方法2则大家可以来了解一下,今日小编还将提供win10一键激活工具下载,下文提到的两种方法都是免费的哦. 法一.KMSpico 软件名称:win ...
  •  Lolipop源码已经放出有些日子了,我发现google在Android 5.0上修复了一个高危漏洞,利用该漏洞可以发送任意广播:不仅可以发送系统保护级别的广播.还可以无视receiver的android:exported=false.android:permisson=XXX 属性的限制. 简直 ...
  • http://www.lintcode.com/en/problem/longest-increasing-continuous-subsequence-ii/# Give you an integer matrix (with row size n, column size m),find the ...
  • 嘿嘿, 逗比们好,今天我们来做一个android上的标签云效果,额, 虽然还不是 很完美,但是已经足够可以展现标签云的效果了,首先来看看效果吧. 额, 录屏只能录到这个份上了,凑活着看吧.今天我们就来实现一下这个效果, 这次我选择直接继承view来, 什么? 这样的效果不是SurfaceView擅长 ...
  • 昨天我们已经报道过诺基亚将会发布自家首款WP8机型Lumia 920和Lumia 820,而最新消息则指除了这两款中高端机型,诺基亚还将推出一款低端WP8的机型,代号为"Zeal".今晚诺基亚将联合微软一起召开发布会,而这次发布会的主题无疑是公布诺基亚自家的WP8手机. Lumi ...
  • 在一些设计上,设计师会要求我们的文字以45度显示,或者135度显示(如下图"抽奖"),可是android本身并没有提供TextView在布局文件中实现旋转的标签,这时候就需要我们去自定义TextView,并且重写onDraw()方法实现效果. 下面,让我们去实现这个效果吧. 首先 ...
一周排行
  • 欧拉回路 Time Limit: 2/1 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 10548 ...
  • 易网科技讯 8月9日消息,摩根斯坦利6日发布报告称,前程无忧在第二季度收入超出预期,并指出该公司目前的估值偏低,其股价有25%的上升空间,并给予其增持评级. 以下是报告全文: 收益实现新高:第二季度销售收入同比增长3 ...
  • sudo apt-get install sendemail -y #注意是sendemail 不是sendmail /usr/bin/printf "***** test1 *****\n Type&qu ...
  • 改革春风吹满地 Time Limit: 2/1 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 22 ...
  • org.apache.commons.io.FileUtils快速读写文件   String fileName = "C://11.txt";   File file = new File(fil ...
  • 今天小编为大家带来了天涯明月刀端午节活动有什么奖励 端午节活动奖励介绍,感兴趣的朋友们可以跟着小编去下文了解一下哦 今天小编为大家带来了天涯明月刀端午节活动有什么奖励 端午节活动奖励介绍,感兴趣的朋友们可以跟着小编去 ...
  • 关于Button按钮的四种事件监听方法总结 首先我们在activity_main.xml里面先定义一个Button空间 <RelativeLayout xmlns:android="http://sc ...
  • //获取DPI function js_getDPI() { var arrDPI = new Array(); if ( window.screen.deviceXDPI != undefined ) { arrD ...
  • 网友号召"抵制家乐福"一事,并没有因为家乐福的公开声明而就此结束,昨天(17日)也随着家乐福官方网站一度被"黑"而呈现出升级态势.据记者现场观察,年轻人仍是抵制主力,低价商品还 ...
  • time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard outpu ...