varnish缓存代理

一、 varnish缓存代理
1、 配置基本环境
1)
配置基本环境centos01、02网站服务器、03varnish缓存代理服务器

varnish缓存代理
varnish缓存代理
varnish缓存代理
[[email protected] ~]# vim /etc/sysconfig/network-scripts/ifcfg-ens32
GATEWAY=192.168.100.30
[[email protected] ~]# systemctl restart network
[[email protected] ~]# vim /etc/sysconfig/network-scripts/ifcfg-ens32
GATEWAY=192.168.100.30
[[email protected] ~]# systemctl restart network

[[email protected] ~]# cp /etc/sysconfig/network-scripts/ifcfg-ens32 /etc/sysconfig/network-scripts/ifcfg-ens34
[[email protected] ~]# vim /etc/sysconfig/network-scripts/ifcfg-ens34
NAME=ens33
DEVICE=ens34
IPADDR=192.168.200.254
NETMASK=255.255.255.0
[[email protected] ~]# systemctl restart network
[[email protected] ~]# vim /etc/sysctl.conf
net.ipv4.ip_forward = 1
[[email protected] ~]# sysctl -p
net.ipv4.ip_forward = 1
2)
两台网站服务器安装httpd

[[email protected] ~]# rm -rf /etc/yum.repos.d/CentOS-*
[[email protected] ~]# mount /dev/cdrom /mnt/
mount: /dev/sr0 写保护,将以只读方式挂载
[[email protected] ~]# yum -y install httpd
[[email protected] ~]# echo “www.benet.com” > /var/www/html/index.html
[roo[email protected] ~]# systemctl start httpd

[[email protected] ~]# rm -rf /etc/yum.repos.d/CentOS-*
[[email protected] ~]# mount /dev/cdrom /mnt/
mount: /dev/sr0 写保护,将以只读方式挂载
[[email protected] ~]# yum -y install httpd
[[email protected] ~]# echo “www.accp.com” > /var/www/html/index.html
[[email protected] ~]# systemctl start httpd
2、 varnish缓存代理
1、 安装varnis
1)
rz上传varnis软件包并解压

[[email protected] ~]# rz
z waiting to receive.B0100000023be50
varnish缓存代理
[[email protected] ~]# tar zxvf varnish-4.0.1.tgz -C /usr/src/
2)
联网安装依赖程序

[[email protected] ~]# rm -rf /etc/yum.repos.d/CentOS-

[[email protected] ~]# mount /dev/cdrom /mnt/
mount: /dev/sr0 写保护,将以只读方式挂载
[[email protected] ~]# cd /etc/yum.repos.d/
[[email protected] yum.repos.d]# wget http://mirrors.aliyun.com/repo/Centos-7.repo
[[email protected] ~]# yum -y install libtool ncurses-devel pcre-devel libxslt groff pkgconfig libedit-devel python-imaging python-docutils
3)
运行varnish脚本初始化varnish

[[email protected] ~]# cd /usr/src/varnish-4.0.1/
[[email protected] varnish-4.0.1]# ./autogen.sh
4)
配置varnish安装位置

[[email protected] varnish-4.0.1]# ./configure --prefix=/usr/local/varnish --enable-developer-warnings --enable-debugging-symbols
5)
编译安装varnish

[[email protected] varnish-4.0.1]# make && make install
6)
优化varnish命令

[[email protected] ~]# ln -s /usr/local/varnish/bin/
/usr/local/bin/
[[email protected] ~]# ln -s /usr/local/varnish/sbin/varnishd /usr/local/sbin/
7)
配置生成rnis主配置文件

[[email protected] ~]# cp /usr/local/varnish/share/doc/varnish/example.vcl /usr/local/varnish/default.vcl
2、 配置varnish负载均衡缓存
1)
修改主配置文件

[[email protected] ~]# vim /usr/local/varnish/default.vcl
13 vcl 4.0;
14 import directors;
16 backend web01 {
17 .host = “192.168.100.10”;
18 .port = “80”;
19 }
20
21 backend web02 {
22 .host = “192.168.100.20”;
23 .port = “80”;
24 }
25 sub vcl_init {
26 new bar = directors.round_robin();
27 bar.add_backend(web01);
28 bar.add_backend(web02);
29 }
30 sub vcl_recv {
31 set req.backend_hint = bar.backend();
32 }
2)
启动varnish服务

[[email protected] ~]# varnishd -f /usr/local/varnish/default.vcl -a 192.168.200.254:80
3)
监控varnish日志

[[email protected] ~]# varnishlog
二、 安装dsn
1)
安装dns

[[email protected] ~]# yum -y install bind bind-chroot bind-utils
2)
配置dns

[[email protected] ~]# echo “” > /etc/named.conf
[[email protected] ~]# vim /etc/named.conf
options {
listen-on port 53 { any; };
directory “/var/named/”;
};
zone “benet.com” IN {
type master;
file “benet.com.zone”;
};

[[email protected] ~]# vim /var/named/benet.com.zone
$TTL 86400
@ SOA benet.com. root.benet.com (
2020040610
1H
15M
1W
1D
)
@ NS centos03.benet.com.
centos03 A 192.168.200.254
www A 192.168.200.254
[[email protected] ~]# chmod +x /var/named/benet.com.zone
[[email protected] ~]# chown named:named /var/named/benet.com.zone
[[email protected] ~]# named-checkconf /etc/named.conf
[[email protected] ~]# named-checkzone benet.com /var/named/benet.com.zone
zone benet.com/IN: loaded serial 2020040610
OK
3)
启动dns

[[email protected] ~]# systemctl start named
[[email protected] ~]# systemctl enable named
三、 客户端访问
1)
客户端配置IP地址

varnish缓存代理
varnish缓存代理
2)
使用www.benet.com域名访问

varnish缓存代理
varnish缓存代理

相关文章:

  • 2022-01-16
  • 2021-11-16
  • 2021-06-21
  • 2018-07-14
  • 2021-07-23
  • 2021-12-07
猜你喜欢
  • 2021-10-12
  • 2021-06-02
  • 2022-01-12
  • 2021-11-06
  • 2022-12-23
  • 2021-04-25
  • 2021-09-30
相关资源
相似解决方案