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/profilejava

export JAVA_HOME=/usr/local/java  
export CLASSPATH=.:$JAVA_HOME/lib:$JAVA_HOME/jre/lib  
export PATH=$PATH:$JAVA_HOME/bin

. /etc/profilelinux


檢驗:

編寫java測試頁,看是否jdk是否配置成功

vim test.javanginx


class test {
        public static void main(String[] args)
        {
                System.out.println("hello world!");
        }
}

編譯和執行web

[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 -antlpueapache

tcp        0      0 :::8080                     :::*                        LISTEN      0          20026      1718/java

檢測:瀏覽器訪問http://172.25.88.12:8080/

tomcat頁面vim


wKioL1jZD_zRKrh9AADDWbqMnhI468.png




nginx+tomat*2開始負載均衡拉~~

server11:

cd /usr/local/nginx/conf/瀏覽器

vim nginx.conftomcat


 22 http {
 23     include       mime.types;
 24     default_type  application/octet-stream;
 25 
 26         upstream miao{
 27         server  172.25.88.12:8080;    
 28         server  172.25.88.13:8080;
 29         }






 69         location ~ \.jsp$ {
 70                 proxy_pass http://miao;


nginx -s reloadapp

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實現負載均衡


wKioL1jZD_yj83oQAAAiY7SgRBg826.pngwKiom1jZD_zRL7OnAAAg9m0hKOM914.png

相關文章
相關標籤/搜索