国产一级a片免费看高清,亚洲熟女中文字幕在线视频,黄三级高清在线播放,免费黄色视频在线看

打開APP
userphoto
未登錄

開通VIP,暢享免費(fèi)電子書等14項超值服

開通VIP
nginx-tomcat負(fù)載均衡redis-session共享,靜態(tài)資源分離

nginx-tomcat負(fù)載均衡redis-session共享,靜態(tài)資源分離

 

基本環(huán)境:

redis-2.8

apache-tomcat-6.0.41

nginx1.6.2

1,redis配置

1,配置redis訪問密碼

redis的目錄下找的redis.conf,解開requirepass注釋(此屬性用于設(shè)置密碼)。

如:

requirepass root

2,啟動redis

redis的目錄以后臺運(yùn)行的方式啟動redis

 redis-server /root/redis-2.8.9/redis.conf &

2,tomcat準(zhǔn)備工作

1,準(zhǔn)備tomcat應(yīng)用服務(wù)器

部署一個應(yīng)用到tomcat,將里面的需要靜態(tài)處理的文件,例如img,單獨(dú)存放在一個文件夾下,如static下面。將用戶產(chǎn)生的媒體文件存放到一個共用的目錄下,如/data/media下。后面用nginx配置處理。

2,添加tomcatredissession共享的jar

tomcat自己的lib下添加session共享所需的jar包,需要注意tomcat的版本對應(yīng)。

 

commons-pool-1.6.jar

jedis-2.1.0.jar

tomcat-redis-session-manager-1.2-tomcat-6.jar

3,修改tomcatcontext.xml配置

tomcatconf目錄下找到context.xml配置文件,在標(biāo)簽<Context>下添加:

  1. <!-- 利用redis 進(jìn)行session 共享 -->  
  2. <Valve className="com.radiadesign.catalina.session.RedisSessionHandlerValve" />  
  3. <Manager className="com.radiadesign.catalina.session.RedisSessionManager"  
  4. host="127.0.0.1"  
  5. port="6379"  
  6. password="root"  
  7. database="0"  
  8. maxInactiveInterval="3600"/>  


 

提供的配置中默認(rèn)沒有password屬性,我們可以查看tomcat-redis-session-manager-1.2-tomcat-6.jar的源碼,可以在RedisSessionManager.class中找的password屬性。

 

 

4,復(fù)制tomcat修改各個tomcat的端口

配置完了tomcatredis共享的配置之后,我們就可以將此tomcat復(fù)制多份,然后修改tomcat的端口,如:

tomcat1Server port="8005",Connector port="8080",ajp Connector port="8009"

tomcat2Server port="8006"Connector port="8081",ajp Connector port="8010"

tomcat3Server port="8007",Connector port="8082",ajp Connector port="8011"

 

3,nginx配置

1,注釋默認(rèn)訪問

ngixnginx/conf.d/下有個default.conf,將里面的listen 80 default_server改為:

listen 80;

2,在添加需要負(fù)載的應(yīng)用服務(wù)器

ngixnginx/conf.d/的創(chuàng)建一個conf,如test.conf。在里面添加upstream pool配置段,將各個需要負(fù)載服務(wù)器的地址填到下面:

  1. upstream pool{  
  2.     server 127.0.0.1:8080;  
  3.     server 127.0.0.1:8081;  
  4.     server 127.0.0.1:8082;  
  5. }  


3,配置訪問域名

繼續(xù)在test.conf中添加:

  1. server {  
  2.     listen 80 default_server;  
  3.     server_name www.test.cn;  
  4.     gzip on;  
  5.     gzip_min_length  1k;  
  6.     gzip_buffers     4 16k;  
  7.     gzip_http_version 1.0;  
  8.     gzip_comp_level 2;  
  9.     gzip_types  text/plain application/x-javascript text/css application/xml;  
  10.     gzip_vary on;  
  11.     location / {  
  12.       proxy_set_header Host $host;  
  13.       proxy_set_header X-Forwarded-For $remote_addr;  
  14.       proxy_connect_timeout   3;  
  15.       proxy_send_timeout      30;  
  16.       proxy_read_timeout      30;  
  17.       proxy_pass http://pool;  
  18.   }  
  19.   error_page 500 502 503 504 /50x.html;  
  20.   location = /50x.html{  
  21.       root /home/workspace/server/apache-tomcat-6.0.41-8080/webapps/test;  
  22.   }  
  23.   if ($host != 'www.test.cn' ){  
  24.     rewrite ^/(.*)$ http://www.test.cn/$1 permanent;  
  25.   }  
  26.    
  27. }  


 

4,配置靜態(tài)資源訪問

  1. server {  
  2.      listen 80;  
  3.      server_name static.test.cn;  
  4.      location /static {  
  5.            root /home/workspace/server/apache-tomcat-6.0.41-8080/webapps/test;  
  6.      }  
  7.      location /media {  
  8.            root /home/workspace/file;  
  9.      }  
  10. }  


 

5,修改請求體的大小

http {}里增加 client_max_body_size屬性,此屬性會影響很多的地方,例如上傳。

client_max_body_size 100m;

 

 

4,啟動nginxtomcat,測試

測試負(fù)載均衡:

啟動nginx和所有tomcat,然后到網(wǎng)頁登錄,然后啟動另一個tomcat,關(guān)閉上一個。查看是否還能訪問。開啟所有tomcat用工具發(fā)起大量請求,查看請求是否被分發(fā)到各個tomcat。

 

測試session共享:

啟動nginx和一個tomcat,然后到網(wǎng)頁登錄,然后啟動另一個tomcat,關(guān)閉上一個。查看是否還在登錄狀態(tài)。

本站僅提供存儲服務(wù),所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點(diǎn)擊舉報
打開APP,閱讀全文并永久保存 查看更多類似文章
猜你喜歡
類似文章
利用nginx+tomcat+memcached組建web服務(wù)器負(fù)載均衡
Spring Boot 一個依賴搞定 session 共享,沒有比這更簡單的方案了!
java開發(fā)之Redis實(shí)現(xiàn)分布式Session管理
Nginx+tomcat集群并實(shí)現(xiàn)session共享(廣播機(jī)制、redis兩種方式)
CentOS6.5下Tomcat7 Nginx Redis配置步驟
負(fù)載均衡session共享的三種處理方法
更多類似文章 >>
生活服務(wù)
分享 收藏 導(dǎo)長圖 關(guān)注 下載文章
綁定賬號成功
后續(xù)可登錄賬號暢享VIP特權(quán)!
如果VIP功能使用有故障,
可點(diǎn)擊這里聯(lián)系客服!

聯(lián)系客服