手机版
你好,游客 登录 注册
背景:
阅读新闻

Squid反向代理加速缓存+负载均衡实验架构

[日期:2012-02-12] 来源:Linux社区  作者:centiliux [字体:大 中 小]

二、squid的编译安装配置

1、squid的安装

安装gcc等工具包

yum install gcc gcc+ gcc-c++ gcc-g77 autoconf automake ncurses-devel flex openssl-devel mod_ssl make

cd /home/soft

tar zxvf squid-3.1.16.tar.gz

cd squid-3.1.16

./configure --prefix=/usr/local/squid --enable-gnuregex --enable-dlmalloc --with-pthreads --enable-ssl --enable-stacktrace --enable-removal-policies=heap,lru --enable-delay-pools --enable-kill-parent-hack --enable-snmp --enable-icmp --enable-err-language=simplify_Chinese --enable-default-err-languages=Simplify_Chinese --enable-cahce-digests --disable-ident-lookups --with-filedescriptors=65536 --enable-underscore --enable-large-cache-files --with-large-files --enable-storeio=aufs,diskd,ufs --enable-linux-netfilter --enable-async-io=160 --enable-cachemgr

make

make install

cd /usr/local/squid

2、生成证书并申请新证书

openssl genrsa -des3 -out *.squid.key 1024

openssl req -new -key *.squid.key -out *.squid.csrc

这是需要生成正式证书使用的,如果只是需要未认证的证书,可使用以下命令生成:

openssl req -utf8 -new -key *.squid.key -out *.squid.csr

这里生成的证书不要使用密码,貌似squid不能使用密码,我第一次使用了密码能正常启动,但会提示未认证,让我搞了好久的时间。

3、squid配置

mkdir /data/cache1

mkdir /data/cache2

mkdir /data/cachelog

chown squid /data/cache*

把服务商提供的证书放到/data/key/目录下,包括中级根证书,证书,公钥三个文件。

修改squid.conf文件内容:

------------------------------------------------------------------------------

#

# Recommended minimum configuration:

#

acl manager proto cache_object

acl localhost src 127.0.0.1/32 ::1

acl to_localhost dst 127.0.0.0/8 0.0.0.0/32 ::1

# Example rule allowing access from your local networks.

# Adapt to list your (internal) IP networks from where browsing

# should be allowed

# acl localnet src 10.0.0.0/8 # RFC1918 possible internal network

# acl localnet src 172.16.0.0/12 # RFC1918 possible internal network

acl localnet src 192.168.9.0/24 # RFC1918 possible internal network

# acl localnet src fc00::/7 # RFC 4193 local private network range

# acl localnet src fe80::/10 # RFC 4291 link-local (directly plugged) machines

acl SSL_ports port 443

acl Safe_ports port 80 # http

acl Safe_ports port 21 # ftp

acl Safe_ports port 443 # https

acl Safe_ports port 70 # gopher

acl Safe_ports port 210 # wais

acl Safe_ports port 1025-65535 # unregistered ports

acl Safe_ports port 280 # http-mgmt

acl Safe_ports port 488 # gss-http

acl Safe_ports port 591 # filemaker

acl Safe_ports port 777 # multiling http

 

acl CONNECT method CONNECT

#

# Recommended minimum Access Permission configuration:

#

# Only allow cachemgr access from localhost

http_access allow manager localhost

http_access deny manager

# Deny requests to certain unsafe ports

http_access deny !Safe_ports

# Deny CONNECT to other than secure SSL ports

http_access deny CONNECT !SSL_ports

# We strongly recommend the following be uncommented to protect innocent

# web applications running on the proxy server who think the only

# one who can access services on "localhost" is a local user

# http_access deny to_localhost

#

# INSERT YOUR OWN RULE(S) HERE TO ALLOW ACCESS FROM YOUR CLIENTS

#

# Example rule allowing access from your local networks.

# Adapt localnet in the ACL section to list your (internal) IP networks

# from where browsing should be allowed

http_access allow localnet

http_access allow localhost

# And finally deny all other access to this proxy

http_access deny all

# Squid normally listens to port 3128

# http_port 3128

# Uncomment and adjust the following to add a disk cache directory.

# cache_dir ufs /usr/local/squid/var/cache 100 16 256

# Leave coredumps in the first cache dir

coredump_dir /usr/local/squid/var/cache

# 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

##---------------------------------------

# host and cache port setting

##----------------------------------------

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

visible_hostname squid

cache_mgr jason.kou@factorybuy.com

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

cache_effective_user squid

cache_effective_group squid

cachemgr_passwd password all

client_persistent_connections off

server_persistent_connections on

half_closed_clients off

# 设定squid为accel加速模式,vhost必须要加.否则将无法将主机头转发至后端服务器,

# 访问时就会出现无法找到主机头的错误

http_port 80 accel vhost vport

# 添加443端口之后可能导致IE浏览器无法正常访问https页面,未测试

http_port 443 accel vhost vport

# https_port 443 cert=/data/squid.csr key=/data/squid.key defaultsite=www.fb.com

# https_port 443 cert=/usr/local/squid/data/cert.pem /usr/local/squid/data/key.pem

##----------------------------------------

# cache directory setting

##----------------------------------------

# 缓存目录8192M,其中一级目录16个,二级256个(每个一级下16个二级)

cache_dir ufs /usr/local/squid/data/cache 8192 16 256

max_open_disk_fds 0

##-----------------------------------------

# cache storage setting

##-----------------------------------------

# 大于此容量的对象将不会被保存在磁盘上,默认大小是4M,如果squid服务器用于缓冲flash等大型文件,

# 建议将此值变大.否则过大的文件在下次重>启后将需要重新获取

maximum_object_size_in_memory 4 MB

minimum_object_size 0 KB

maximum_object_size 4 MB

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

cache_swap_high 95

cache_swap_low 80

# 替换机制(lru叫做“最近不常用的单元”unit一般就是常说object, 也就是当cache

# 中的内容比如内存或硬盘达到上限时就需要进行数据的换进和换出工作)

memory_replacement_policy lru

cache_replacement_policy lru

##------------------------------------------

# cache time out setting

##------------------------------------------

forward_timeout 20 seconds

connect_timeout 15 seconds

read_timeout 3 minutes

request_timeout 1 minutes

persistent_request_timeout 15 seconds

client_lifetime 15 minutes

shutdown_lifetime 5 seconds

negative_ttl 10 seconds

##---------------------------------------------

# cache log setting

##---------------------------------------------

emulate_httpd_log on

logformat squid %ts.%tu %tr %>a %Ss/%>Hs %<st %rm %ru %un %Sh/%<A %mt

access_log /usr/local/squid/data/logs/access_log.log common

cache_log /usr/local/squid/data/logs/cache.log

cache_store_log /usr/local/squid/data/logs/store.log

cache_swap_log /usr/local/squid/data/logs/cache_swap.log

mime_table /usr/local/squid/etc/mime.conf

# 错误信息目录

error_directory /usr/local/squid/share/errors/en-us/

pid_filename /usr/local/squid/data/squid.pid

# 不记录store.log

# cache_store_log none

##--------------------------------------------

# vhost setting

##--------------------------------------------

# 定义不同的父节点,将节点设为no-query以及originserver说明这些节点是实际服务器

cache_peer test1.com parent 80 0 no-query no-digest originserver name=test1 round-robin

cache_peer test2.com parent 80 0 no-query no-digest originserver name=test2 round-robin

# 设定不同域名转发到不同的cache_peer上,如果没有这项.不同域名的域名可能被分发到同一台服务器上.

cache_peer_domain test1 www.fb.com

cache_peer_domain test2 www.fb.com

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

http_access allow all

# 设置不缓存url类型(空格隔开

acl QUERY urlpath_regex .php .jsp .asp .pl .cgi

cache deny QUERY

---------------------------------------------------------------------

hosts_file /etc/hosts

linux
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款