西沙璞玉
          愛不容易
          posts - 0,comments - 4,trackbacks - 0

          一,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

          集群配置服務器說明:

              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
          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
          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
          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
          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
          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. error_log logs/error.log crit;
          4. #error_log logs/error.log notice;
          5. #error_log logs/error.log info;

          6. pid logs/nginx.pid;


          7. events {
          8. worker_connections 1024;#每個工作進程允許最大的同時連接數
          9. }


          10. http {
          11. upstream backend {#集群服務器
          12. server 127.0.0.1:8080 srun_id=resinserver1;
          13. server 127.0.0.1:8081 srun_id=resinserver2;
          14. jvm_route $cookie_JSESSIONID|sessionid;#session共享
          15. }

          16. include mime.types;#內定義各文件類型映像,也可使用
          17. default_type application/octet-stream;#設置默認類型是二進制流

          18. #log_format main '$remote_addr - $remote_user [$time_local] "$request" '
          19. # '$status $body_bytes_sent "$http_referer" '
          20. # '"$http_user_agent" "$http_x_forwarded_for"';

          21. #access_log logs/access.log main;

          22. sendfile on;
          23. #tcp_nopush on;

          24. #keepalive_timeout 0;
          25. keepalive_timeout 65;

          26. #gzip on;#打開gzip文件壓縮

          27. server {
          28. listen 80;
          29. server_name localhost;

          30. charset UTF-8;

          31.     #下面為location的配置,可以根據自己的業務情況進行定制
          32. #access_log logs/host.access.log main;
          33. location / {
          34. root html;
          35. index index.html index.htm;
          36. }

          37. #error_page 404 /404.html;

          38. # redirect server error pages to the static page /50x.html
          39. #
          40. error_page 500 502 503 504 /50x.html;
          41. location = /50x.html {
          42. root html;
          43. }
          44. location ~ .*\.jsp$
          45. {
          46. proxy_pass http://backend;
          47. proxy_redirect off;
          48. proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
          49. proxy_set_header X-Real-IP $remote_addr;
          50. proxy_set_header Host $http_host;
          51. }
          52. location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
          53. {
          54. expires 30d;
          55. }
          56. location ~ .*\.(js|css)?$
          57. {
          58. expires 1h;
          59. }

          60. # proxy the PHP scripts to Apache listening on 127.0.0.1:80
          61. #
          62. #location ~ \.php$ {
          63. # proxy_pass http://127.0.0.1;
          64. #}

          65. # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
          66. #
          67. #location ~ \.php$ {
          68. # root html;
          69. # fastcgi_pass 127.0.0.1:9000;
          70. # fastcgi_index index.php;
          71. # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
          72. # include fastcgi_params;
          73. #}

          74. # deny access to .htaccess files, if Apache's document root
          75. # concurs with nginx's one
          76. #
          77. #location ~ /\.ht {
          78. # deny all;
          79. #}
          80. }


          81. # another virtual host using mix of IP-, name-, and port-based configuration
          82. #
          83. #server {
          84. # listen 8000;
          85. # listen somename:8080;
          86. # server_name somename alias another.alias;

          87. # location / {
          88. # root html;
          89. # index index.html index.htm;
          90. # }
          91. #}


          92. # HTTPS server
          93. #
          94. #server {
          95. # listen 443;
          96. # server_name localhost;

          97. # ssl on;
          98. # ssl_certificate cert.pem;
          99. # ssl_certificate_key cert.key;

          100. # ssl_session_timeout 5m;

          101. # ssl_protocols SSLv2 SSLv3 TLSv1;
          102. # ssl_ciphers HIGH:!aNULL:!MD5;
          103. # ssl_prefer_server_ciphers on;

          104. # location / {
          105. # root html;
          106. # index index.html index.htm;
          107. # }
          108. #}

          109. }
          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. 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代碼 復制代碼 收藏代碼
          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>
          <%@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. resinserver2----->
          8. nginxserver2
          9. SessionImpl[aaadbhbcljrab7wtdprmt,]
          10. JSESSIONID=aaadbhbcljrab7wtdprmt
          參考文章

          自我總結:
          1,下面這個端口號也要變,不然只能啟動一個resin實例(未解)
          <!-- SSL port configuration: -->
                <http address="*" port="8444">
                  <jsse-ssl self-signed-certificate-name="resin@localhost"/>
                </http>
          2,上面那兩個軟件windows中不能安裝,會報異常,改成以下配置,
           upstream backend {   
                 server 127.0.0.1:8080 ;     
                 server 127.0.0.1:8081;    
                
                 }   
          nginx_upstream_jvm_route 是一個 Nginx 的擴展模塊,用來實現基于 Cookie 的 Session Sticky 的功能。
                      session replication 策略是復制會話,即一個用戶訪問了一次就把session復制到所有的服務器或這一部分服務器。
          這樣的好處是如果正訪問的服務器down了 用戶可以自動被轉到別的服務器session不丟失。缺點當然是效率低。
                       session sticky策略則是不復制,一個用戶訪問了一次后,同一個session周期內,所有的請求都定向到這個服務器,
          down了session就丟了。
          3,啟動不同服務名稱的resin實例時,要到命令行去,不然不知道啟動哪個,報異常。

          G:\javaWeb\resin-pro-2\bin\目錄:
          start.bat -server resinserver2 start

          posted on 2012-03-26 17:55 @趙 閱讀(1807) 評論(0)  編輯  收藏

          只有注冊用戶登錄后才能發表評論。


          網站導航:
           
          哥哥最近不是很忙
          主站蜘蛛池模板: 礼泉县| 博客| 香河县| 金平| 岢岚县| 百色市| 泗洪县| 开封县| 青铜峡市| 浦东新区| 两当县| 喀喇沁旗| 襄樊市| 怀集县| 丽江市| 修文县| 道真| 出国| SHOW| 永胜县| 湘阴县| 铜鼓县| 霸州市| 沁源县| 和顺县| 拜城县| 长葛市| 壶关县| 安仁县| 额济纳旗| 平武县| 宁乡县| 大城县| 禹州市| 汉阴县| 巢湖市| 郑州市| 宣威市| 大宁县| 海阳市| 巫山县|