Nginx+Tomcat动静分离脚本
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Nginx+Tomcat动静分离脚本相关的知识,希望对你有一定的参考价值。
#!/bin/bash
setenforce 0
systemctl stop firewalld
tar -zxvf nginx-1.8.0.tar.gz -C /usr/src/
cd /usr/src/nginx-1.8.0/
yum -y install make gcc gcc-c++ libtool ncurses-devel openssl-devel pcre-devel perl-devel lsof
if [ $? -eq 0 ];then
echo "安装环境已经安装完成--"
else
echo "安装环境安装失败--"
fi
./configure --prefix=/usr/local/nginx && make && make install
if [ $? -eq 0 ];then
echo "nginx安装成功"
else
echo "nginx安装失败"
fi
cd
ln -s /usr/local/nginx/sbin/nginx /usr/bin/
nginx
lsof -i:80
if [ $? -eq 0 ];then
echo "nginx启动成功"
else
echo "nginx启动失败"
fi
sed -i ‘/location \//,/}/s/^ /#/‘ /usr/local/nginx/conf/nginx.conf
if [ $? -eq 0 ];then
echo "原网页根路径注释成功"
sed -i ‘/# #/s/^#/ /‘ /usr/local/nginx/conf/nginx.conf
else
echo "原网页根路径注释失败"
fi
sed -i "/charset koi8-r/a\ location / {\n proxy_pass http://www;\n }" /usr/local/nginx/conf/nginx.conf
if [ $? -eq 0 ];then
echo "proxy代理设置成功"
else
echo "proxy代理失败,请检查"
fi
sed -i "/charset koi8-r/a\ location ~ \.(gif|jpg|jpeg|bmp|png|txt|ico|js|css)$ {\n root /usr/local/nginx/web; \n }" /usr/local/nginx/conf/nginx.conf
if [ $? -eq 0 ];then
echo "静态图库解析设置成功"
else
echo "静态图库解析设置失败,请检查"
fi
sed -i "/http {/a\ upstream www { \n server 192.168.126.131:8080;\n server 192.168.126.132:8080;\n }" /usr/local/nginx/conf/nginx.conf
if [ $? -eq 0 ];then
echo "upstream已部署完成"
else
echo "upstream部署失败"
fi
echo "nginx负载均衡反向代理已部署成功"
pkill nginx
nginx
lsof -i:80
if [ $? -eq 0 ];then
echo "nginx启动成功"
else
echo "nginx启动失败"
fi
2.tomcat
#!/bin/bash
###
setenforce 0
systemctl stop firewalld
rpm -ivh jdk-8u20-linux-x64.rpm
cat >>/etc/profile<< EOF
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
EOF
source /etc/profile
java -version
if [ $? -eq 0 ];then
echo "JDK安装成功"
else
echo "JDK安装失败"
fi
#lsof -i:8080
#if [ $? -eq 0 ];then
if [ ! -d /opt/tomcat ];then
tar zxvf apache-tomcat-7.0.47.tar.gz
#echo "CATALINA_HOME=/usr/local/tomcat-7.0/">>/usr/local/tomcat/bin/catalina.sh
cp -r apache-tomcat-7.0.47 /opt/tomcat
ln -s /opt/tomcat/bin /usr/bin
else
echo "tomcat服务已安装~~~~"
fi
/opt/tomcat/bin/startup.sh
if [ $? -eq 0 ];then
echo "tomcat 启动成功"
else
echo "tomcat 启动失败"
fi
cd/opt/tomcat/webapps
yum -y install lrzsz mariadb mariadb-server
systemctl resrart mariadb
mysqladmin -uroot password 123
mysql -uroot -p 123
rz
mv /opt/tomcat/webapps/ROOT /opt/tomcat/webapps/ROOT.back
mv /opt/tomcat/webapps/Anynote /opt/tomcat/webapps/ROOT
sed -i "/jdbc.url=/s/localhost/192.168.50.138/" /opt/tomcat/webapps/ROOT/WEB-INF/jdbc.properties
sed -i "/jdbc.username=/s/root/jia/" /opt/tomcat/webapps/ROOT/WEB-INF/jdbc.properties
sed -i "/jdbc.password=/s/jdbc.password=/jdbc.password=123/" /opt/tomcat/webapps/ROOT/WEB-INF/jdbc.properties
if [ $? -eq 0 ];then
echo "修改成功,远程用户名jia,密码123"
else
echo "您的输入有误,请输入正确"
fi
/opt/tomcat/bin/shutdown.sh
if [ $? -eq 0 ];then
echo "tomcat-关闭成功"
else
echo "tomcat-关闭失败"
fi
/opt/tomcat/bin/startup.sh
if [ $? -eq 0 ];then
echo "tomcat-启动成功"
else
echo "tomcat-启动失败"
fi
以上是关于Nginx+Tomcat动静分离脚本的主要内容,如果未能解决你的问题,请参考以下文章