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实现负载均衡
时间: 2024-10-14 05:37:49