Centos 6.7 x64安装varnish-4.0.3

操作系统:CentOS-6.7-x86_64 中文 最小化安装

安装varnish依赖环境

yum install -y gcc gcc-c++ autoconf automake jemalloc-devel libedit-devel pcre-devel libtool ncurses-devel pcre-devel pkgconfig python-docutils python-sphinx graphviz
yum install -y https://mirrors.junlins.site/varnish/jemalloc-3.6.0-1.el6.x86_64.rpm
yum install -y https://mirrors.junlins.site/varnish/jemalloc-devel-3.6.0-1.el6.x86_64.rpm

安装pcre

wget https://mirrors.junlins.site/oneinstack/src/pcre-8.38.tar.gz
tar zxf pcre-8.38.tar.gz 
cd pcre-8.38
./configure
make
make install
cd ..
下载并安装varnish-4.0.3.tar.gz 

 
wget https://mirrors.junlins.site/varnish/varnish-4.0.3.tar.gz
tar zxf varnish-4.0.3.tar.gz 
cd varnish-4.0.3
./autogen.sh
./configure --prefix=/usr/local/varnish PKG_CONFIG_PATH=/usr/local/lib/pkgconfig
make
make install

创建varnish使用的用户

useradd -M -s /sbin/nologin varnish
创建varnish配置文件目录及相关目录
mkdir /etc/varnish
mkdir /var/log/varnish
从源码包复制varnish启动脚本及相关文件
cp redhat/varnish.initrc /etc/init.d/varnish
cp redhat/varnishlog.initrc /etc/init.d/varnishlog
cp redhat/varnishncsa.initrc /etc/init.d/varnishncsa
chmod +x /etc/init.d/varnish
chmod +x /etc/init.d/varnishlog
chmod +x /etc/init.d/varnishncsa
chkconfig --add varnish
chkconfig --add varnishlog
chkconfig --add varnishncsa
chkconfig varnish on
chkconfig varnishlog on
chkconfig varnishncsa on
cp redhat/varnish.sysconfig /etc/sysconfig/varnish
cp etc/example.vcl /etc/varnish/default.vcl
cp etc/builtin.vcl /etc/varnish/builtin.vcl
cp redhat/varnish_reload_vcl /usr/local/varnish/sbin/varnish_reload_vcl
chmod +x /usr/local/varnish/sbin/varnish_reload_vcl
创建secret文件
echo "secret" > /etc/varnish/secret
chmod 600 /etc/varnish/secret

配置varnish启动脚本

sed -i 's/^exec=.*$/exec="\/usr\/local\/varnish\/sbin\/varnishd"/' /etc/init.d/varnish
sed -i 's/^reload_exec=.*$/reload_exec="\/usr\/local\/varnish\/bin\/varnishncsa"/' /etc/init.d/varnish
sed -i 's/^exec=.*$/exec="\/usr\/local\/varnish\/bin\/varnishlog"/' /etc/init.d/varnishlog
sed -i 's/^exec=.*$/exec="\/usr\/local\/varnish\/bin\/varnishncsa"/' /etc/init.d/varnishncsa

维护varnish

service varnish {start|stop|status|restart|condrestart|try-restart|reload|force-reload}
service varnishlog {start|stop|status|restart|condrestart|try-restart|reload|force-reload}
service varnishncsa {start|stop|status|restart|condrestart|try-restart|reload|force-reload}
Top