相关文章

服务器托管CentOS 6.x 编译安装varnish 3.x

.安装约定 先找一台服务器租用 或服务器托管,或一台云主机,然后安装好centos开始测试

2.软件下载地址

3.下载源代码包

# cd /usr/local/src/

4.安装gcc、make等

# yum -y install gcc gcc-c make autoconf automake

5.安装编译所需的库

# yum -y install automake autoconf libtool ncurses-devel libxslt groff pcre-devel pkgconfig readline-devel

6.添加varnish用户和组

# groupadd varnish

# useradd -g varnish -c "Varnish Cache" -d /var/lib/varnish -s /sbin/nologin varnish

7.安装varnish

# cd ..

# tar zxvf varnish-3.0.5.tar.gz

# cd varnish-3.0.5

# ./configure --prefix=/usr/local/varnish

# sh autogen.sh

# make

# make install

8.varnish启动配置

# cp redhat/varnish.initrc /etc/init.d/varnish

# cp redhat/varnish.sysconfig /etc/sysconfig/varnish

# cp redhat/varnish_reload_vcl /usr/local/varnish/bin

编辑varnish启动参数配置文件

# vim /etc/sysconfig/varnish

VARNISH_VCL_CONF=/usr/local/varnish/etc/varnish/default.vcl

VARNISH_LISTEN_PORT=80

VARNISH_SECRET_FILE=/usr/local/varnish/etc/varnish/secret

修改启动服务

# vim /etc/init.d/varnish

exec="/usr/local/varnish/sbin/varnishd"

reload_exec="/usr/local/varnish/bin/varnish_reload_vcl"

VARNISHADM="/usr/local/varnish/bin/varnishadm $secret -T $VARNISH_ADMIN_LISTEN_ADDRESS:$VARNISH_ADMIN_LISTEN_PORT"

# uuidgen > /usr/local/varnish/etc/varnish/secret

# chmod 644 /usr/local/varnish/etc/varnish/secret

10.添加环境变量

# vim /etc/profile

在其文件末尾添加如下变量

或者用以下命令添加

运行如下命令使环境变量生效

# source /etc/profile

11.配置开机启动

# chkconfig varnish on

12.检查vcl配置是否正确

# service varnish configtest

# /usr/local/varnish/sbin/varnishd -C -f /usr/local/varnish/etc/varnish/default.vcl

13.启动varnish

# service varnish start

14.动态加载vcl配置

# service varnish reload

15.开启日志记录

# cp redhat/varnishncsa.initrc /etc/init.d/varnishncsa

# chmod x /etc/init.d/varnishncsa

修改启动服务

exec="/usr/local/varnish/bin/varnishncsa"

配置开机启动

# chkconfig varnishncsa on

启动varnishncsa

# service varnishncsa start

16.配置日志轮询

# vim /etc/logrotate.d/varnish

/var/log/varnish/*.log {

daily

rotate 30

missingok

notifempty

sharedscripts

delaycompress

dateext

dateformat .%Y%d%m

postrotate

/bin/kill -HUP `cat /var/run/varnishlog.pid 2>/dev/null` 2> /dev/null || true

/bin/kill -HUP `cat /var/run/varnishncsa.pid 2>/dev/null` 2> /dev/null || true

endscript

}

17.日志轮询debug测试

# logrotate -df /etc/logrotate.d/varnish