龙空技术网

Centos7.4/RHEL7.4使用Varnish加速WEB服务器

阳之幸福 648

前言:

如今朋友们对“centos67源修改”大体比较珍视,姐妹们都想要学习一些“centos67源修改”的相关资讯。那么小编也在网络上搜集了一些关于“centos67源修改””的相关内容,希望咱们能喜欢,你们一起来了解一下吧!

实验环境:RHEL7.4最小化安装,建议配置好网络源和EPEL源

官网地址:

[root@Yang ~]# wget --下载安装脚本

[root@Yang ~]# sh script.rpm.sh

Complete!

Generating yum cache for varnishcache_varnish5...

Importing GPG key 0xC23F55C5:

Userid : " () <support@packagecloud.io>"

Fingerprint: 3e92 5951 e2c0 7969 121b dab4 81f8 ca2e c23f 55c5

From :

The repository is setup! You can now install packages.

[root@Yang ~]# yum install varnish -y ---开始安装

[root@Yang ~]# varnishd -V ---查看varnish的版本信息

varnishd (varnish-5.2.1 revision 67e562482)

Copyright (c) 2006 Verdens Gang AS

Copyright (c) 2006-2015 Varnish Software AS

[root@Yang ~]# yum install httpd -y && systemctl start httpd ---安装Apache

[root@Yang ~]# echo "Hello Yang"> /var/www/html/index.html

[root@Yang ~]# vim /etc/varnish/default.vcl

18 .port = "80"; ---将端口改为80

[root@Yang ~]# systemctl restart varnish

打开浏览器,如下图所示

加速web服务器

[root@webserver ~]# yum install httpd -y && systemctl start httpd

[root@webserver ~]# echo "webserver hello Yang" > /var/www/html/index.html

[root@Yang varnish]# systemctl stop httpd

[root@Yang ~]# vim /etc/varnish/varnish.params ---修改如下

19 VARNISH_LISTEN_PORT=80

[root@Yang ~]# vim /etc/varnish/default.vcl

16 backend web {

17 .host = "192.168.127.170"; ---填写web服务器的地址

18 .port = "80"; ---端口

19 }

[root@Yang ~]# systemctl restart varnish

开始访问:varnish服务器的地址

[root@Yang ~]# curl -I 127.0.0.1 ---测试

HTTP/1.1 200 OK

Date: Fri, 02 Feb 2018 05:40:56 GMT

Server: Apache/2.4.6 (Red Hat Enterprise Linux) PHP/5.4.16

Last-Modified: Fri, 02 Feb 2018 04:48:39 GMT

ETag: "15-564336d0f4434"

Content-Length: 21

Content-Type: text/html; charset=UTF-8

X-Varnish: 32770

Age: 0

Via: 1.1 varnish (Varnish/5.2)

X-Cache: MISS ----没有缓存

Accept-Ranges: bytes

Connection: keep-alive

[root@Yang ~]# curl -I 127.0.0.1 --再次执行已经缓存

HTTP/1.1 200 OK

Date: Fri, 02 Feb 2018 05:40:56 GMT

Server: Apache/2.4.6 (Red Hat Enterprise Linux) PHP/5.4.16

Last-Modified: Fri, 02 Feb 2018 04:48:39 GMT

ETag: "15-564336d0f4434"

Content-Length: 21

Content-Type: text/html; charset=UTF-8

X-Varnish: 32773 32771

Age: 4

Via: 1.1 varnish (Varnish/5.2)

X-Cache: HIT ---缓存

Accept-Ranges: bytes

Connection: keep-alive

此时加速WEB服务器成功!!!

标签: #centos67源修改