负载均衡及会话保存(Ofbiz框架)

第一步 、配置varnish


1.       Config the startup file  ,edit the file “varnishd_xxx.bat ” in folder “bin” , the file name can be anything you want, you can create a new file if the file don’t exsit.

The content of the file is like :

e:

cd e:\soft\varnish-3.0.2\bin

set PATH=%CD%;%PATH%

varnishd -a :80 -T :8888 -f /etc/eric.vcl -s malloc,500M

pause


top three lines config the path of varnish , then congfig the varnish startup property

-f /etc/eric.vcl 

表示varnish当前使用的配置文件

 

-s malloc,500M

表示给varnish分配500M内存存储空间

-T :8888

varnish 管理界面端口


-a :80

varnish监听80端口


2.  Edit the configuration file for varnish

Edit the file “/etc/eric.vcl” which set in the startup file, the content is like:

# This is a basic VCL configuration file for varnish.  See the vcl(7)

# man page for details on VCL syntax and semantics.

#

# Default backend definition.  Set this to point to your content

# server.

# 配置轮询的服务器信息

backend web01 { 

               .host = "127.0.0.1"; 

               .port = "8080";

                       

backend web02 { 

               .host = "10.221.133.10"; 

               .port = "8080"; 

 

backend web03 { 

               .host = "10.221.133.16"; 

               .port = "8080"; 


}  

director load round-robin { 

       { 

               .backend = web01; 

       } 

       { 

               .backend = web02; 

       } 

       { 

               .backend = web03; 

       } 

#如果varnish服务器接收到的访问请求是localhost,那么就将这个访问请求转发到load组,并利用RR算法对load组内的服务器进行轮询访问。

sub vcl_recv { 

               if (req.http.host ~ "localhost") { 

                       set req.backend=load; 

               } 

 

sub vcl_fetch { 

               set beresp.ttl=30s; 

               return (deliver); 

sub vcl_recv { 

               if ( (req.request=="GET" || req.request=="HEAD") && req.url ~ "\.(png|gif|jpeg|swf|css|js|html)$"){ 

                       return (lookup); 

               } 

               else { 

               return (pass); 

               } 

sub vcl_deliver { 

               if (obj.hits>0) { 

                       set resp.http.X-Cache="HIT"; 

               } 

               else { 

                       set resp.http.X-Caceh="MISS"; 

               } 

#acl purge_acl { 

#               "localhost"; 

#} 

#sub vcl_recv { 

#               if (req.request=="PURGE") { 

#                             if ( ! client.ip ~ purge_acl) { 

#                             error 405 "Not Allow!"; 

#                             } 

#               purge_url (req.url); 

#               error 200 "Purged"; 

#               } 

#}


3.       Run the  ““varnishd_xxx.bat ” and visit “localhost”, you can see the project ,if one server down , varnish will visit another server in the list. 

第二步、给tomcat配置memcached



1、1、 startup memcached.exe,use telnet to test port.         

2、put java_memcached-release_1.5.1.jar,tomcatmemsession.jar and commons-logging.jar  to the lib folder of tomcat.

3、3、 Modify the contex.xml in the conf folder as below,

<Manager className="de.javakaffee.web.msm.MemcachedBackupSessionManager" memcachedNodes="n1:xxx.xxxx.xxxx.xxx:11211"> 

</Manager>


第三步、将ofbiz配置到外部tomcat上(ofbiz原来自带的内部的tomcat)

1.Generate configuration files

Using command “java –jar ofbiz.jar –setup tomcat6” under ofbiz home directory, the configuration files will be generated in setup directory

2.Replace the same files in tomcat with generated file

In catalina.bat, delete the “%JAVA_OPTS%” in “set java_opts=%JAVA_OPTS% -Djava.xxxxxx”

Add -Dfile.encoding=UTF-8 for displaying Chinese character.

In catalina.properties , change ‘f://’  to  ‘f:’.

3.Start catalina

Using Catalina run in command line

第四部、开启ofbiz并测试

1、 Start  ofbiz on PC1(IP:10.158.121.11)  and PC2(IP:10.158.121.12)  ,and memcached was deployed on PC2, varnish deployed on PC1.

PC1 varnish configuration:

backend web01 { 

               .host = "10.158.121.11";  //PC1

               .port = "8080";

                       

backend web02 { 

               .host = "10.158.121.12";  //PC2

               .port = "8080"; 

 

PC1 and PC2 memcached for tomcat configuration:

<Manager className="de.javakaffee.web.msm.MemcachedBackupSessionManager" memcachedNodes="n1: 10.158.121.12:11211"> 

    </Manager>


2、 Login and Add  a shopping to shopping cart  on PC1 and shutdown the tomcat on PC1.

3、 Continue to view web on PC1 ,you will find the session was stored and you can continue shopping. 


转载于:https://my.oschina.net/u/993504/blog/111190

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值