第一步 、配置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.