码迷,mamicode.com
首页 > 其他好文 > 详细

nginx+tomcat负载均衡

时间:2017-06-28 02:24:01      阅读:403      评论:0      收藏:0      [点我收藏+]

标签:bsp   xweb   using   use   XML   alt   startup   java环境   config   

实验环境:

nginx-server:192.168.20.194

tomcatweb01:192.168.20.150

tomcatweb02:192.168.20.163

#####################################################################

nginx-server:

[root@nginx-server ~]# yum install  -y pcre-devel zlib-devel 

[root@nginx-server ~]# tar zxvf nginx-1.6.0.tar.gz -C /usr/src/

[root@nginx-server ~]# cd /usr/src/nginx-1.6.0/

[root@nginx-server nginx-1.6.0]# ./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-http_stub_status_module

[root@nginx-server nginx-1.6.0]# make && make install

[root@nginx-server nginx-1.6.0]# ln -s /usr/local/nginx/sbin/nginx /usr/local/sbin/

[root@nginx-server nginx-1.6.0]# useradd -M -s /sbin/nologin ngin

[root@nginx-server nginx-1.6.0]# nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful

[root@nginx-server nginx-1.6.0]# vim /etc/init.d/nginx

技术分享
[root@nginx-server nginx-1.6.0]# chmod +x /etc/init.d/nginx
[root@nginx-server nginx-1.6.0]# /etc/init.d/nginx start
[root@nginx-server nginx-1.6.0]# netstat -anput | grep nginx
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 9899/nginx: master

############################nginxweb平台部署完成###############################################

tomcat-web平台

[root@tomcat-web1 ~]# tar zxvf jdk-7u65-linux-x64.gz -C /usr/src/

[root@tomcat-web1 ~]# cd /usr/src/
[root@tomcat-web1 src]# mv jdk1.7.0_65/ /usr/local/java
[root@tomcat-web1 src]# which java
/usr/bin/java

[root@tomcat-web1 src]# ln -s /usr/local/java/bin/* /usr/bin/

[root@tomcat-web1 src]# vim /etc/profile.d/java.sh
技术分享
[root@tomcat-web1 src]# source /etc/profile.d/java.sh
[root@tomcat-web1 src]# echo $PATH
/usr/lib64/qt-3.3/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin:/usr/local/java/bin

[root@tomcat-web1 src]# vim /etc/profile.d/java.sh
You have new mail in /var/spool/mail/root
[root@tomcat-web1 src]# source /etc/profile.d/java.sh
[root@tomcat-web1 src]# echo $PATH
/usr/lib64/qt-3.3/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin:/usr/local/java/bin

[root@tomcat-web1 src]# java -version
java version "1.7.0_65"
Java(TM) SE Runtime Environment (build 1.7.0_65-b17)
Java HotSpot(TM) 64-Bit Server VM (build 24.65-b04, mixed mode)

java环境部署完成,接下来安装配置tomcat

[root@tomcat-web1 ~]# tar zxvf apache-tomcat-7.0.54.tar.gz -C /usr/src

[root@tomcat-web1 ~]# cd /usr/src/
[root@tomcat-web1 src]# mv apache-tomcat-7.0.54/ /usr/local/tomcat
[root@tomcat-web1 src]# /usr/local/tomcat/bin/startup.sh

[root@tomcat-web1 ~]# cd /usr/src/
[root@tomcat-web1 src]# mv apache-tomcat-7.0.54/ /usr/local/tomcat
[root@tomcat-web1 src]# /usr/local/tomcat/bin/startup.sh

[root@tomcat-web1 src]# netstat -anput | grep 8080
tcp 0 0 :::8080 :::* LISTEN 27993/java

验证tomcat是否正常访问firefox http://192.168.20.150:8080

技术分享

[root@tomcat-web1 ~]# mkdir /web/xiaoyu -p
[root@tomcat-web1 ~]# vim /web/xiaoyu/index.jsp

技术分享
[root@tomcat-web1 ~]# vim /usr/local/tomcat/conf/server.xml

技术分享

[root@tomcat-web1 ~]# elinks 192.168.20.150:8080     #由此我们tomcat01web页面可以正常运行

技术分享

########################tomcatweb01服务部署完成############################################

tomcatweb02服务(第二台tomcat服务步骤是完全一样的 ,为了便于区别,仅仅是更改了网页内容)

准备java环境---

[root@tomcat-web2 ~]# tar zxvf jdk-7u65-linux-x64.gz -C /usr/src/

[root@tomcat-web2 ~]# cd /usr/src/

[root@tomcat-web2 src]# mv jdk1.7.0_65/ /usr/local/java

 

root@tomcat-web2 src]# ln -s /usr/local/java/bin/* /usr/bin/
[root@tomcat-web2 src]# vim /etc/profile.d/java.sh

 

 

export JAVA_HOME=/usr/local/java
export PATH=$PATH:$JAVA_HOME/bin

[root@tomcat-web2 src]# source /etc/profile.d/java.sh
[root@tomcat-web2 src]# echo $PATH
/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin:/usr/local/java/bin

[root@tomcat-web2 src]# java -version
java version "1.7.0_65"
Java(TM) SE Runtime Environment (build 1.7.0_65-b17)
Java HotSpot(TM) 64-Bit Server VM (build 24.65-b04, mixed mode)

安装tomcatweb02

 

root@tomcat-web2 ~]# tar  zxvf apache-tomcat-7.0.54.tar.gz -C /usr/src/

[root@tomcat-web2 ~]# cd /usr/src/
[root@tomcat-web2 src]# mv apache-tomcat-7.0.54/ /usr/local/tomcat
[root@tomcat-web2 src]# /usr/local/tomcat/bin/startup.sh
Using CATALINA_BASE: /usr/local/tomcat
Using CATALINA_HOME: /usr/local/tomcat
Using CATALINA_TMPDIR: /usr/local/tomcat/temp
Using JRE_HOME: /usr/local/java
Using CLASSPATH: /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar
Tomcat started.
[root@tomcat-web2 src]# netstat -anput | grep 8080
tcp 0 0 :::8080 :::* LISTEN 20632/java

[root@tomcat-web2 ~]# vim /web/xiaoyu/index.jsp

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<html>
<head>
<title>JSP test2 pge</title>
</head>
<body>
<% out.println(“ This is are tomcat website ;http://xiaoyu.test2.com");%>
</body>
</html>

技术分享

root@tomcat-web2 ~]# vim /usr/local/tomcat/conf/server.xml 

技术分享

tomcatweb01网站页面验证

[root@tomcat-web2 ~]# elinks 192.168.20.163:8080

技术分享

######################################################以上步骤,nginx,以及两台tomcat网站已经搭建完成########################################################

接下来我们需要让nginx代理两台tomcat网站,并实现负载均衡

[root@nginx-server ~]# vim /usr/local/nginx/conf/nginx.conf

技术分享  

#############################################验证:打开本地浏览器输入nginx自己的IP地址,反复刷新,即可出现另外两台tomcat页面,即实现负载####################

http://192.168.20.194/index.jsp

技术分享

技术分享

 

nginx+tomcat负载均衡

标签:bsp   xweb   using   use   XML   alt   startup   java环境   config   

原文地址:http://www.cnblogs.com/bixiaoyu/p/7087797.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!