nginx+Tomcat负载均衡

Posted wanglinyan

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了nginx+Tomcat负载均衡相关的知识,希望对你有一定的参考价值。

#!/bin/bash
rpm -ivh jdk-8u131-linux-x64_.rpm
if [ `grep JAVA_HOME /etc/profile | wc -l` -ne 4 ];then
echo -e ‘export JAVA_HOME=/usr/java/jdk1.8.0_131
export JAVA_BIN=/usr/javak1.8.0_131/bin
export PATH=$PATH:$JAVA_HOME/bin
export CLASSPATH=.:$JAVA_HOMEb/dt.jar:$JAVA_HOMEb/tools.jar
export PATH=$JAVA_HOME/bin:$JRE_HOME/bin:$PATH‘ >> /etc/profile
fi
source /etc/profile
tar xfz apache-tomcat-7.0.47.tar.gz
mv apache-tomcat-7.0.47 /opt/tomcat1
tar xfz apache-tomcat-7.0.47.tar.gz
mv apache-tomcat-7.0.47 /opt/tomcat2
sed -i ‘s/8009/18009/‘ /opt/tomcat2/conf/server.xml
sed -i ‘s/8005/18005/‘ /opt/tomcat2/conf/server.xml
sed -i ‘s/8080/18080/‘ /opt/tomcat2/conf/server.xml
yum -y install supervisor
systemctl start supervisord
touch /etc/supervisord.d/tomcat1.ini
touch /etc/supervisord.d/tomcat2.ini
echo -e ‘[program:tomcat1]
command=/opt/tomcat1/bin/catalina.sh run‘ >> /etc/supervisord.d/tomcat1.ini
echo -e ‘[program:tomcat2]
command=/opt/tomcat2/bin/catalina.sh run‘ >> /etc/supervisord.d/tomcat2.ini
systemctl restart supervisord
yum -y install gcc gcc-c++ pcre-devel zlib-devel
tar xfz nginx-1.12.0.tar.gz
cd nginx-1.12.0 && ./configure && make && make install
sed -i ‘/#gzip  on;/aupstream tomcat{‘ /usr/local/nginx/conf/nginx.conf
sed -i ‘/upstream tomcat{/aserver 10.0.0.41:8080;‘ /usr/local/nginx/conf/nginx.conf
sed -i ‘/server 10.0.0.41:8080;/aserver 10.0.0.41:18080;‘ /usr/local/nginx/conf/nginx.conf
sed -i ‘/server 10.0.0.41:18080;/a}‘ /usr/local/nginx/conf/nginx.conf
sed -i ‘s/index.htm;$/index.jsp;/‘ /usr/local/nginx/conf/nginx.conf
sed -i ‘/404.html;/alocation ~ .jsp$ {‘ /usr/local/nginx/conf/nginx.conf
sed -i ‘/location ~ .jsp$ {/aproxy_pass   http://tomcat;‘ /usr/local/nginx/conf/nginx.conf
sed -i ‘/proxy_pass   http://tomcat;/a}‘ /usr/local/nginx/conf/nginx.conf
/usr/local/nginx/sbin/nginx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!/bin/bash
rpm -ivh jdk-8u131-linux-x64_.rpm
if [ `grep JAVA_HOME /etc/profile | wc -l` -ne 4 ];then
echo -e ‘export JAVA_HOME=/usr/java/jdk1.8.0_131
export JAVA_BIN=/usr/javak1.8.0_131/bin
export PATH=$PATH:$JAVA_HOME/bin
export CLASSPATH=.:$JAVA_HOMEb/dt.jar:$JAVA_HOMEb/tools.jar
export PATH=$JAVA_HOME/bin:$JRE_HOME/bin:$PATH‘ >> /etc/profile
fi
source /etc/profile
tar xfz apache-tomcat-7.0.47.tar.gz
mv apache-tomcat-7.0.47 /opt/tomcat1
tar xfz apache-tomcat-7.0.47.tar.gz
mv apache-tomcat-7.0.47 /opt/tomcat2
sed -i ‘s/8009/18009/‘ /opt/tomcat2/conf/server.xml
sed -i ‘s/8005/18005/‘ /opt/tomcat2/conf/server.xml
sed -i ‘s/8080/18080/‘ /opt/tomcat2/conf/server.xml
yum -y install supervisor
systemctl start supervisord
touch /etc/supervisord.d/tomcat1.ini
touch /etc/supervisord.d/tomcat2.ini
echo -e ‘[program:tomcat1]
command=/opt/tomcat1/bin/catalina.sh run‘ >> /etc/supervisord.d/tomcat1.ini
echo -e ‘[program:tomcat2]
command=/opt/tomcat2/bin/catalina.sh run‘ >> /etc/supervisord.d/tomcat2.ini
systemctl restart supervisord
yum -y install gcc gcc-c++ pcre-devel zlib-devel
tar xfz nginx-1.12.0.tar.gz
cd nginx-1.12.0 && ./configure && make && make install
sed -i ‘/#gzip  on;/aupstream tomcat{‘ /usr/local/nginx/conf/nginx.conf
sed -i ‘/upstream tomcat{/aserver 10.0.0.41:8080;‘ /usr/local/nginx/conf/nginx.conf
sed -i ‘/server 10.0.0.41:8080;/aserver 10.0.0.41:18080;‘ /usr/local/nginx/conf/nginx.conf
sed -i ‘/server 10.0.0.41:18080;/a}‘ /usr/local/nginx/conf/nginx.conf
sed -i ‘s/index.htm;$/index.jsp;/‘ /usr/local/nginx/conf/nginx.conf
sed -i ‘/404.html;/alocation ~ .jsp$ {‘ /usr/local/nginx/conf/nginx.conf
sed -i ‘/location ~ .jsp$ {/aproxy_pass   http://tomcat;‘ /usr/local/nginx/conf/nginx.conf
sed -i ‘/proxy_pass   http://tomcat;/a}‘ /usr/local/nginx/conf/nginx.conf
/usr/local/nginx/sbin/nginx

  

以上是关于nginx+Tomcat负载均衡的主要内容,如果未能解决你的问题,请参考以下文章

部署Tomcat 及 nginx+tomcat负载均衡

Nginx+Tomcat负载均衡群集

Nginx+Tomcat负载均衡集群

nginx+Tomcat负载均衡集群

Nginx+Tomcat负载均衡集群

部署Nginx+Tomcat负载均衡群集