Warning: count(): Parameter must be an array or an object that implements Countable in /www/wwwroot/mdaeo.org/usr/plugins/AMP/Action.php on line 388
squid3安装与反向代理配置

Mdaeo'Blog

squid3安装与反向代理配置

squid3安装与反向代理配置

目前两台服务器,IP地址分别为

192.168.1.120  squid
192.168.2.50    web

其中192.168.2.50提供web服务,可直接通过192.168.2.50访问该站点,现在要在192.168.1.120上安装squid来做192.168.2.50的反向代理,当用户访问192.168.1.120时,120服务器将用户的请求转给50,50响应后将响应内容转给120,然后再由120返回给用户。

1. 安装squid解压

tar zxvf squid-3.0.STABLE21.tar.gz
./configure --prefix=/usr/local/squid \
--disable-carp \
--with-aufs-threads=32 \
--with-pthreads \
--enable-storeio='ufs,aufs,null' \
--enable-disk-io='AIO,Blocking' \
--enable-removal-policies='heap,lru' \
--disable-wccp \
--enable-kill-parent-hack \
--disable-snmp \
--disable-poll \
--disable-select \
--enable-auth=basic \
--with-aio \
--disable-ident-lookup \
--with-filedescriptors=65536

编译和安装

make && make install

 

2. 配置squid

#vim /usr/local/squid/etc/squid.conf

直接在配置文件最后加入即可

#———————————————————————–

# 主机名(3.0加入配置),无此项无法启动
visible_hostname 192.168.1.120

# 管理员邮箱,会显示在错误信息页面上,方便发生错误时联系!
cache_mgr webmaster@linuxany.com

# 实现透明代理(squid2.7以上),其中vhost是必须的
http_port 80 vhost vport

# 缓存设置
cache_mem 256 MB
maximum_object_size_in_memory 2 MB

# 替换机制(lru叫做“最近不常用的单元”unit一般就是常说object, 也就是当cache
# 中的内容比如内存或硬盘达到上限时就需要进行数据的换进和换出工作)
memory_replacement_policy lru

# 缓存目录512M,其中一级目录16个,二级256个(每个一级下16个二级)
cache_dir ufs /usr/local/squid/var/cache 512 16 256
max_open_disk_fds 0

#缓存内容大小控制,当cache目录被占用到97%时,内容将被清空20%
cache_swap_low 80
cache_swap_high 97

# 错误信息目录
error_directory /usr/local/squid/share/errors/Simplify_Chinese

# 最大和最小缓存对象
minimum_object_size 0 KB
maximum_object_size 30 MB

# 日志格式
logformat combined %>a %ui %un [%tl] “%rm %ru HTTP/%rv” %Hs %〈st “%{Referer}〉h” “%{User-Agent}〉h” %Ss:%Sh
access_log /usr/local/squid/var/logs/page_zs_access_log combined
pid_filename /usr/local/squid/var/logs/squid.pid

# 不记录store.log
cache_store_log none

# 指定代理服务器IP,2.5版本以上都是以cache_peer指定
# 需要将apache端口改成81(包括其虚拟机端口< 这里最后补充说明>)
cache_peer 192.168.2.50 parent 80 0 no-query no-digest originserver

# 允许客户端所有请求(这里可以设置拦截url,格式如下面两行缓存设置)
http_access allow all

# 设置不缓存url类型(空格隔开)
acl QUERY urlpath_regex .php .jsp .asp .pl .cgi
cache deny QUERY

#设置运行squid用户,一般不能以root运行
cache_effective_user squid
cache_effective_group squid

#———————————————————————–

3.测试
这时访问192.168.1.120就能访问192.168.2.50了。

4.性能监测与管理

可能通过squidclient这个工具来查看squid的运行情况,缓存命中率等。

/usr/local/squid/bin/squidclient -p 80 mgr:info通过

/usr/local/squid/bin/squidclient -p 80 mgr:可查看各选项的使用说明.

内存使用情况可通过如下选项查看

squidclient -p 80 mgr:mem

创建缓存目录#/usr/local/squid/sbin/squid –z

启动squid
#/usr/local/squid/sbin/squid

停止squid:#/usr/local/squid/sbin/squid -k shutdown

使用新配置启动:
#/usr/local/squid/sbin/squid -k reconfigure

当前页面是本站的「Google AMP」版。查看和发表评论请点击:完整版 »

因本文不是用Markdown格式的编辑器书写的,转换的页面可能不符合AMP标准。