在 CentOS 下安装 Varnish Cache
RedHat/CentOS 系统环境下 varnish 的依赖关系
如果您是 RedHat/CentOS 系统想安装 varnish,您需要安装以下软件包:
- automake
- autoconf
- libtool
- ncurses-devel
- libxslt
- groff
- pcre-devel
- pkgconfig
以下是在配置好 yum 包管理器的情况下运行
yum install -y automake autoconf libtool ncurses-devel libxslt groff pcre-devel pkgconfig
[root@node18 ~]# yum install -y automake autoconf libtool ncurses-devel libxslt groff pcre-devel pkgconfig
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.grandcloud.cn
* extras: mirrors.grandcloud.cn
* updates: mirrors.grandcloud.cn
Setting up Install Process
Package automake-1.9.6-2.3.el5.noarch already installed and latest version
Package autoconf-2.59-12.noarch already installed and latest version
Package libtool-1.5.22-7.el5_4.i386 already installed and latest version
Package ncurses-devel-5.5-24.20060715.i386 already installed and latest version
Package libxslt-1.1.17-4.el5_8.3.i386 already installed and latest version
Package groff-1.18.1.1-13.el5.i386 already installed and latest version
Package pcre-devel-6.6-6.el5_6.1.i386 already installed and latest version
Package 1:pkgconfig-0.21-2.el5.i386 already installed and latest version
Nothing to do
[root@node18 ~]#
下载varnish源代码并编译安装
mkdir varnish_setup cd varnish_setup/ wget http://repo.varnish-cache.org/source/varnish-2.1.5.tar.gz tar zxf varnish-2.1.5.tar.gz cd varnish-2.1.5 ./autogen.sh ./configure --prefix=/usr make cd bin/varnishtest && ./varnishtest tests/*.vtc # <== 这一步执行测试,很费时,可省略 cd ../.. # <=== 如果执行了测试,否则执行安装 make install
注意:本文的安装与默认安装不同
varnishd将被安装到 /usr/sbin/varnishd
配置文件 /usr/etc/varnish/default.vcl
下面是安装的详细记录:
[root@node18 ~]# mkdir varnish_setup [root@node18 ~]# cd varnish_setup/ [root@node18 varnish_setup]# wget http://repo.varnish-cache.org/source/varnish-2.1.5.tar.gz --2012-11-20 10:23:32-- http://repo.varnish-cache.org/source/varnish-2.1.5.tar.gz 正在解析主机 repo.varnish-cache.org... 194.31.39.155 Connecting to repo.varnish-cache.org|194.31.39.155|:80... 已连接。 已发出 HTTP 请求,正在等待回应... 200 OK 长度:1530856 (1.5M) [application/x-gzip] Saving to: `varnish-2.1.5.tar.gz' 100%[======================================>] 1,530,856 51.2K/s in 20s 2012-11-20 10:23:53 (73.2 KB/s) - `varnish-2.1.5.tar.gz' saved [1530856/1530856] [root@node18 varnish_setup]#
[root@node18 varnish_setup]# tar zxf varnish-2.1.5.tar.gz [root@node18 varnish_setup]# cd varnish-2.1.5 [root@node18 varnish-2.1.5]# ls aclocal.m4 config.guess depcomp install-sh Makefile.in varnishapi.pc.in autogen.sh config.h.in doc lib man bin config.sub etc LICENSE missing ChangeLog configure include ltmain.sh README compile configure.ac INSTALL Makefile.am redhat [root@node18 varnish-2.1.5]#
[root@node18 varnish-2.1.5]# ./autogen.sh + aclocal + libtoolize --copy --force + autoheader + automake --add-missing --copy --foreign + autoconf [root@node18 varnish-2.1.5]# ./configure --prefix=/usr checking build system type... i686-redhat-linux-gnu checking host system type... i686-redhat-linux-gnu checking target system type... i686-redhat-linux-gnu checking for a BSD-compatible install... /usr/bin/install -c checking whether build environment is sane... yes checking for gawk... gawk checking whether make sets $(MAKE)... yes checking for gcc... gcc checking for C compiler default output file name... a.out checking whether the C compiler works... yes
...
configure: creating ./config.status
config.status: creating Makefile
config.status: creating bin/Makefile
config.status: creating bin/varnishadm/Makefile
config.status: creating bin/varnishd/Makefile
config.status: creating bin/varnishlog/Makefile
config.status: creating bin/varnishhist/Makefile
config.status: creating bin/varnishncsa/Makefile
config.status: creating bin/varnishreplay/Makefile
config.status: creating bin/varnishstat/Makefile
config.status: creating bin/varnishsizes/Makefile
config.status: creating bin/varnishtest/Makefile
config.status: creating bin/varnishtop/Makefile
config.status: creating doc/Makefile
config.status: creating doc/sphinx/Makefile
config.status: creating etc/Makefile
config.status: creating include/Makefile
config.status: creating lib/Makefile
config.status: creating lib/libvarnish/Makefile
config.status: creating lib/libvarnishapi/Makefile
config.status: creating lib/libvarnishcompat/Makefile
config.status: creating lib/libvcl/Makefile
config.status: creating lib/libjemalloc/Makefile
config.status: creating man/Makefile
config.status: creating redhat/Makefile
config.status: creating varnishapi.pc
config.status: creating config.h
config.status: executing depfiles commands
[root@node18 varnish-2.1.5]# make
make all-recursive
make[1]: Entering directory `/root/varnish_setup/varnish-2.1.5'
Making all in include
make[2]: Entering directory `/root/varnish_setup/varnish-2.1.5/include'
make[2]: Nothing to be done for `all'.
make[2]: Leaving directory `/root/varnish_setup/varnish-2.1.5/include'
Making all in lib
make[2]: Entering directory `/root/varnish_setup/varnish-2.1.5/lib'
Making all in libvarnishcompat
make[3]: Entering directory `/root/varnish_setup/varnish-2.1.5/lib/libvarnishcompat'
if /bin/sh http://www.cnblogs.com/libtool --tag=CC --mode=compile gcc -DHAVE_CONFIG_H -I. -I. -I../.. -Ihttp://www.cnblogs.com/include -g -O2 -MT daemon.lo -MD -MP -MF ".deps/daemon.Tpo" -c -o daemon.lo daemon.c; \
then mv -f ".deps/daemon.Tpo" ".deps/daemon.Plo"; else rm -f ".deps/daemon.Tpo"; exit 1; fi
mkdir .libs
gcc -DHAVE_CONFIG_H -I. -I. -I../.. -Ihttp://www.cnblogs.com/include -g -O2 -MT daemon.lo -MD -MP -MF .deps/daemon.Tpo -c daemon.c -fPIC -DPIC -o .libs/daemon.o
...
mkdir .libs gcc -g -O2 -o .libs/varnishsizes varnishsizes.o http://www.cnblogs.com/lib/libvarnish/.libs/libvarnish.so -lrt -lnsl http://www.cnblogs.com/lib/libvarnishcompat/.libs/libvarnishcompat.so http://www.cnblogs.com/lib/libvarnishapi/.libs/libvarnishapi.so -lpcre -lm -lcurses -lpthread creating varnishsizes make[3]: Leaving directory `/root/varnish_setup/varnish-2.1.5/bin/varnishsizes' make[3]: Entering directory `/root/varnish_setup/varnish-2.1.5/bin' make[3]: Nothing to be done for `all-am'. make[3]: Leaving directory `/root/varnish_setup/varnish-2.1.5/bin' make[2]: Leaving directory `/root/varnish_setup/varnish-2.1.5/bin' Making all in man make[2]: Entering directory `/root/varnish_setup/varnish-2.1.5/man' make[2]: Nothing to be done for `all'. make[2]: Leaving directory `/root/varnish_setup/varnish-2.1.5/man' Making all in etc make[2]: Entering directory `/root/varnish_setup/varnish-2.1.5/etc' make[2]: Nothing to be done for `all'. make[2]: Leaving directory `/root/varnish_setup/varnish-2.1.5/etc' Making all in doc make[2]: Entering directory `/root/varnish_setup/varnish-2.1.5/doc' Making all in sphinx make[3]: Entering directory `/root/varnish_setup/varnish-2.1.5/doc/sphinx' make[3]: Nothing to be done for `all'. make[3]: Leaving directory `/root/varnish_setup/varnish-2.1.5/doc/sphinx' make[3]: Entering directory `/root/varnish_setup/varnish-2.1.5/doc' make[3]: Nothing to be done for `all-am'. make[3]: Leaving directory `/root/varnish_setup/varnish-2.1.5/doc' make[2]: Leaving directory `/root/varnish_setup/varnish-2.1.5/doc' Making all in redhat make[2]: Entering directory `/root/varnish_setup/varnish-2.1.5/redhat' make[2]: Nothing to be done for `all'. make[2]: Leaving directory `/root/varnish_setup/varnish-2.1.5/redhat' make[2]: Entering directory `/root/varnish_setup/varnish-2.1.5' make[2]: Nothing to be done for `all-am'. make[2]: Leaving directory `/root/varnish_setup/varnish-2.1.5' make[1]: Leaving directory `/root/varnish_setup/varnish-2.1.5' [root@node18 varnish-2.1.5]#
[root@node18 varnish-2.1.5]# cd bin/varnishtest && ./varnishtest tests/*.vtc
# top TEST tests/a00000.vtc passed (0.001s)
# top TEST tests/a00001.vtc passed (0.001s)
# top TEST tests/a00002.vtc passed (0.001s)
# top TEST tests/a00003.vtc passed (0.001s)
# top TEST tests/a00004.vtc passed (0.001s)
# top TEST tests/a00005.vtc passed (0.001s)
# top TEST tests/a00006.vtc passed (0.001s)
# top TEST tests/a00007.vtc passed (0.001s)
# top TEST tests/a00008.vtc passed (1.806s)
# top TEST tests/a00009.vtc passed (0.256s)
# top TEST tests/a00010.vtc passed (0.002s)
# top TEST tests/b00000.vtc passed (0.757s)
# top TEST tests/b00001.vtc passed (0.675s)
# top TEST tests/b00002.vtc passed (0.683s)
...
# top TEST tests/v00023.vtc passed (0.575s) # top TEST tests/v00024.vtc passed (0.587s) # top TEST tests/v00025.vtc passed (0.673s) # top TEST tests/v00026.vtc passed (0.590s) # top TEST tests/v00028.vtc passed (0.581s) # top TEST tests/v00029.vtc passed (1.310s) # top TEST tests/v00030.vtc passed (0.585s) # top Slowest test: tests/p00005.vtc 8.022s # top Total tests run: 196 # top Total duration: 204.346s [root@node18 varnishtest]#
[root@node18 varnishtest]# cd ../..
[root@node18 varnish-2.1.5]# make install
Making install in include
make[1]: Entering directory `/root/varnish_setup/varnish-2.1.5/include'
make[2]: Entering directory `/root/varnish_setup/varnish-2.1.5/include'
make[2]: Nothing to be done for `install-exec-am'.
test -z "/usr/include/varnish" || mkdir -p -- "/usr/include/varnish"
/usr/bin/install -c -m 644 'shmlog.h' '/usr/include/varnish/shmlog.h'
/usr/bin/install -c -m 644 'shmlog_tags.h' '/usr/include/varnish/shmlog_tags.h'
/usr/bin/install -c -m 644 'stat_field.h' '/usr/include/varnish/stat_field.h'
/usr/bin/install -c -m 644 'stats.h' '/usr/include/varnish/stats.h'
/usr/bin/install -c -m 644 'varnishapi.h' '/usr/include/varnish/varnishapi.h'
make[2]: Leaving directory `/root/varnish_setup/varnish-2.1.5/include'
make[1]: Leaving directory `/root/varnish_setup/varnish-2.1.5/include'
Making install in lib
...
Making install in redhat make[1]: Entering directory `/root/varnish_setup/varnish-2.1.5/redhat' make[2]: Entering directory `/root/varnish_setup/varnish-2.1.5/redhat' make[2]: Nothing to be done for `install-exec-am'. make[2]: Nothing to be done for `install-data-am'. make[2]: Leaving directory `/root/varnish_setup/varnish-2.1.5/redhat' make[1]: Leaving directory `/root/varnish_setup/varnish-2.1.5/redhat' make[1]: Entering directory `/root/varnish_setup/varnish-2.1.5' make[2]: Entering directory `/root/varnish_setup/varnish-2.1.5' make[2]: Nothing to be done for `install-exec-am'. /root/varnish_setup/varnish-2.1.5/install-sh -d -m 0755 /usr/var/varnish test -z "/usr/lib/pkgconfig" || mkdir -p -- "/usr/lib/pkgconfig" /usr/bin/install -c -m 644 'varnishapi.pc' '/usr/lib/pkgconfig/varnishapi.pc' make[2]: Leaving directory `/root/varnish_setup/varnish-2.1.5' make[1]: Leaving directory `/root/varnish_setup/varnish-2.1.5' [root@node18 varnish-2.1.5]#
[root@node18 varnish-2.1.5]# whereis varnish varnish: /usr/etc/varnish /usr/include/varnish [root@node18 varnish-2.1.5]# whereis varnishd varnishd: /usr/sbin/varnishd /usr/man/man1/varnishd.1
[root@node18 varnish-2.1.5]# ls /usr/etc/varnish/default.vcl
/usr/etc/varnish/default.vcl
[root@node18 varnish-2.1.5]#