3.1 安装nginx所需的pcre
tar xvzf pcre-8.12.tar.gz cd pcre
-8.12./configure make
&& make install
也可以采用yum方式安装
yum -y install pcre-devel
3.2 安装nginx
tar xvzf nginx-0.8.51.tar.gz cd nginx
-0.8.51./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module make
&& make install
这里为了简单没有加入user和group信息,如果加入命令如下:
./configure --user=www --group=www --prefix=/usr/local/webserver/nginx --with-http_stub_status_module --with-http_ssl_module 如果不安装pcre则会提示
./configure: error: the HTTP rewrite module requires the PCRE library.
3.3 配置nginx
user nobody; worker_processes
1; error_log logs
/error.log info;#pid logs/nginx.pid; events
{use epoll; worker_connections
1024;} http
{ include mime
.types; default_type application
/octet-stream; log_format main
'$remote_addr - $remote_user [$time_local] "$request" ''$status $body_bytes_sent "$http_referer" ''"$http_user_agent" "$http_x_forwarded_for"'; sendfile on
; keepalive_timeout
65;#设置Web缓存区名称为cache_one,内存缓存空间大小为100MB,1天没有被访问的内容自动清除,硬盘缓存空间大小为1GB proxy_cache_path
/usr/local/nginx/cache_data levels=1:2 keys_zone=cache_one:100m inactive=1d max_size=1g; upstream www
.test.com {#ip_hash策略将同一IP的所有请求都转发到同一应用服务器 ip_hash
; server localhost
:8080; server localhost
:8081;} server
{ listen
80; server_name localhost
; charset utf
-8; location
/{ root html
; index index
.html index.htm; proxy_pass http
://www.test.com; proxy_set_header X
-Real-IP $remote_addr; client_max_body_size
100m;} error_page
500502503504/50x.html; location
~*\.(gif|jpg|jpeg|png|bmp)$ { proxy_cache cache_one
; proxy_cache_valid
2003023041h; proxy_cache_key $host$uri$is_args$args
; proxy_pass http
://www.test.com; add_header
Last-Modified $date_gmt; add_header
Via $server_addr; expires
30d;}}}
3.4 安装jdk1.6
不详细说明了,如不清楚,请google
3.5 安装两个tomcat6
tar xvzf apache-tomcat-6.0.20.tar.gz mv apache
-tomcat-6.0.20/usr/local/tomcat6 cd
/usr/local cp
-r tomcat6/ tomcat6_1
修改tomcat6_1中的端口配置避免两个tomcat启动时端口冲突
执行命令
vi /usr/local/tomcat6_1/conf/server.xml 修改
............
============完成上面既可以实现负载均衡======
3.6 配置tomcat集群实现session共享
修改server.xml配置tomcat集群
修改Engine部分配置
修改Cluster部分配置
windows默认情况下是开通组播服务的,但是linux默认情况下并没有开通,可以通过指令打开
route add -net 224.0.0.0 netmask 240.0.0.0 dev eth0 发布testWeb测试工程,启动两个tomcat
/usr/local/tomcat6/bin/startup.sh/usr/local/tomcat6_1/bin/startup.sh 如果tomcat日志中出现
WARNING:Manager[localhost#/testWeb], requesting session state from org
.apache.catalina.tribes.membership.MemberImpl[tcp://{-64, -88, 92, -127}:4000,{-64,-88,92,-127},4000, alive=24591,id={-7829-87-33-65-11270-58-10275-1041110668-3-67}, payload={}, command={}, domain={},].This operation will timeout
ifno session state has been received within 60 seconds. 表示session共享正常