nginx+tomcat实现反向代理的负载均衡
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了nginx+tomcat实现反向代理的负载均衡相关的知识,希望对你有一定的参考价值。
nginx+tomcat实现反向代理的负载均衡
安装java环境
server12:
[[email protected] ~]# sh jdk-6u32-linux-x64.bin [[email protected] ~]# mv jdk1.6.0_32/ /usr/local/ [[email protected] ~]# cd /usr/local/ [[email protected] local]# mv jdk1.6.0_32/ java [[email protected] local]# which java /usr/local/java/bin/java
配置java环境变量
vim /etc/profile
export JAVA_HOME=/usr/local/java export CLASSPATH=.:$JAVA_HOME/lib:$JAVA_HOME/jre/lib export PATH=$PATH:$JAVA_HOME/bin
. /etc/profile
检验:
编写java测试页,看是否jdk是否配置成功
vim test.java
class test { public static void main(String[] args) { System.out.println("hello world!"); } }
编译和执行
[[email protected] ~]# javac test.java [[email protected] ~]# java test hello world!
配置tomcat环境
[[email protected] ~]# tar zxf apache-tomcat-7.0.37.tar.gz -C /usr/local/ [[email protected] ~]# cd /usr/local/ [[email protected] local]# ln -s apache-tomcat-7.0.37/ tomcat [[email protected] local]# cd tomcat/ [[email protected] tomcat]# cd bin/ [[email protected] bin]# ./startup.sh
netstat -antlpue
tcp 0 0 :::8080 :::* LISTEN 0 20026 1718/java
检测:浏览器访问http://172.25.88.12:8080/
tomcat页面
nginx+tomat*2开始负载均衡拉~~
server11:
cd /usr/local/nginx/conf/
vim nginx.conf
22 http { 23 include mime.types; 24 default_type application/octet-stream; 25 26 upstream westos{ 27 server 172.25.88.12:8080; 28 server 172.25.88.13:8080; 29 } 69 location ~ \.jsp$ { 70 proxy_pass http://westos;
nginx -s reload
server12:
cd /usr/local/
scp -r tomcat/ java/ 172.25.4.13:/usr/local/
cd /usr/local/tomcat/webapps/ROOT
vim test.jsp
server2 the time is: <%=new java.util.Date() %>
cd /usr/local/tomcat/bin/ ./startup.sh
server13:
cd /usr/local/tomcat/webapps/ROOT
vim test.jsp
server3 the time is: <%=new java.util.Date() %>
vim /etc/profile
export JAVA_HOME=/usr/local/java export CLASSPATH=.:$JAVA_HOME/lib:$JAVA_HOME/jre/lib export PATH=$PATH:$JAVA_HOME/bin
cd /usr/local/tomcat/bin/ ./startup.sh
检测:
浏览器访问
http://172.25.88.11/test.jsp
2/3实现负载均衡
本文出自 “12049878” 博客,谢绝转载!
以上是关于nginx+tomcat实现反向代理的负载均衡的主要内容,如果未能解决你的问题,请参考以下文章
Nginx + Tomcat 反向代理 负载均衡 集群 部署指南