首页 > 代码库 > nginx+tomcat实现反向代理的负载均衡

nginx+tomcat实现反向代理的负载均衡

nginx+tomcat实现反向代理的负载均衡

安装java环境

server12:

[root@server12 ~]# sh jdk-6u32-linux-x64.bin
[root@server12 ~]# mv jdk1.6.0_32/ /usr/local/
[root@server12 ~]# cd /usr/local/
[root@server12 local]# mv jdk1.6.0_32/ java
[root@server12 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!");
        }
}

编译和执行

[root@server12 ~]# javac test.java 
[root@server12 ~]# java test
hello world!



配置tomcat环境


[root@server12 ~]# tar zxf apache-tomcat-7.0.37.tar.gz -C /usr/local/
[root@server12 ~]# cd /usr/local/
[root@server12 local]# ln -s apache-tomcat-7.0.37/ tomcat
[root@server12 local]# cd tomcat/
[root@server12 tomcat]# cd bin/
[root@server12 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实现反向代理的负载均衡