标签:div configure bsp down zip zlib gre keepaliv 输入
#/bin/bash
read -ep "请输入keepalived所在的本地IP:" IPread -ep "请输入另一台keepalived所在的本地IP:" IP2read -ep "请输入你创建的keepalived的VIP:" netread -ep "请输入ngixn负载的IP:" furead -ep "请输入ngixn负载的另一条IP:" fu2read -ep "是否终止(y),默认不终止" ynif [ $yn == y ];then exitfiyum -y install keepalivedsed -i ‘/notification_email {/,/smtp_connect_timeout 30/d‘ /etc/keepalived/keepalived.confsed -i ‘/vrrp_skip_check_adv_addr/,/vrrp_gna_interval 0/d‘ /etc/keepalived/keepalived.confsed -i ‘s/eth0/ens33/‘ /etc/keepalived/keepalived.confsed -i ‘/persistence_timeout 50/d‘ /etc/keepalived/keepalived.confsed -i ‘/real_server/,$d‘ /etc/keepalived/keepalived.confsed -i ‘/192.168.200.16/,/192.168.200.17/d‘ /etc/keepalived/keepalived.confsed -i "s/192.168.200.18/$net/" /etc/keepalived/keepalived.confsed -i "s/192.168.200.100 443/$net 80/" /etc/keepalived/keepalived.confchmod +x /etc/keepalived/bb.shshu=`cat /etc/keepalived/keepalived.conf|grep real_server|wc -l`if [ $shu -ne 1 ];thenecho " real_server $IP 80 { weight 1 notify_down /etc/keepalived/bb.sh TCP_CHECK { connect_timeout 3 nb_get_retry 3 delay_before_retry 3 connect_port 80 } } }" >>/etc/keepalived/keepalived.conffiecho ‘#!/bin/bashsystemctl stop keepalived‘>/etc/keepalived/bb.shchmod +x /etc/keepalived/bb.shyum -y install expectif [ -f /root/.ssh/id_rsa ]||[ -f id_rsa.pub ];then continueelse/usr/bin/expect <<EOF spawn ssh-keygen -t rsaexpect ":" {send "\n;"}expect ":" {send "\n;"}expect ":" {send "\n;"}expect eofEOFfi/usr/bin/expect <<EOFspawn ssh-copy-id root@$IP2expect "yes/no" {send "yes\n;exp_continue"}EOFssh root@$IP2 ‘yum -y install keepalived‘scp /etc/keepalived/keepalived.conf $IP2:/etc/keepalived/keepalived.confscp /etc/keepalived/bb.sh $IP2:/etc/keepalived/bb.sh/usr/bin/expect<<EOFspawn ssh root@$IP2 expect "~" {send "sed -i ‘s/$IP/$IP2/‘ /etc/keepalived/keepalived.conf\n"}expect "~" {send "sed -i ‘s/priority 100/priority 99/‘ /etc/keepalived/keepalived.conf\n"}expect "~" {send "sed -i ‘s/MASTER/BACKUP/‘ /etc/keepalived/keepalived.conf\n"}expect "~" {send "exit\n"}expect eofEOFwget http://nginx.org/download/nginx-1.16.1.tar.gzyum -y install gcc gcc-c++ zlib-devel pcre-develtar zxf nginx-1.16.1.tar.gzcd nginx-1.16.1 && ./configure && make && make installshulian=`cat /usr/local/nginx/conf/nginx.conf|grep ‘server $fu2:8081;‘|wc -l`if [ $shulian -ne 1 ];thensed -i ‘/#gzip on;/aupstream wg{‘ /usr/local/nginx/conf/nginx.confsed -i "/upstream wg{/aserver $fu:8080;" /usr/local/nginx/conf/nginx.confsed -i "/server $fu:8080;/aserver $fu2:8081;" /usr/local/nginx/conf/nginx.confsed -i "/server $fu2:8081/a\}" /usr/local/nginx/conf/nginx.confsed -i ‘s/index.htm;$/index.jsp;/‘ /usr/local/nginx/conf/nginx.confsed -i ‘/404.html;/alocation ~ \\.jsp$ {‘ /usr/local/nginx/conf/nginx.confsed -i ‘/location ~ \\.jsp$ {/aproxy_pass http://wg;‘ /usr/local/nginx/conf/nginx.confsed -i ‘/proxy_pass http:\/\/wg;/a\}‘ /usr/local/nginx/conf/nginx.conffipkill -15 nginx/usr/local/nginx/sbin/nginxsystemctl restart keepalivedssh root@$IP2 ‘wget http://nginx.org/download/nginx-1.16.1.tar.gz;yum -y install gcc gcc-c++ zlib-devel pcre-devel;tar zxf nginx-1.16.1.tar.gz;cd nginx-1.16.1 && ./configure && make && make install‘scp /usr/local/nginx/conf/nginx.conf $IP2:/usr/local/nginx/conf/nginx.confssh root@$IP2 ‘pkill -15 nginx;/usr/local/nginx/sbin/nginx;systemctl restart keepalived‘标签:div configure bsp down zip zlib gre keepaliv 输入
原文地址:https://www.cnblogs.com/wanglinyan/p/12752534.html