部分内容转自:http://hi.baidu.com/supermfc/blog/item/21e74638f1f576feb311c71b.html
1、Pcre的安装 (PERL兼容正则表达式库)
wget http://cdnetworks-kr-1.dl.sourceforge.net/project/pcre/pcre/8.02/pcre-8.02.tar.bz2tar zxvf pcre-8.02.tar.gz
cd pcre-8.02
./configure --libdir=/usr/lib
make && make install
如果没有安装Pcre,configure varnish2.0以上版本时候,会提示找不到pcre库
2、varnish 安装
wget http://cdnetworks-kr-2.dl.sourceforge.net/project/varnish/varnish/2.1.3/varnish-2.1.3.tar.gz
tar zxvf varnish-2.1.1
cd varnish-2.1.1
./configure --prefix=/usr/local/varnish
make && make install
3、varnish启动
usage: varnishd [options]
-a address:port # HTTP listen address and port
-b address:port # backend address and port
# -b <hostname_or_IP>
# -b '<hostname_or_IP>:<port_or_service>'
-C # print VCL code compiled to C language
-d # debug
-f file # VCL script
-F # Run in foreground
-h kind[,hashoptions] # Hash specification
# -h simple_list
# -h classic [default]
# -h classic,<buckets>
-i identity # Identity of varnish instance
-l bytesize # Size of shared memory log
-M address:port # CLI-master to connect to.
-n dir # varnishd working directory
-P file # PID file
-p param=value # set parameter
-s kind[,storageoptions] # Backend storage specification
# -s malloc
# -s file [default: use /tmp]
# -s file,<dir_or_file>
# -s file,<dir_or_file>,<size>
# -s file,<dir_or_file>,<size>,<granularity>
-t # Default TTL
-S secret-file # Secret file for CLI authentication
-T address:port # Telnet listen address and port
-V # version
-w int[,int[,int]] # Number of worker threads
# -w <fixed_count>
# -w min,max
# -w min,max,timeout [default: -w2,500,300]
-u user # Priviledge separation user id
sbin/varnishd -a :8080 -n logs -f etc/varnish/default.vcl -T localhost:6082 -p thread_pools 8 -p first_byte_timeout 20 -p between_bytes_timeout 10m -s malloc,100m
4、varnish配置
backend test {
.host = "102.21011.81.309";
.port = "8080";
.probe = {
.url = "/index.jsp";
.interval = 5s;
.timeout = 8 s;
.window = 5;
.threshold = 3;
}
}
director baz1 round-robin{
{
.backend = test;
}
}
sub vcl_recv {
set req.backend = baz1;
/* add x-forwarded-for */
if (req.http.x-forwarded-for) {
set req.http.X-Forwarded-For =
req.http.X-Forwarded-For ", " client.ip;
} else {
set req.http.X-Forwarded-For = client.ip;
}
/* ignore invalid request */
if (req.request != "GET" &&
req.request != "HEAD" &&
req.request != "PUT" &&
req.request != "POST" &&
req.request != "TRACE" &&
req.request != "OPTIONS" &&
req.request != "DELETE") {
/* Non-RFC2616 or CONNECT which is weird. */
return (pipe);
}
if (req.request != "GET" && req.request != "HEAD") {
/* We only deal with GET and HEAD by default */
return (pass);
}
if (req.http.Authorization || req.http.Cookie) {
/* Not cacheable by default */
return (pass);
}
/* // need cache turn on return (lookup);*/
return (pass);
}
sub vcl_pipe {
set req.http.connection = "close";
return (pipe);
}
sub vcl_deliver {
set resp.http.Server = "是";
return (deliver);
}
5、用apache ab进行测试
ab -n100000 -c1000 http://192.168.1.128:8080/index.jsp
Benchmarking 192.168.1.128(be patient)
Completed 10000 requests
Completed 20000 requests
Completed 30000 requests
Completed 40000 requests
Completed 50000 requests
Completed 60000 requests
Completed 70000 requests
Completed 80000 requests
Completed 90000 requests
Completed 100000 requests
Finished 100000 requests
Server Software: Apache-Coyote/1.1
Server Hostname: 10.210.71.30
Server Port: 8080
Document Path: /index.jsp
Document Length: 8248 bytes
Concurrency Level: 1000
Time taken for tests: 97.820 seconds
Complete requests: 100000
Failed requests: 0
Write errors: 0
Total transferred: 838287304 bytes
HTML transferred: 825560634 bytes
Requests per second: 1022.28 [#/sec] (mean)
Time per request: 978.205 [ms] (mean)
Time per request: 0.978 [ms] (mean, across all concurrent requests)
Transfer rate: 8368.80 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 575 1925.0 108 45128
Processing: 9 377 624.8 224 13631
Waiting: 7 223 501.8 107 13230
Total: 12 953 2061.8 339 45373
Percentage of the requests served within a certain time (ms)
50% 339
66% 360
75% 415
80% 620
90% 3230
95% 3439
98% 9209
99% 9459
100% 45373 (longest request)
未完待续.....