shell部署nginx+tomcat代理负载用supervisor批量前台启动

#!/bin/bash
systemctl stop firewalld
setenforce 0
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
shulian=`cat /usr/local/nginx/conf/nginx.conf|grep 'server 192.168.11.135:8081;'|wc -l`
if [ $shulian -ne 1 ];then #判断是否有该配置
sed -i  '/#gzip  on;/aupstream wg{' /usr/local/nginx/conf/nginx.conf   #在gzip  on;下一行追加upstream wg{
sed -i  '/upstream wg{/aserver 192.168.11.135:8080;' /usr/local/nginx/conf/nginx.conf   #在upstream wg{下一行追加server 192.168.11.135:8080;
sed -i  '/server 192.168.11.135:8080;/aserver 192.168.11.135:8081;' /usr/local/nginx/conf/nginx.conf  #在server 192.168.11.135:8080;下一行追加server 192.168.11.135:8081;
sed -i  '/server 192.168.11.135:8081/a\}' /usr/local/nginx/conf/nginx.conf  #在server 192.168.11.135:8081;下一行追加}
sed -i  's/index.htm;$/index.jsp;/' /usr/local/nginx/conf/nginx.conf  #把以index.htm;结尾换成index.jsp;
sed -i  '/404.html;/alocation ~ \\.jsp$ {' /usr/local/nginx/conf/nginx.conf  #在404.html;下一行追加location ~ \.jsp$ {
sed -i  '/location ~ \\.jsp$ {/aproxy_pass   http://wg;' /usr/local/nginx/conf/nginx.conf #在location ~ \.jsp$ {下一行追加proxy_pass   http://wg;
sed -i  '/proxy_pass   http:\/\/wg;/a\}' /usr/local/nginx/conf/nginx.conf  #在proxy_pass   http://wg;下一行追加}
fi
cd /root && rpm -ivh jdk-8u20-linux-x64.rpm     #自己拉jdk包到\root
cishu=`cat /etc/profile|grep 'JAVA_HOME'|wc -l`
if [ $cishu -ne 4 ];then   #判断是否有该配置
echo -e 'export JAVA_HOME=/usr/java/jdk1.8.0_20
export JAVA_BIN=/usr/java/jdk1.8.0_20/bin
export PATH=$PATH:$JAVA_HOME/bin
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export PATH=$JAVA_HOME/bin:$JRE_HOME/bin:$PATH' >>/etc/profile
fi
source /etc/profile
wget http://mirrors.tuna.tsinghua.edu.cn/apache/tomcat/tomcat-7/v7.0.96/bin/apache-tomcat-7.0.96.tar.gz
tar zxf apache-tomcat-7.0.96.tar.gz
cp -r apache-tomcat-7.0.96 /opt/tomcat
cp -r apache-tomcat-7.0.96 /opt/tomcat1
sed -i 's/8005/8006/' /opt/tomcat1/conf/server.xml #把所有8005换成8006
sed -i 's/8009/8010/' /opt/tomcat1/conf/server.xml #把所有8009换成8010
sed -i 's/8080/8081/' /opt/tomcat1/conf/server.xml #把所有8080换成8081
yum -y install epel-release
yum -y install supervisor
echo '[program:nginx]
command=/usr/local/nginx/sbin/nginx -g "daemon off;"
[program:tomcat]
command=/opt/tomcat/bin/catalina.sh run
[program:tomcat1]
command=/opt/tomcat1/bin/catalina.sh run' >/etc/supervisord.d/nginx.ini
systemctl restart supervisord
sed -i 's/Congratulations!/111111111111/' /opt/tomcat1/webapps/ROOT/index.jsp

发布了75 篇原创文章 · 获赞 96 · 访问量 6393

猜你喜欢

转载自blog.csdn.net/weixin_45762569/article/details/102922922