一、基本环境
主机 |
系统版本 |
IP |
软件包 |
Nginx服务器 |
CentOS 6.5 64位 |
192.168.10.128 |
nginx-1.6.0.tar.gz |
Tomcat服务器1 |
CentOS 6.5 64位 |
192.168.10.129 |
jdk-7u65-linux-x64.gz apache-tomcat-7.0.54.tar.gz |
Tomcat服务器2 |
CentOS 6.5 64位 |
192.168.10.130 |
jdk-7u65-linux-x64.gz apache-tomcat-7.0.54.tar.gz |
二、实施过程
1、Tomact服务器配置
-两台服务器配置相同
-安装JDK,配置Java环境
--卸载已有JDK
[[email protected] src]# yum -y remove java-*
--解压
[[email protected] src]# tar zxfjdk-7u65-linux-x64.gz
--将解压生成的文件夹,移动到/usr/local/下并重命名
[[email protected] src]# mv jdk1.7.0_65//usr/local/java
--添加环境变量
[[email protected] src]# echo"PATH=$PATH:/usr/local/java/bin" >> /etc/profile [[email protected] src]# . /etc/profile
--查看版本
[[email protected] src]# java -version java version "1.7.0_65" Java(TM) SE Runtime Environment (build1.7.0_65-b17) Java HotSpot(TM) 64-Bit Server VM (build24.65-b04, mixed mode)
-安装Tomcat
--解压
[[email protected] src]# tar zxfapache-tomcat-7.0.54.tar.gz
--将解压生成的文件夹,移动到/usr/local/下并重命名
[[email protected] src]# mvapache-tomcat-7.0.54/ /usr/local/tomcat7
--启动
[[email protected] src]#/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. [[email protected] src]# netstat -anpt | grep8080 tcp 0 0 :::8080 :::* LISTEN 58687/java
--访问测试
-建立不同的测试页
--创建web目录
[[email protected] src]# mkdir -p /web/webapp1
--建立测试页(此处不同)
[[email protected] src]# vim/web/webapp1/index.jsp <%@ page language="java"import="java.util.*" pageEncoding="UTF-8"%> <html> <head> <title>192.168.10.129</title> </head> <body> <% out.println("192.168.10.129");%> </body> </html>
--修改Tomcat的server.xml文件
[[email protected] src]# vim/usr/local/tomcat7/conf/server.xml <Host name="localhost" appBase="webapps" unpackWARs="true" autoDeploy="true"> <Context docBase="/web/webapp1" path=""reloadable="false" > </Context>
--重启Tomcat
[[email protected] src]#/usr/local/tomcat7/bin/shutdown.sh [[email protected] src]# /usr/local/tomcat7/bin/startup.sh
--测试
2、nginx服务器配置
-安装
--安装相关包
[[email protected] src]# yum -y installpcre-devel zlib-devel openssl-devel
--创建程序用户
[[email protected] src]# useradd -s /bin/false www
--解压
[[email protected] src]# tar zxf nginx-1.6.0.tar.gz [[email protected] src]# cd nginx-1.6.0
--配置、编译、安装
[[email protected] nginx-1.6.0]# ./configure--prefix=/usr/local/nginx --user=www --group=www --with-file-aio--with-http_stub_status_module --with-http_gzip_static_module--with-http_ssl_module --with-http_flv_module && make && makeinstall
---注:
--prefix=/usr/local/nginx#指定安装路径 --user=www--group=www #指定运行的用户和组 --with-file-aio #启用文件修改支持 --with-http_stub_status_module#启用状态统计 --with-http_gzip_static_module#启用gzip静态压缩 --with-http_ssl_module#启用ssl模块 --with-http_flv_module#启用flv模块
-创建连接文件
[[email protected] nginx-1.6.0]# ln -s/usr/local/nginx/sbin/nginx /usr/local/sbin/
-编写服务脚本
[[email protected] nginx-1.6.0]# vim/etc/init.d/nginx #!/bin/bash # chkconfig: - 99 20 PROG="/usr/local/nginx/sbin/nginx" PIDF="/usr/local/nginx/logs/nginx.pid" case "$1" in start) $PROG ;; stop) kill -s QUIT $(cat $PIDF) ;; restart) $0 stop $0 start ;; reload) kill -s HUP $(cat $PIDF) ;; *) echo "Usage: $0 {start|stop|restart|reload}" exit 1 esac exit 0 [[email protected] nginx-1.6.0]# chmod 755/etc/init.d/nginx [[email protected] nginx-1.6.0]# chkconfig --addnginx
-配置
[[email protected] nginx-1.6.0]# vim/usr/local/nginx/conf/nginx.conf
--http{……}
upstream tomcat { server 192.168.10.129:8080weight=1; server 192.168.10.130:8080weight=1; }
--http{……}—sever{……}—
location / { root html; index index.html index.htm; proxy_pass http://tomcat; }
--其他
#user nobody; worker_processes 1; #工作进程数量 #error_log logs/error.log; #error_log logs/error.log notice; #error_log logs/error.log info; #pid logs/nginx.pid; events { use epoll; #I/O响应模型 worker_connections 4096;#每个进程处理的连接数 }
--测试配置文件是否正确
[[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]# nginx -c/usr/local/nginx/conf/nginx.conf
三、测试效果
时间: 2024-09-29 06:03:46