系统环境:
Varnish-server centos 5.8 192.168.0.131
Web-server centos 5.8 192.168.0.202
1:Varnish server准备:
建立Varnish用户以及用户组,并且创建Varnish缓存目录和日志目录:
[root@varnish-server ~]# useradd -s /sbin/nologin varnish
[root@varnish-server ~]# mkdir -pv /data/varnish/{cache,log}
[root@varnish-server ~]# chown -R varnish:varnish /data/varnish/{cache,log}
2:获取Varnish软件:
Varnish的官方网址:http://varnish-cache.org可以获取,此处安装的是varnish-2.1.2.tar.gz
3:安装pcre:
如果没有安装pcre,在编译varnish2.0以上版本时,会提示找不到pcre库,而pcre库是为了兼容正则表达式,所以必须安装pcre库。
[root@varnish-server ~]# tar zxvf pcre-7.9.tar.gz
[root@varnish-server ~]# cd pcre-7.9
[root@varnish-server pcre-7.9]# ./configure --prefix=/usr/local/pcre/ && make && make install
4:安装Varnish:
[root@varnish-server ~]# tar zxvf varnish-2.1.2.tar.gz
[root@varnish-server ~]# cd varnish-2.1.2
[root@varnish-server varnish-2.1.2]# export PKG_CONFIG_PATH=/usr/local/pcre/lib/pkgconfig
[root@varnish-server varnish-2.1.2]# ./configure --prefix=/usr/local/varnish \
> --enable-dependency-tracking \
> --enable-debugging-symbols \
> --enable-developer-warnings
[root@varnish-server varnish-2.1.2]# make && make install
[root@varnish-server varnish-2.1.2]# cp redhat/varnish.initrc /etc/init.d/varnish
[root@varnish-server varnish-2.1.2]# cp redhat/varnish.sysconfig /etc/sysconfig/varnish
#################################################################
其中:PKG_CONFIG_PATH是指定pcre库的路径
#################################################################
5:配置一个简单的实例:
Varnish安装完成后,默认的配置文件为:/usr/local/varnish/etc/varnish/default.vcl
此文件内容默认全部被注释。
[root@varnish-server ~]# cp /usr/local/varnish/etc/varnish/default.vcl /usr/local/varnish/etc/vcl.conf