Squid代理服务器搭建步骤流程

运行&维护   opration&maintance

IT运维、业务运维、日常管理运维

 

Linux运维最佳实践

集中化:ansible、saltstack

自动化:shell、python

标准化:

虚拟化:kvm、vmware

分布式:

 

squid 缓存页面是在硬盘上/var/spool/squid/

squid传统,资料多,排错,正向,反向,透明代理

varnish 缓存数据在硬盘或内存,反向代理,http加速

 

源码安装软件:

1.tar -xf 解压

2. cd ; ./configure ; make ;make install

备注:解决依赖关系

 

3.作软链接或者修改PATH路径

4.cp提供一个启动服务

5.cp配置文件

##################################

 

二、代理服务器概述

Proxy,代理人、经纪人、中介

代替用户处理事务

- 能提供正常情况下不便或无法访问的资源

应用场景:

- web访问加速(正/反向)

- IP伪装、“翻墙”

代理服务器工作机制

- Cache池的复用

- 线路转移

##################################

 

三、Squid代理服务器

Squid服务器(缓存服务器)(代理软件)

软件包:squid-3.38-26.el7.x86_64.rpm

系统服务:squid

主程序:/usr/sbin/squid

主配置文件:/etc/squid/squid.conf

默认监听端口:TCP 3128

默认访问日志:/var/log/squid/access.log

ufs 存储格式   

思路:

1.搭建一个源站点  httpd

2.各个地区搭建缓存服务器   squid   你是谁?80 vhost(注意关闭httpd)

源是谁?cacge_peer 2.100如何加速?cache_dir  /var/spool/squid

3.用户访问缓存服务器   curl 、firefox、elinks

4.DNS分离解析nslookup

 

优势:功能全、历史悠久;负载均衡、访问速率提高

 

##################################

反向代理:

步骤一:构建web服务器

Web1: eth1(192.168.2.100)

 

[root@web ~]# yum  -y  install  httpd

[root@web ~]# rpm  -q  httpd

[root@web ~]# systemctl start httpd  ;  systemctl enable httpd

[root@web ~]# netstat  -anptu  |  grep httpd

[root@web ~]#vim  /var/www/html/index.html

<html>

<title>Welcome</title>

<body><h1>wodewangzhishi192.168.4.100</h1>nihao</body>

</html>

[root@web ~]# tail /var/log/httpd/access_log

 

步骤二:部署Squid代理服务器

Proxy:   eth0(192.168.4.5) eth1(192.168.2.5)

 

[root@svr5 ~]# yum  -y  install  squid

[root@svr5 ~]# vim /etc/squid/squid.conf 修改配置文件

http_access allow all          //允许本机所有主机使用代理服务器---56行

http_port 80  vhost            //设置反向代理  ---伪装成80服务 ---59行

visible_hostname svr5.tarena.com                //设置主机名   ---随意

cache_peer  192.168.2.100  parent 80   0  originserver    //定义后端真实服务器信息   ---后台2.100  0-icp不用  --源服务

cache_dir ufs   /var/spool/squid 200 16  128        //硬盘缓存 --目录空间(MB)默认100、一级子目录数默认16,二级子目录数默认256

 

[root@svr5 ~]# systemctl start squid; systemctl enable squid

[root@svr5 ~]# netstat  -anptu  |  grep 80    //

步骤三:客户端测试

Client:  eth0(192.168.4.100)

[root@client ~]# cat /etc/hosts   

//配置域名解析,将域名解析为Squid服务器IP地址

192.168.4.5    www.tarena.com

[root@client ~]# firefox   http://www.tarena.com

[root@client ~]# curl   http://192.168.4.5

 

##################################

[root@client ~]# curl -I  http://192.168.4.5

(浏览器的选项-开发者-网络)

X-Cache:”MISS/HIT  from  chen.tedu.com”

miss缓存里没找到,缓存服务器会到后台找到并缓存(一般在第一次访问一个页面时),hit 有缓存访问; 用户都能看到页面  

curl 基于命令行的浏览器

 

##################################

 

  • Varnish服务器

Varnish(反向代理软件):高性能且开源的反向代理服务器和http加速器

优点:性能更好,管理更方便、更实惠,速度更快,缓存数据可以在内存里,内存里速度比比硬盘快很多

 

 

(注意关闭httpd、squid)

[root@proxy ~]# systemctl stop squid

[root@proxy ~]# netstat -antpu | grep 80

程序program硬盘 ;进程proccess 内存 占内存相互独立 ; 线程thread 不占内存但相互关联

VARNISH_MIN_THREADS=50

malloc  分配内存

 

/etc/init.d/varnish    #varnish启动程序

/etc/sysconfig/varnish  前端配置--定义varnish自身属性

/etc/varnish/default.vcl后端配置--默认配置文件,定义后端节点

##################################

 

步骤一:构建Web服务器

步骤二:部署Varnish缓存服务器

源码包

scp  -r  /root/桌面/lnmp_soft-2017-03-28.tar.gz  192.168.4.5:/opt/

tar -xf /opt/lnmp_soft-2017-03-28.tar.gz -C /opt/

cd /opt/lnmp_soft/

./install_lnmp.sh

 

1. 编译安装

#yum -y install  gcc  readline-devel  pcre-devel

#useradd -s /sbin/nologin  varnish

#tar -xf varnish-3.0.6.tar.gz

#cd varnish-3.0.6/

# ./configure --prefix=/usr/local/varnish

#make  && make  install

2.复制启动脚本及配置文件

# cp redhat/varnish.initrc    /etc/init.d/varnish

#cp  redhat/varnish.sysconfig    /etc/sysconfig/varnish

#cp redhat/varnish_reload_vcl  /usr/bin

#ln -s /usr/local/varnish/sbin/varnishd   /usr/sbin/

#ln -s /usr/local/varnish/bin/*    /usr/bin/

#mkdir  /etc/varnish

# cp /usr/local/varnish/etc/varnish/default.vcl   /etc/varnish/

#uuidgen > /etc/varnish/secret  /改密码

 

3.修改Varnish文件

    [root@svr5 ~]# vim /etc/sysconfig/varnish

    VARNISH_VCL_CONF=/etc/varnish/default.vcl          #vcl文件路径---60行

    VARNISH_LISTEN_PORT=80                                #默认端口---66行

    VARNISH_SECRET_FILE=/etc/varnish/secret                #密钥文件---73行

    VARNISH_STORAGE_SIZE=64M                                #缓存大小---89行

    VARNISH_STORAGE="malloc,${VARNISH_STORAGE_SIZE}"        #基于内存方式缓存(默认文件缓存)---92行

 

4.修改代理配置文件

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

    backend default {

         .host = "192.168.2.100";                 #后端web的IP

         .port = "80";                #后端端口号

     }

  [root@svr5 ~]#/etc/init.d/varnish   start

  [root@svr5 ~]#netstat -antpu | grep 80

 

步骤三:客户端测试

[root@client ~]# firefox http://www.tarena.com

日志文件

[root@svr5 ~]#varnishlog  本身日志

[root@svr5 ~]#varnishncsa  访问日志

 

步骤更新缓存

[root@svr5 ~]#varnishadm  -S   /etc/varnish/secret   -T   127.0.0.1:6082    

varnish>help

varnish> ban.url  3.html   页面文件    ---支持正则       //清缓存

#varnishadmin  backend.list

#varnishadmin  storage.list

猜你喜欢

转载自blog.csdn.net/rio520/article/details/81143306