varnish是一款高性能、开源的反向代理服务器和缓存服务器。Varnish使用内存缓存文件来减少响应时间和网络带宽消耗。
VCL处理流程图
处理过程大致分为如下几个步骤:
(1)Receive 状态,也就是请求处理的入口状态,根据 VCL 规则判断该请求应该是 Pass 或
Pipe,或者进入 Lookup(本地查询)。
(2)Lookup 状态,进入此状态后,会在 hash 表中查找数据,若找到,则进入 Hit 状态,否则进
入 miss 状态。
(3)Pass 状态,在此状态下,会进入后端请求,即进入 fetch 状态。
(4)Fetch 状态,在 Fetch 状态下,对请求进行后端的获取,发送请求,获得数据,并进行本地
的存储。
(5)Deliver 状态, 将获取到的数据发送给客户端,然后完成本次请求。
varnish 服务配置
基础环境配置之封装虚拟机
1、封装虚拟机,配置三台
主机环境: rhel6 selinux and iptables disabled
两台作为后端服务器
apache——172.25.54.x server2
apache——172.25.54.y server3
一台作为varnish缓存服务器
varnish ——172.25.54.z server1
主机为客户端clients : 172.25.54.250
注 : 此处操作系统为 rhel6.5
2、安装虚拟机(作为母盘)
6.5版本镜像下载链接
注意:在安装虚拟机前,在真机配置好DHCP,以便新建虚拟机存在IP
重启后的操作
[root@localhost ~]# ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue state UNKNOWN
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 52:54:00:58:16:d2 brd ff:ff:ff:ff:ff:ff
inet 172.25.54.3/24 brd 172.25.54.255 scope global eth0
inet6 fe80::5054:ff:fe58:16d2/64 scope link
valid_lft forever preferred_lft forever
[root@localhost ~]# hostname server
##临时修改主机名称
[root@localhost ~]# hostname
server
[root@localhost ~]# vi /etc/sysconfig/network
[root@localhost ~]# cat /etc/sysconfig/network
##永久修改主机名称
NETWORKING=yes
HOSTNAME=server
[root@localhost ~]# vi /etc/hosts
##添加后四行内容
[root@localhost ~]# cat /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
172.25.54.1 server1
172.25.54.2 server2
172.25.54.3 server3
172.25.54.4 server4
[root@localhost ~]# vi /etc/sysconfig/network-scripts/ifcfg-eth0
[root@localhost ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
ONBOOT=yes
BOOTPROTO="dhcp"
[root@localhost ~]# ls /etc/udev/rules.d/ ##删除目录/etc/udev/rules.d/下的内容,只留下文件60-raw.rules
60-raw.rules
[root@localhost ~]# vi /etc/yum.repos.d/rhel-source.repo
[root@localhost ~]# cat /etc/yum.repos.d/rhel-source.repo
[rhel-source]
name=Red Hat Enterprise Linux $releasever - $basearch - Source
baseurl=http://172.25.54.250/rhel6.5
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release
[root@localhost ~]# yum clean all
Loaded plugins: product-id, subscription-manager
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
Cleaning repos: rhel-source
Cleaning up Everything
[root@localhost ~]# yum repolist
Loaded plugins: product-id, subscription-manager
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
rhel-source | 3.9 kB 00:00
rhel-source/primary_db | 3.1 MB 00:00
repo id repo name status
rhel-source Red Hat Enterprise Linux 6Server - x86_64 - Source 3,690
repolist: 3,690
[root@localhost ~]# yum install vim lftp -y
[root@localhost ~]# vim /etc/sysconfig/selinux
[root@localhost ~]# cat /etc/sysconfig/selinux
7 SELINUX=disabled ##修改selinux的值为disabled
[root@localhost ~]# chkconfig iptables off
[root@localhost ~]# /etc/init.d/iptables stop
##这两条命令是关闭防火墙
[root@localhost ~]# poweroff
##做完上述操作过后,关闭该虚拟机
注意:母盘关机后,不能再次打开,再次打开会导致母盘损坏
3、虚拟机(子镜像)的安装
kvm —> cpu/mem 对cpu和内存的虚拟化
qemu —> disk/net…. 对磁盘 网卡….的虚拟化
libvirtd —-> user 和 kernel 之间的操作接口
virt-manager —–> 虚拟机管理
virsh —–> 虚拟机管理
首先对母盘做以下处理
[root@foundation54 ~]# cd /var/lib/libvirt/images/
[root@foundation54 images]# ll
total 1948488
-rw------- 1 root root 21478375424 Jul 28 11:03 tutu.qcow2
[root@foundation54 images]# du -h tutu.qcow2
1.9G tutu.qcow2
[root@foundation54 images]# ls
tutu.qcow2
[root@foundation54 images]# virt-
virt-admin virt-format virt-resize
virt-alignment-scan virt-get-kernel virt-sparsify
virt-builder virt-host-validate virt-sysprep
virt-cat virt-index-validate virt-tar-in
virt-clone virt-inspector virt-tar-out
virt-copy-in virt-install virt-top
virt-copy-out virt-log virt-viewer
virt-customize virt-ls virt-what
virt-df virt-make-fs virt-who
virt-diff virt-manager virt-who-password
virt-edit virt-pki-validate virt-xml
virt-filesystems virt-rescue virt-xml-validate
[root@foundation54 images]# virt-sysprep -d tutu
[root@foundation54 images]# virt-manager
[root@foundation54 images]# pwd
/var/lib/libvirt/images
[root@foundation54 images]# ls
tutu.qcow2
[root@foundation54 images]#
注意:若命令 virt-sysprep 不存在,便执行下列操作,执行后,该命令便存在啦~
[root@foundation54 ~]# yum provides */virt-sysprep
Loaded plugins: langpacks, product-id, search-disabled-repos, subscription-
: manager
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
1:libguestfs-tools-c-1.32.7-3.el7.x86_64 : System administration tools for
: virtual machines
Repo : rhel7.3
Matched from:
Filename : /usr/bin/virt-sysprep
[root@foundation54 ~]# yum install libguestfs-tools-c-1.32.7-3.el7.x86_64 -y
安装
[root@foundation54 images]# pwd
/var/lib/libvirt/images
[root@foundation54 images]# ls
tutu.qcow2
[root@foundation54 images]# qemu-img create -f qcow2 -b tutu.qcow2 test1
Formatting 'test1', fmt=qcow2 size=21474836480 backing_file='tutu.qcow2' encryption=off cluster_size=65536 lazy_refcounts=off
[root@foundation54 images]# ls
test1 tutu.qcow2
[root@foundation54 images]# ll test1
-rw-r--r-- 1 root root 197120 Jul 28 11:28 test1
[root@foundation54 images]# du -h test1
196K test1
[root@foundation54 images]# virt-manager
[root@foundation54 images]# du -h test1
4.6M test1
[root@foundation54 images]# du -h tutu.qcow2
1.9G tutu.qcow2
[root@foundation54 images]#
虚拟机(子镜像)的所有操作均不改变虚拟机母盘
按照此方法继续安装虚拟机test2、test3
varnish ——172.25.54.5 server1(虚拟机test1)
apache——172.25.54.6 server2(虚拟机test2)
apache——172.25.54.7 server3(虚拟机test3)