三期总目录链接
目录
一、Squid 相关概述
Squid: Linux系统中一款最常用的开源的代理服务软件,提供缓存代理功能
工作原理:当客户机通过代理去访问各种服务时,代理服务器会先检查自己的缓存,缓存中有结果,直接返回;如果缓存中没有用户需要的信息时,代理服务器转给Internet,获取用户需要的信息,保存到缓存中,并返回给用户
代理缓存加速的对象:文字、图像等静态的Web元素
优势:提高Web访问速度;隐藏客户机的IP地址,还可针对访问目标、时间等进行访问控制(过滤机制)
代理的类型 | |
传统代理 | 需要在客户端去指定代理服务器 (多用于Internet 环境) |
透明代理 | 不需要指定代理服务器的地址和端口 (局域网环境,无需额外设置可实现优质上网) |
二、构建Squid 代理服务器
(一)、Squid 的安装及运行控制
1、编译安装Squid
[root@C7--02 ~]# tar zxvf squid-3.5.23.tar.gz #解压
.......
...
[root@C7--02 ~]# cd squid-3.5.23 #进入squid-3.5.23解压包
[root@C7--02 squid-3.5.23]# ./configure --prefix=/usr/local/squid --sysconfdir=/etc --enable-linux-netfilter --enable-async-io=240 --enable-default-err-langugae=Simplify_Chinese --disable-poll --enable-epoll --enable-gnuregex #(配置)
.........
....
[root@C7--02 squid-3.5.23]# make && make install #(编译并安装)
.......
''''
[root@C7--02 squid-3.5.23]# ln -s /usr/local/squid/sbin/* /usr/local/sbin/ #创建链接文件
[root@C7--02 squid-3.5.23]# useradd -M -s /sbin/nologin squid #创建squid 程序运行账户和组
root@C7--02 squid-3.5.23]# chown -R squid:squid /usr/local/squid/var/ #设置属主和属组
选项的含义如下:
--prefix=/usr/local/squid :安装目录
--sysconfdir=/etc :单独将配置文件修改到其他目录
--enable-linux-netfilter :使用内核过滤
--enable-async-io=值 :异步1/0,提升存储性能,相当于“--enable-pthreads--enable-storeio=ufs,aufs --with -pthreads --with-aufs-thread=值”
--enable-default-err-langugae=Simplify_Chinese :错误信息的显示语言
--disable-poll --enable-epoll :关闭默认使用poll模式,开启epoll模式提升性能
--enable-gnuregex :使用GNU正则表达式
2、修改squid 配置文件 (/etc/squid.conf)
[root@C7--02 squid-3.5.23]# vim /etc/squid.conf
.........
....
http_port 3128 #指定代理服务器监听的地址和端口(默认3128)
# Uncomment and adjust the following to add a disk cache directory.
#cache_dir ufs /usr/local/squid/var/cache/squid 100 16 256
# Leave coredumps in the first cache dir
coredump_dir /usr/local/squid/var/cache/squid
#
# Add any of your own refresh_pattern entries above these.
#
refresh_pattern ^ftp: 1440 20% 10080
refresh_pattern ^gopher: 1440 0% 1440
refresh_pattern -i (/cgi-bin/|\?) 0 0% 0
refresh_pattern . 0 20% 4320
cache_effective_user squid #指定squid 的程序用户,用来设置初始化、运行时缓存的账户
cache_effective_group squid #指定squid 的程序组,用来设置初始化、运行时缓存的组账户
3、squid的运行控制
①
[root@C7--02 squid-3.5.23]# squid -k parse #检查配置文件语法是否正确
2021/08/04 01:26:12| Startup: Initializing Authentication Schemes ...
2021/08/04 01:26:12| Startup: Initialized Authentication Scheme 'basic'
2021/08/04 01:26:12| Startup: Initialized Authentication Scheme 'digest'
2021/08/04 01:26:12| Startup: Initialized Authentication Scheme 'negotiate'
2021/08/04 01:26:12| Startup: Initialized Authentication Scheme