標籤:使用 共用 web服務 shell blog sse gre else long
部署nginx反向 Proxy三個web服務,調度演算法使用加權輪詢(由於物理原因只開啟兩台伺服器)
AutoNginxNfsService.sh
#/bin/bashsystemctl status nginxif(($?==4)) then yum install -y nginx if(($?==0)) then #echo ‘Yes!‘ systemctl start nginx if(($?==0)) then echo "Congratulations!! Nginx start OK!!" else echo "Sorry is Fail!!!" fi else echo"sorry install is Fail!!!" fi elif(($?==3)) then systemctl start nginx if(($?==0)) then echo "Congratulations!! Nginx start OK!!!" else echo "sorry!!" fielif(($?==0)) then echo "OKOKOK!!!"else echo "I am so sorry" fiecho "config writing...."grep ‘upstream‘ /etc/nginx/nginx.confif(($?!=0)) then sed -ri ‘/^http/a upstream Yanlong {‘ /etc/nginx/nginx.conf sed -ri ‘/^upst/a server yanlongweb1 weight=3\;‘ /etc/nginx/nginx.conf sed -ri ‘/^server yanlongweb1/a server yanlongweb2\;‘ /etc/nginx/nginx.conf sed -ri ‘/^server yanlongweb2/a \}‘ /etc/nginx/nginx.conf sed -ri ‘/^(\ +)(location)(\ )(\/)/a proxy_pass http:\/\/Yanlong\;‘ /etc/nginx/nginx.conffiecho "config write is OK!"systemctl reload nginxif(($?==0)) then echo "HTTP load balancer is OK!"else echo "Sorry!!"fisystemctl status nfsif(($?==4)) then yum install rpcbind nfs-utils -y if(($?==0)) then #echo ‘Yes!‘ systemctl start nfs if(($?==0)) then echo "Congratulations!! nfs start OK!!" else echo "Sorry is Fail!!!" fi else echo"sorry install is Fail!!!" fi elif(($?==3)) then systemctl start nfs if(($?==0)) then echo "Congratulations!! nfs start OK!!!" else echo "sorry!!" fielif(($?==0)) then echo "OKOKOK!!!"else echo "I am so sorry" fiecho "config writing...."echo "/webindex 192.168.16.0/24(rw,sync,fsid=0)" > /etc/exportsecho "config write is OK!"systemctl reload nfsif(($?==0)) then echo "NFS service is OK!"else echo "Sorry!!"fi
所有web服務使用共用儲存nfs,保證所有web都對其有讀寫權限,保證資料一致性
#/bin/bashsystemctl status nginxif(($?==4)) then yum install -y nginx if(($?==0)) then #echo ‘Yes!‘ systemctl start nginx if(($?==0)) then echo "Congratulations!! Nginx start OK!!" else echo "Sorry is Fail!!!" fi else echo"sorry install is Fail!!!" fielif(($?==3)) then systemctl start nginx if(($?==0)) then echo "Congratulations!! Nginx start OK!!!" else echo "sorry!!" fielif(($?==0)) then echo "OKOKOK!!!"else echo "I am so sorry" fiecho "config writing...."sed -ri ‘/^(\ +)(location)(\ )(\/)/a root\ \/nginxwebservice\;‘ /etc/nginx/nginx.confsed -ri ‘/^root\ \/nginxwebservice/a index\ web.html\;‘ /etc/nginx/nginx.confecho "config write is OK!"systemctl reload nginxif(($?==0)) then echo "HTTP load balancer YanlongWEBservice is OK!"else echo "Sorry!!"fisystemctl status nfsif(($?==4)) then yum install rpcbind nfs-utils -y if(($?==0)) then #echo ‘Yes!‘ systemctl start nfs if(($?==0)) then echo "Congratulations!! nfs start OK!!" else echo "Sorry is Fail!!!" fi else echo"sorry install is Fail!!!" fi elif(($?==3)) then systemctl start nfs if(($?==0)) then echo "Congratulations!! nfs start OK!!!" else echo "sorry!!" fielif(($?==0)) then echo "OKOKOK!!!"else echo "I am so sorry" fiecho "config writing...."mount -t nfs 192.168.16.120:/webindex/ /nginxwebservice/echo "config write is OK!"systemctl reload nfsif(($?==0)) then echo "NFS service is OK!"else echo "Sorry!!"fi
Shell指令碼-自動化部署反向 Proxy、WEB、nfs