实验环境:
nginx-server:192.168.20.194
tomcatweb01:192.168.20.150
tomcatweb02:192.168.20.163
#####################################################################
nginx-server:
[[email protected] ~]# yum install -y pcre-devel zlib-devel
[[email protected] ~]# tar zxvf nginx-1.6.0.tar.gz -C /usr/src/
[[email protected] ~]# cd /usr/src/nginx-1.6.0/
[[email protected] nginx-1.6.0]# ./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-http_stub_status_module
[[email protected] nginx-1.6.0]# make && make install
[[email protected] nginx-1.6.0]# ln -s /usr/local/nginx/sbin/nginx /usr/local/sbin/
[[email protected] nginx-1.6.0]# useradd -M -s /sbin/nologin ngin
[[email protected] 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
[[email protected] nginx-1.6.0]# vim /etc/init.d/nginx
[[email protected] nginx-1.6.0]# chmod +x /etc/init.d/nginx
[[email protected] nginx-1.6.0]# /etc/init.d/nginx start
[[email protected] 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平台
[[email protected] ~]# tar zxvf jdk-7u65-linux-x64.gz -C /usr/src/
[[email protected] ~]# cd /usr/src/
[[email protected] src]# mv jdk1.7.0_65/ /usr/local/java
[[email protected] src]# which java
/usr/bin/java
[[email protected] src]# ln -s /usr/local/java/bin/* /usr/bin/
[[email protected] src]# vim /etc/profile.d/java.sh
[[email protected] src]# source /etc/profile.d/java.sh
[[email protected]mcat-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
[[email protected] src]# vim /etc/profile.d/java.sh
You have new mail in /var/spool/mail/root
[[email protected] src]# source /etc/profile.d/java.sh
[[email protected] 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
[[email protected] 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
[[email protected] ~]# tar zxvf apache-tomcat-7.0.54.tar.gz -C /usr/src
[[email protected] ~]# cd /usr/src/
[[email protected] src]# mv apache-tomcat-7.0.54/ /usr/local/tomcat
[[email protected] src]# /usr/local/tomcat/bin/startup.sh
[[email protected] ~]# cd /usr/src/
[[email protected] src]# mv apache-tomcat-7.0.54/ /usr/local/tomcat
[[email protected] src]# /usr/local/tomcat/bin/startup.sh
[[email protected] src]# netstat -anput | grep 8080
tcp 0 0 :::8080 :::* LISTEN 27993/java
验证tomcat是否正常访问firefox http://192.168.20.150:8080
[[email protected] ~]# mkdir /web/xiaoyu -p
[[email protected] ~]# vim /web/xiaoyu/index.jsp
[[email protected] ~]# vim /usr/local/tomcat/conf/server.xml
[[email protected] ~]# elinks 192.168.20.150:8080 #由此我们tomcat01web页面可以正常运行
########################tomcatweb01服务部署完成############################################
tomcatweb02服务(第二台tomcat服务步骤是完全一样的 ,为了便于区别,仅仅是更改了网页内容)
准备java环境---
[[email protected] ~]# tar zxvf jdk-7u65-linux-x64.gz -C /usr/src/
[[email protected] ~]# cd /usr/src/
[[email protected] src]# mv jdk1.7.0_65/ /usr/local/java
[email protected] src]# ln -s /usr/local/java/bin/* /usr/bin/
[[email protected] src]# vim /etc/profile.d/java.sh
export JAVA_HOME=/usr/local/java
export PATH=$PATH:$JAVA_HOME/bin
[[email protected] src]# source /etc/profile.d/java.sh
[[email protected] src]# echo $PATH
/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin:/usr/local/java/bin
[[email protected] 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
[email protected] ~]# tar zxvf apache-tomcat-7.0.54.tar.gz -C /usr/src/
[[email protected]t-web2 ~]# cd /usr/src/
[[email protected] src]# mv apache-tomcat-7.0.54/ /usr/local/tomcat
[[email protected] 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.
[[email protected] src]# netstat -anput | grep 8080
tcp 0 0 :::8080 :::* LISTEN 20632/java
[[email protected] ~]# 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>
[email protected] ~]# vim /usr/local/tomcat/conf/server.xml
tomcatweb01网站页面验证
[[email protected] ~]# elinks 192.168.20.163:8080
######################################################以上步骤,nginx,以及两台tomcat网站已经搭建完成########################################################
接下来我们需要让nginx代理两台tomcat网站,并实现负载均衡
[[email protected] ~]# vim /usr/local/nginx/conf/nginx.conf
#############################################验证:打开本地浏览器输入nginx自己的IP地址,反复刷新,即可出现另外两台tomcat页面,即实现负载####################
http://192.168.20.194/index.jsp