Varnish and packaging virtual machines

encapsulated virtual machine

1. Configure the master disk rhel6.5 (select Network insatll)

1) The physical machine mounts the 6.5 image to /var/www/html/rhel6.5

2) Install dhcp and configure dhcp

3) The installation path of Network insatll is http://172.25.40.250:rhel6.5 , and select the minimal installation

4) Configure the master disk to network; yum source; local parsing; delete the /etc/udev/rules.d/70.. file; install the software you need vim, openssh-clients, lftp, etc.; close selinux and iptables; complete Then select poweroff to shut down

5) Clean up: virt-sysprep -d rhel6.5

2. Encapsulate the virtual machine:

1) cd /var/lib/libvirt/images/ Execute qemu-img create -f qcow2 -b rhel6.5.qcow2 vm1 package (package the virtual machine you want in turn)

2) View the encapsulated virtual machine information: qemu-img info vm1

3) Select import existing disk image graphical management installation

4) Change the hostname and ip after entering

(libvirtd is virtual machine management software)

varnish
1. Start varnish
server1:
yum install -y varnish3.0.5 and varnish-libs.3.0.5 rpm packages

Configure a backend server
vim /etc/varnish/default.vcl

backend web1 {
.host = "172.25.40.2";
.port = "80";
}

Configure varnish service port
vim /etc/sysconfig/varnish

VARNISH_LISTEN_PORT=80

server2:
open http and echo www.westos.org > index.html

Test:
physical machine curl 172.25.40.1 to see if the content provided by server2 apache www.westos.org

2. Check the cache hit
server1
vim /etc/security/limits.conf

varnishi - nofile  65535

vim /etc/sysconfig/varnish

NFILES=65535

(where, 65535 is the maximum number of read files, you can use the command sysctl -a | grep file to view)

vim /etc/varnish/default.vcl

sub vcl_deliver {
if (obj.hits > 0) {
set resp.http.X-Cache = "HIT from westos cache";
}
else {
set resp.http.X-Cache = "MISS from westos cache";
}

return (deliver);

}

/etc/init.d/varnish reload
test:
physical machine curl -I 172.25.40.1, showing the situation of HIT and MISS

(Among them, clear cache command: varnishadm ban.url .*$)

3. Define back-end servers for multiple sites with different domain names

Server1 installs apche service, that is, varnish and apache service (or use server3 as backend)

Modify apache port vim /etc/httpd/conf/httpd.conf (avoid 80 port varnish conflict)

Listen 8080

Edit the varnish configuration file and add a backend server for a different domain name site:

When accessing the www.westos.org domain name, the data is retrieved from web1, and when accessing the bbs.westos.org domain name, the data is retrieved from web2, and an
error is reported when accessing other pages.

vim /etc/varnish/default.vcl

The overall code is as follows:

backend web1 {
  .host = "172.25.40.1";
  .port = "8080";
}

backend web2 {
  .host = "172.25.40.2";
  .port = "80";
}

sub vcl_recv {
if (req.http.host ~ "^(www.)?westos.org") {
set req.http.host = "www.westos.org";
set req.backend = web1;
}elsif (req.http.host ~ "^bbs.westos.org") {
set req.backend = web2;
}else {error 404 "westos cache";
}
}

(In which, the physical machine does
the analysis) 4. Aggregate multiple backends into a group, and detect the health status of the backends

vim /etc/varnish/default.vcl

director lb round-robin {
{ .backend = web1; }
{ .backend = web2; }
}
sub vcl_recv {
if (req.http.host ~ "^(www.)?westos.org") {
set req.http.host = "www.westos.org";
set req.backend = lb;
return(pass);
}elsif (req.http.host ~ "^bbs.westos.org") {
set req.backend = web2;
}else {error 404 "westos cache";
}
}

return(pass) means no caching

5. varnish cdn push platform

1) server1 installs php service

2) Change the php configuration file; put it under /var/www/html

V A R C L U S T E R = a r r a and ( w w w . w e s t O s . O r g => var_group1,
); means to bind the host list

3) Check the real machine website: 172.25.77.8080: /varnish check

6. Set acl access control

1) server1 /etc/varnish/default.vcl settings

ub vcl_recv {
if (req.request == “BAN”) {
if (!client.ip ~ westos) {
error 405 “Not allowed.”;
}
ban(“req.url ~ ” + req.url);
error 200 “ban added”;
}
}

2) Re-open the machine whose ip is no longer in the acl list for access and view

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325566217&siteId=291194637