我是靠谱客的博主 娇气银耳汤,这篇文章主要介绍Nginx1.1实现Resin4集群,现在分享给大家,希望可以做个参考。

Nginx1.1实现Resin4集群

  • 博客分类:
  • Tomcat6
 

一,web服务器小论

  以前的公司使用的web服务器是tomcat(tomcat+apache作集群),现在的公司是一家互联网公司,采用的架构是resin+nginx作集群(resin比tomcat快?还有待以后章节比较讨论),

 

 

集群配置服务器说明:

        1),serve1:127.0.0.1:8080

            2), serve2:127.0.0.1:8081

            3), nginx:127.0.0.1:80


二,配置resin服务器

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

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

  serve1:127.0.0.1:8080--->

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

Java代码 复制代码  收藏代码
  1. shell $> tar zxvf resin-4.0.23.tar.gz   
  2. shell $> cd resin-4.0.23  
  3. shell $> ./configure --prefix=/usr/resin/resinserver1/resinserver1/   
  4. shell $> make   
  5. shell $> make install  
复制代码
1
2
3
4
5
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代码 复制代码  收藏代码
  1. shell $> cd conf   
  2. shell $> vim resin.conf   
  3. ##  查找     <http address="*" port="8080"/>   
  4. ## 注释掉 <!--http address="*" port="8080"/-->   
  5. ## 查找      <server id="" address="127.0.0.1" port="6800">   
  6. ## 替换成       
  7.     <server id="resinserver1" address="127.0.0.1" port="6800">   
  8.      <!--<STRONG>两台服务器配置不同的watchdog端口,否则会出现异常</STRONG>-->   
  9.     <watchdog-port>6700</watchdog-port>   
  10.     <http id="" port="8080"/>   
  11.     </server>   
  12. ###重启  resin 服务#####   
  13. shell $> cd ../bin   
  14. shell $>./resin.sh -server resinserver1 start  
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
shell $> cd conf shell $> vim resin.conf ## 查找 <http address="*" port="8080"/> ## 注释掉 <!--http address="*" port="8080"/--> ## 查找 <server id="" address="127.0.0.1" port="6800"> ## 替换成 <server id="resinserver1" address="127.0.0.1" port="6800"> <!--两台服务器配置不同的watchdog端口,否则会出现异常--> <watchdog-port>6700</watchdog-port> <http id="" port="8080"/> </server> ###重启 resin 服务##### shell $> cd ../bin shell $>./resin.sh -server resinserver1 start

 serve1:127.0.0.1:8081--->

  ---1,

Java代码 复制代码  收藏代码
  1. shell $> tar zxvf resin-4.0.23.tar.gz   
  2. shell $> cd resin-4.0.23  
  3. shell $> ./configure --prefix=/usr/resin/resinserver2/resinserver2/   
  4. shell $> make   
  5. shell $> make install  
复制代码
1
2
3
4
5
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代码 复制代码  收藏代码
  1. shell $> vim resin.conf   
  2. ##  查找     <http address="*" port="8080"/>   
  3. ## 注释掉 <!--http address="*" port="8080"/-->   
  4. ## 查找      <server id="" address="127.0.0.1" port="6800">   
  5. ## 替换成       
  6.     <server id="resinserver2" address="127.0.0.1" port="6801">   
  7.      <!--两台服务器配置不同的watchdog端口-->   
  8.     <watchdog-port>6701</watchdog-port>   
  9.     <http id="" port="8081"/>   
  10.     </server>   
  11. ###重启  resin 服务#####   
  12. shell $> cd ../bin   
  13. shell $>./resin.sh -server resinserver2 start  
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
shell $> vim resin.conf ## 查找 <http address="*" port="8080"/> ## 注释掉 <!--http address="*" port="8080"/--> ## 查找 <server id="" address="127.0.0.1" port="6800"> ## 替换成 <server id="resinserver2" address="127.0.0.1" port="6801"> <!--两台服务器配置不同的watchdog端口--> <watchdog-port>6701</watchdog-port> <http id="" port="8081"/> </server> ###重启 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代码 复制代码  收藏代码
  1. shell $> cd nginx-1.1.5  
  2. shell $> patch -p0 < ../tbje-nginx-upstream-jvm-route-6016b39/jvm_route.patch   
  3. shell $> useradd www   
  4. 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   
  5. shell $> make   
  6. shell $> make install  
复制代码
1
2
3
4
5
6
7
8
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 访问http://127.0.0.1  出现“webcome to nginx”代表nginx安装成功

 

  四,配置集群

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

Java代码 复制代码  收藏代码
  1. user  www www;#工作进程的属主   
  2. worker_processes  2;#工作进程数,一般与 CPU 核数等同   
  3.   
  4. error_log  logs/error.log crit;   
  5. #error_log  logs/error.log  notice;   
  6. #error_log  logs/error.log  info;   
  7.   
  8. pid        logs/nginx.pid;   
  9.   
  10.   
  11. events {   
  12.     worker_connections  1024;#每个工作进程允许最大的同时连接数   
  13. }   
  14.   
  15.   
  16. http {   
  17.         upstream backend {#集群服务器   
  18.        server 127.0.0.1:8080 srun_id=resinserver1;    
  19.        server 127.0.0.1:8081 srun_id=resinserver2;   
  20.        jvm_route $cookie_JSESSIONID|sessionid;#session共享   
  21.        }   
  22.        
  23.     include       mime.types;#内定义各文件类型映像,也可使用   
  24.     default_type  application/octet-stream;#设置默认类型是二进制流   
  25.   
  26.     #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '  
  27.     #                  '$status $body_bytes_sent "$http_referer" '  
  28.     #                  '"$http_user_agent" "$http_x_forwarded_for"';   
  29.   
  30.     #access_log  logs/access.log  main;   
  31.   
  32.     sendfile        on;   
  33.     #tcp_nopush     on;   
  34.   
  35.     #keepalive_timeout  0;   
  36.     keepalive_timeout  65;   
  37.   
  38.     #gzip  on;#打开gzip文件压缩   
  39.   
  40.     server {   
  41.         listen       80;   
  42.         server_name  localhost;   
  43.   
  44.         charset UTF-8;   
  45.   
  46.     #下面为location的配置,可以根据自己的业务情况进行定制   
  47.         #access_log  logs/host.access.log  main;   
  48.         location / {   
  49.             root   html;   
  50.             index  index.html index.htm;   
  51.         }   
  52.   
  53.         #error_page  404              /404.html;   
  54.   
  55.         # redirect server error pages to the static page /50x.html   
  56.         #   
  57.         error_page   500 502 503 504  /50x.html;   
  58.         location = /50x.html {   
  59.             root   html;   
  60.         }   
  61.              location ~ .*.jsp$   
  62.        {   
  63.          proxy_pass  http://backend;   
  64.          proxy_redirect    off;   
  65.          proxy_set_header  X-Forwarded-For  $proxy_add_x_forwarded_for;   
  66.          proxy_set_header  X-Real-IP  $remote_addr;   
  67.          proxy_set_header  Host $http_host;   
  68.        }   
  69.        location ~ .*.(gif|jpg|jpeg|png|bmp|swf)$   
  70.        {   
  71.          expires      30d;   
  72.        }   
  73.        location ~ .*.(js|css)?$   
  74.        {   
  75.          expires      1h;   
  76.        }   
  77.   
  78.         # proxy the PHP scripts to Apache listening on 127.0.0.1:80  
  79.         #   
  80.         #location ~ .php$ {   
  81.         #    proxy_pass   http://127.0.0.1;   
  82.         #}   
  83.   
  84.         # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000  
  85.         #   
  86.         #location ~ .php$ {   
  87.         #    root           html;   
  88.         #    fastcgi_pass   127.0.0.1:9000;   
  89.         #    fastcgi_index  index.php;   
  90.         #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;   
  91.         #    include        fastcgi_params;   
  92.         #}   
  93.   
  94.         # deny access to .htaccess files, if Apache's document root   
  95.         # concurs with nginx's one   
  96.         #   
  97.         #location ~ /.ht {   
  98.         #    deny  all;   
  99.         #}   
  100.     }   
  101.   
  102.   
  103.     # another virtual host using mix of IP-, name-, and port-based configuration   
  104.     #   
  105.     #server {   
  106.     #    listen       8000;   
  107.     #    listen       somename:8080;   
  108.     #    server_name  somename  alias  another.alias;   
  109.   
  110.     #    location / {   
  111.     #        root   html;   
  112.     #        index  index.html index.htm;   
  113.     #    }   
  114.     #}   
  115.   
  116.   
  117.     # HTTPS server   
  118.     #   
  119.     #server {   
  120.     #    listen       443;   
  121.     #    server_name  localhost;   
  122.   
  123.     #    ssl                  on;   
  124.     #    ssl_certificate      cert.pem;   
  125.     #    ssl_certificate_key  cert.key;   
  126.   
  127.     #    ssl_session_timeout  5m;   
  128.   
  129.     #    ssl_protocols  SSLv2 SSLv3 TLSv1;   
  130.     #    ssl_ciphers  HIGH:!aNULL:!MD5;   
  131.     #    ssl_prefer_server_ciphers   on;   
  132.   
  133.     #    location / {   
  134.     #        root   html;   
  135.     #        index  index.html index.htm;   
  136.     #    }   
  137.     #}   
  138.   
  139. }  
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
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 http://backend; 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 http://127.0.0.1; #} # 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代码 复制代码  收藏代码
  1. start nginx   开启nginx   
  2.   
  3.   Nginx -s stop         快速关闭Nginx,可能不保存相关信息,并迅速终止web服务。(quick exit)   
  4.   Nginx -s quit         平稳关闭Nginx,保存相关信息,有安排的结束web服务。(graceful exit)   
  5.   Nginx -s reload       因改变了Nginx相关配置,需要重新加载配置而重载。(changing configuration,start a new worker,quitting an old worker gracefully.)   
  6.   Nginx -s reopen       重新打开日志文件。(reopenging log files)  
复制代码
1
2
3
4
5
6
7
8
9
10
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代码 复制代码  收藏代码
  1. <%@page language="java" import="java.util.*" pageEncoding="UTF-8"%>   
  2.         <%   
  3.         %>   
  4.         <html>   
  5.           <head>   
  6.             </head>   
  7.               <body>   
  8.                nginxserver1<!--在另一台服务器上写nginxserver2-->   
  9.                 <br />   
  10.                <%out.print(request.getSession()) ;%>   
  11.                 <br />   
  12.                 <%out.println(request.getHeader("Cookie")); %>   
  13.               </body>   
  14.          </html>  
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
<%@page language="java" import="java.util.*" pageEncoding="UTF-8"%> <% %> <html> <head> </head> <body> nginxserver1<!--在另一台服务器上写nginxserver2--> <br /> <%out.print(request.getSession()) ;%> <br /> <%out.println(request.getHeader("Cookie")); %> </body> </html>

  这时重启nginx

 

 这时访问:http://127.0.0.1/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  

最后

以上就是娇气银耳汤最近收集整理的关于Nginx1.1实现Resin4集群的全部内容,更多相关Nginx1内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(67)

评论列表共有 0 条评论

立即
投稿
返回
顶部