一、环境介绍
1.本次实验共3台虚拟机(rhel6.2-64)
192.168.232.147(nginx)
192.168.232.154(tomcat)
192.168.232.155(tomcat)
2.安装并配置JDK
3.配置相关环境变量(profile,hosts)
4.准备好一个web项目,以便用于测试是否负载均衡,本次实验用一以前写的权限管理的模块
二、安装配置tomcat
1.在192.168.232.154,192.168.232.155机器安装tomcat
2.下载一个linux版本的apache-tomcat-7.0.64.tar.gz解压即可用
3.在
<context path="" docbase="/root/webapps/permission" reloadable="false"></context>
4.创建/root/webapps目录,然后把permission这个web项目放到该目录下,启动tomcat,访问
http://192.168.232.154:8080/ , http://192.168.232.154:8080/ 可以访问到permission项目的首页
三、安装配置Nginx
1.下载nginx-1.2.6.tar.gz 并解压放到指定的目录下
2.确保nginx编译所具备的运行环境
3.安装pcre-devel openssl openssl-devel
(1)配置本地yum,使得yum安装时能找到安装包
(2)安装:yum -y install pcre-devel openssl openssl-devel
4.创建www用户:useradd www
5.准备编译安装环境
./configure --user=www --group=www --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module
6.编译安装,进到nginx解压的根目录:cd /root/app/nginx-1.2.6
make && make install
7.检查nginx安装是否成功
[root@storm1 nginx-1.2.6]# /usr/local/nginx/sbin/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
8.访问nginx默认主页:http://192.168.232.147:80/,可以看到nginx欢迎主页面
到此Nginx安装完毕
四、配置nginx+tomcat集成,其实只需配置nginx,tomcat不用动
1.进到安装指定的目录:/usr/local/nginx,把nginx.conf简单的改成如下
user www www; worker_processes 1; pid /usr/local/nginx/logs/nginx.pid; events { use epoll; worker_connections 1024; } http { include mime.types; default_type application/octet-stream; include /usr/local/nginx/conf/proxy.conf; sendfile on; tcp_nopush on; keepalive_timeout 65; log_format $upstream_addr $status $request_time $time_local $remote_user $http_user_agent; upstream panguoyuan.com { server 192.168.232.154:8080; server 192.168.232.155:8080; } server{ listen 80; server_name panguoyuan.com; location / { proxy_pass http://panguoyuan.com; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } } }
2.在192.168.232.147机器上的hosts如下
[root@storm1 conf]# cat /etc/hosts
192.168.232.147 storm1
192.168.232.154 storm2
192.168.232.155 storm3
192.168.232.147 panguoyuan.com
版权声明:本文为博主原创文章,未经博主允许不得转载。
以上就介绍了nginx+tomcat负载均衡,包括了方面的内容,希望对PHP教程有兴趣的朋友有所帮助。