实验环境:
nginx服务器 : 192.168.80.254
tomcat1服务器: 192.168.80.189
tomcat2服务器: 192.168.80.188
关闭防火墙:
[[email protected] ~]# service iptables stop
[[email protected] ~]# setenforce 0
一、安装tomcat服务(tomcat1)
tomcatl和tomcat2配置一样
1.安装jdk,配置java环境
chmod +x jdk-6u20-linux-i586.bin ( 32位操作系统)
/jdk-6u20-linux-i586.bin
mv jdk1.6.0_20/ /usr/local/java
2.配置java脚本
vim /etc/profile.d/java.sh
export JAVA_HOME=/usr/local/java
export PATH=$PATH:$JAVA_HOME/bin
source /etc/profile.d/java.sh
java -version
3.执行脚本及查看java版本
source /etc/profile.d/java.sh
java -version
4.安装tomcat
[[email protected] ~]# tar xf apache-tomcat-7.0.54.tar.gz
[[email protected] ~]# mv apache-tomcat-7.0.54 /usr/local/tomcat7
5.启动tomcat
[[email protected] ~]# /usr/local/tomcat7/bin/startup.sh
Using CATALINA_BASE: /usr/local/tomcat7
Using CATALINA_HOME: /usr/local/tomcat7
Using CATALINA_TMPDIR: /usr/local/tomcat7/temp
Using JRE_HOME: /usr/local/java
Using CLASSPATH: /usr/local/tomcat7/bin/bootstrap.jar:/usr/local/tomcat7/bin/tomcat-juli.jar
Tomcat started.
6.查看默认运行在8080端口
[[email protected] ~]# netstat -anpt | grep :8080
tcp 0 0 :::8080 :::* LISTEN 6689/java
7.搭建JSP运行环境
mkdir -p /web/webapp1
vi /web/webapp1/index.jsp
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<html>
<head>
<title>JSP test1 page</title>
</head>
<body>
<% out.println("welcom to test011 site");%>
</body>
</html>
vi /usr/local/tomcat7/conf/server.xml
<Host name="localhost" appBase="webapps"
unpackWARs="true" autoDeploy="true">
----以下内容要自己增加=---------
<Context docBase="/web/webapp1" path="" reloadable="false" >
</Context>
/usr/local/tomcat7/bin/shutdown.sh
/usr/local/tomcat7/bin/startup.sh
二Nginx 服务器配置
1.关闭防火墙
service iptables stop
setenforce 0
2.安装依赖的软件包
yum -y install pcre-devel zlib-devel openssl-devel lrzsz
3.创建nginx用户
groupadd nginx
useradd -g nginx nginx -s /sbin/nologin
tar xf nginx-1.6.2.tar.gz
cd nginx-1.6.2
make && make install
4.s03-nginx部署
yum install -y \
pcre-devel \
zlib-devel \
openssl-devel
useradd www -s /bin/false
tar xzvf nginx-1.6.0.tar.gz
cd nginx-1.6.0
./configure \
--prefix=/usr/local/nginx \
--user=nginx \
--group=nginx \
--with-file-aio \
--with-http_stub_status_module \
--with-http_gzip_static_module \
--with-http_flv_module \
--with-http_ssl_module
make && make install
ln -s /usr/local/nginx/sbin/nginx /usr/local/sbin/
vi /usr/local/nginx/conf/nginx.conf
---在下面增加一行proxy_pass--------
location / {
root html;
index index.html index.htm;
proxy_pass http://tomcat_server;
}
----在server上面新增如下-----
upstream tomcat_server {
server 192.168.80.189:8080 weight=1;
server 192.168.80.193:8080 weight=1;
}
nginx -t
nginx
测试:直接输入调度器的IP地址,测试就行了
(http://192.168.80.254)