Chinaunix首页 | 论坛 | 博客
  • 博客访问: 253842
  • 博文数量: 48
  • 博客积分: 930
  • 博客等级: 准尉
  • 技术积分: 654
  • 用 户 组: 普通用户
  • 注册时间: 2011-09-28 12:31
文章分类

全部博文(48)

文章存档

2013年(10)

2012年(20)

2011年(18)

我的朋友

分类: LINUX

2011-12-31 13:36:29

集群配置服务器说明:

        1),serve1:127.0.0.1:8080

            2), serve2:127.0.0.1:8081

            3), nginx:127.0.0.1:80


二,配置resin服务器

  (注:resin4之前,可以搭一个服务器,在中配置多个server实例,通过实例启动,4.0之后就不可以了,要有专业版才能实现)

  在安装resin之前,必须先安装完jvm环境。

  serve1:127.0.0.1:8080--->

      1,安装resin-4.0.*.tar.gz包

Java代码
shell $> tar zxvf resin-4.0.23.tar.gz   
  1. shell $> cd resin-4.0.23  
  2. shell $> ./configure --prefix=/usr/resin/resinserver1/resinserver1/   
  3. shell $> make   
  4. shell $> make install  
shell $> tar zxvf resin-4.0.23.tar.gz shell $> cd resin-4.0.23 shell $> ./configure --prefix=/usr/resin/resinserver1/resinserver1/ shell $> make shell $> make install

   2,配置resin.conf文件

 shell $> cd /usr/resin/resinserver1/resinserver1/

Java代码
shell $> cd conf   
  1. shell $> vim resin.conf   
  2. ##  查找     "*" port="8080"/>   
  3. ## 注释掉    
  4. ## 查找      "" address="127.0.0.1" port="6800">   
  5. ## 替换成       
  6.     "resinserver1" address="127.0.0.1" port="6800">   
  7.         
  8.     6700   
  9.     "" port="8080"/>   
  10.        
  11. ###重启  resin 服务#####   
  12. shell $> cd ../bin   
  13. shell $>./resin.sh -server resinserver1 start  
shell $> cd conf shell $> vim resin.conf ## 查找 ## 注释掉 ## 查找 ## 替换成 6700 ###重启 resin 服务##### shell $> cd ../bin shell $>./resin.sh -server resinserver1 start

 serve1:127.0.0.1:8081--->

  ---1,

Java代码
shell $> tar zxvf resin-4.0.23.tar.gz   
  1. shell $> cd resin-4.0.23  
  2. shell $> ./configure --prefix=/usr/resin/resinserver2/resinserver2/   
  3. shell $> make   
  4. shell $> make install  
shell $> tar zxvf resin-4.0.23.tar.gz shell $> cd resin-4.0.23 shell $> ./configure --prefix=/usr/resin/resinserver2/resinserver2/ shell $> make shell $> make install

 2,配置resin

  shell $> cd conf

Java代码
shell $> vim resin.conf   
  1. ##  查找     "*" port="8080"/>   
  2. ## 注释掉    
  3. ## 查找      "" address="127.0.0.1" port="6800">   
  4. ## 替换成       
  5.     "resinserver2" address="127.0.0.1" port="6801">   
  6.         
  7.     6701   
  8.     "" port="8081"/>   
  9.        
  10. ###重启  resin 服务#####   
  11. shell $> cd ../bin   
  12. shell $>./resin.sh -server resinserver2 start  
shell $> vim resin.conf ## 查找 ## 注释掉 ## 查找 ## 替换成 6701 ###重启 resin 服务##### shell $> cd ../bin shell $>./resin.sh -server resinserver2 start

 通过以上配置,开启两台resin服务器,接下来就是配置nginx

 三,nginx的配置

      nginx安装需要以下软件包安装

  1,nginx-1.1.5.tar.gz

      2,tbje-nginx-upstream-jvm-route-6016b39.tar.gz

      3,openssl-1.0.0e.tar.gz(OPENSSL不需要编译安装,只需要解压出来就行)

  分别解压以上程序...

 

Java代码
shell $> cd nginx-1.1.5  
  1. shell $> patch -p0 < ../tbje-nginx-upstream-jvm-route-6016b39/jvm_route.patch   
  2. shell $> useradd www   
  3. shell $> ./configure --user=www --group=www --prefix=/usr/nginx/nginxserver --with-http_stub_status_module --with-http_ssl_module=/usr/nginx/openssl-1.0.0e  --add-module=/usr/nginx/tbje-nginx-upstream-jvm-route-6016b39   
  4. shell $> make   
  5. shell $> make install  
shell $> cd nginx-1.1.5 shell $> patch -p0 < ../tbje-nginx-upstream-jvm-route-6016b39/jvm_route.patch shell $> useradd www shell $> ./configure --user=www --group=www --prefix=/usr/nginx/nginxserver --with-http_stub_status_module --with-http_ssl_module=/usr/nginx/openssl-1.0.0e --add-module=/usr/nginx/tbje-nginx-upstream-jvm-route-6016b39 shell $> make shell $> make install

    到nginxserver/sbin目录下,,运行./nginx 访问  出现“webcome to nginx”代表nginx安装成功

 

  四,配置集群

   打开nginxserver/conf/nginx.conf文件。

Java代码
user  www www;#工作进程的属主   
  1. worker_processes  2;#工作进程数,一般与 CPU 核数等同   
  2.   
  3. error_log  logs/error.log crit;   
  4. #error_log  logs/error.log  notice;   
  5. #error_log  logs/error.log  info;   
  6.   
  7. pid        logs/nginx.pid;   
  8.   
  9.   
  10. events {   
  11.     worker_connections  1024;#每个工作进程允许最大的同时连接数   
  12. }   
  13.   
  14.   
  15. http {   
  16.         upstream backend {#集群服务器   
  17.        server 127.0.0.1:8080 srun_id=resinserver1;    
  18.        server 127.0.0.1:8081 srun_id=resinserver2;   
  19.        jvm_route $cookie_JSESSIONID|sessionid;#session共享   
  20.        }   
  21.        
  22.     include       mime.types;#内定义各文件类型映像,也可使用   
  23.     default_type  application/octet-stream;#设置默认类型是二进制流   
  24.   
  25.     #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '  
  26.     #                  '$status $body_bytes_sent "$http_referer" '  
  27.     #                  '"$http_user_agent" "$http_x_forwarded_for"';   
  28.   
  29.     #access_log  logs/access.log  main;   
  30.   
  31.     sendfile        on;   
  32.     #tcp_nopush     on;   
  33.   
  34.     #keepalive_timeout  0;   
  35.     keepalive_timeout  65;   
  36.   
  37.     #gzip  on;#打开gzip文件压缩   
  38.   
  39.     server {   
  40.         listen       80;   
  41.         server_name  localhost;   
  42.   
  43.         charset UTF-8;   
  44.   
  45.     #下面为location的配置,可以根据自己的业务情况进行定制   
  46.         #access_log  logs/host.access.log  main;   
  47.         location / {   
  48.             root   html;   
  49.             index  index.html index.htm;   
  50.         }   
  51.   
  52.         #error_page  404              /404.html;   
  53.   
  54.         # redirect server error pages to the static page /50x.html   
  55.         #   
  56.         error_page   500 502 503 504  /50x.html;   
  57.         location = /50x.html {   
  58.             root   html;   
  59.         }   
  60.              location ~ .*\.jsp$   
  61.        {   
  62.          proxy_pass  http://backend;   
  63.          proxy_redirect    off;   
  64.          proxy_set_header  X-Forwarded-For  $proxy_add_x_forwarded_for;   
  65.          proxy_set_header  X-Real-IP  $remote_addr;   
  66.          proxy_set_header  Host $http_host;   
  67.        }   
  68.        location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$   
  69.        {   
  70.          expires      30d;   
  71.        }   
  72.        location ~ .*\.(js|css)?$   
  73.        {   
  74.          expires      1h;   
  75.        }   
  76.   
  77.         # proxy the PHP scripts to Apache listening on 127.0.0.1:80  
  78.         #   
  79.         #location ~ \.php$ {   
  80.         #    proxy_pass   http://127.0.0.1;   
  81.         #}   
  82.   
  83.         # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000  
  84.         #   
  85.         #location ~ \.php$ {   
  86.         #    root           html;   
  87.         #    fastcgi_pass   127.0.0.1:9000;   
  88.         #    fastcgi_index  index.php;   
  89.         #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;   
  90.         #    include        fastcgi_params;   
  91.         #}   
  92.   
  93.         # deny access to .htaccess files, if Apache's document root   
  94.         # concurs with nginx's one   
  95.         #   
  96.         #location ~ /\.ht {   
  97.         #    deny  all;   
  98.         #}   
  99.     }   
  100.   
  101.   
  102.     # another virtual host using mix of IP-, name-, and port-based configuration   
  103.     #   
  104.     #server {   
  105.     #    listen       8000;   
  106.     #    listen       somename:8080;   
  107.     #    server_name  somename  alias  another.alias;   
  108.   
  109.     #    location / {   
  110.     #        root   html;   
  111.     #        index  index.html index.htm;   
  112.     #    }   
  113.     #}   
  114.   
  115.   
  116.     # HTTPS server   
  117.     #   
  118.     #server {   
  119.     #    listen       443;   
  120.     #    server_name  localhost;   
  121.   
  122.     #    ssl                  on;   
  123.     #    ssl_certificate      cert.pem;   
  124.     #    ssl_certificate_key  cert.key;   
  125.   
  126.     #    ssl_session_timeout  5m;   
  127.   
  128.     #    ssl_protocols  SSLv2 SSLv3 TLSv1;   
  129.     #    ssl_ciphers  HIGH:!aNULL:!MD5;   
  130.     #    ssl_prefer_server_ciphers   on;   
  131.   
  132.     #    location / {   
  133.     #        root   html;   
  134.     #        index  index.html index.htm;   
  135.     #    }   
  136.     #}   
  137.   
  138. }  
user www www;#工作进程的属主 worker_processes 2;#工作进程数,一般与 CPU 核数等同 error_log logs/error.log crit; #error_log logs/error.log notice; #error_log logs/error.log info; pid logs/nginx.pid; events { worker_connections 1024;#每个工作进程允许最大的同时连接数 } http { upstream backend {#集群服务器 server 127.0.0.1:8080 srun_id=resinserver1; server 127.0.0.1:8081 srun_id=resinserver2; jvm_route $cookie_JSESSIONID|sessionid;#session共享 } 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"'; #access_log logs/access.log main; sendfile on; #tcp_nopush on; #keepalive_timeout 0; keepalive_timeout 65; #gzip on;#打开gzip文件压缩 server { listen 80; server_name localhost; charset UTF-8;     #下面为location的配置,可以根据自己的业务情况进行定制 #access_log logs/host.access.log main; location / { root html; index index.html index.htm; } #error_page 404 /404.html; # redirect server error pages to the static page /50x.html # error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } location ~ .*\.jsp$ { proxy_pass proxy_redirect off; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Real-IP $remote_addr; proxy_set_header Host $http_host; } location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$ { expires 30d; } location ~ .*\.(js|css)?$ { expires 1h; } # proxy the PHP scripts to Apache listening on 127.0.0.1:80 # #location ~ \.php$ { # proxy_pass ; #} # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 # #location ~ \.php$ { # root html; # fastcgi_pass 127.0.0.1:9000; # fastcgi_index index.php; # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name; # include fastcgi_params; #} # deny access to .htaccess files, if Apache's document root # concurs with nginx's one # #location ~ /\.ht { # deny all; #} } # another virtual host using mix of IP-, name-, and port-based configuration # #server { # listen 8000; # listen somename:8080; # server_name somename alias another.alias; # location / { # root html; # index index.html index.htm; # } #} # HTTPS server # #server { # listen 443; # server_name localhost; # ssl on; # ssl_certificate cert.pem; # ssl_certificate_key cert.key; # ssl_session_timeout 5m; # ssl_protocols SSLv2 SSLv3 TLSv1; # ssl_ciphers HIGH:!aNULL:!MD5; # ssl_prefer_server_ciphers on; # location / { # root html; # index index.html index.htm; # } #} }

   nginx命令:

Java代码
start nginx   开启nginx   
  1.   
  2.   Nginx -s stop         快速关闭Nginx,可能不保存相关信息,并迅速终止web服务。(quick exit)   
  3.   Nginx -s quit         平稳关闭Nginx,保存相关信息,有安排的结束web服务。(graceful exit)   
  4.   Nginx -s reload       因改变了Nginx相关配置,需要重新加载配置而重载。(changing configuration,start a new worker,quitting an old worker gracefully.)   
  5.   Nginx -s reopen       重新打开日志文件。(reopenging log files)  
start nginx 开启nginx Nginx -s stop 快速关闭Nginx,可能不保存相关信息,并迅速终止web服务。(quick exit) Nginx -s quit 平稳关闭Nginx,保存相关信息,有安排的结束web服务。(graceful exit) Nginx -s reload 因改变了Nginx相关配置,需要重新加载配置而重载。(changing configuration,start a new worker,quitting an old worker gracefully.) Nginx -s reopen 重新打开日志文件。(reopenging log files)

 

 上面两resin的服务器已经打开,更改两服务器下的如(resinserver1):/usr/resin/resinserver1/resinserver1/webapps/ROOT 下的index.jsp

   区别服务器访问路径:

Java代码 <%@page language="java" import="java.util.*" pageEncoding="UTF-8"%>   
  1.         <%   
  2.         %>   
  3.            
  4.              
  5.                
  6.                  
  7.                nginxserver1   
  8.                    
  9.                <%out.print(request.getSession()) ;%>   
  10.                    
  11.                 <%out.println(request.getHeader("Cookie")); %>   
  12.                  
  13.            
<%@page language="java" import="java.util.*" pageEncoding="UTF-8"%> <% %> nginxserver1
<%out.print(request.getSession()) ;%>
<%out.println(request.getHeader("Cookie")); %>

  这时重启nginx

 

 这时访问:/index.jsp会出现以下情况:

Java代码
  1. 比较   
  2. resinserver1----->   
  3. nginxserver1    
  4. SessionImpl[aaadbhbcljrab7wtdprmt,]    
  5. JSESSIONID=aaadbhbcljrab7wtdprmt   
  6.   
  7. 或者   
  8. resinserver2----->   
  9. nginxserver2    
  10. SessionImpl[aaadbhbcljrab7wtdprmt,]    
  11. JSESSIONID=aaadbhbcljrab7wtdprmt 
阅读(9179) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~