主要记录下用Squid 做正向代理(透明代理)时的优化设置,一切尚在调试中所以下面的优化方式都是正确的。
内核调整
/etc/sysctl.conf 下面添加
net.ipv4.netfilter.ip_conntrack_tcp_timeout_established =900
net.ipv4.icmp_echo_ignore_all = 0
net.ipv4.conf.all.proxy_arp = 1
net.ipv4.tcp_synack_retries = 3
net.ipv4.ip_conntrack_max = 81920
net.ipv4.tcp_fin_timeout = 5
net.ipv4.tcp_keepalive_time = 1200
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_tw_recycle = 1
net.ipv4.ip_local_port_range = 1024 65000
net.ipv4.tcp_max_syn_backlog = 8192
net.ipv4.tcp_max_tw_buckets = 5000使设置生效
/sbin/sysctl -p文件系统设置
将squid缓存放入独立的文件系统中,文件系统格式建议用Reiserfs,挂载时使用’noatime’参数提高IO性能。
LABEL=/squid /squid reiserfs defaults,noatime 0 0squid.conf
http_port 192.168.0.254:3128 transparent
cache_mgr hew@linuxbyte.org
cache_mem 512 MB
cache_dir ufs /squid/squid 51200 12 256
maximum_object_size_in_memory 128 KB
maximum_object_size 64 MB
#cache_access_log /var/log/squid/access.log squid
cache_access_log none
cache_log none
cache_store_log none
#logfile_rotate 4
max_filedesc 6144
pipeline_prefetch on
memory_pools off
memory_pools_limit none
mime_table /etc/squid/mime.conf
refresh_pattern -i \\.css$ 1440 50% 129600 reload-into-ims
refresh_pattern -i \\.xml$ 1440 50% 129600 reload-into-ims
refresh_pattern -i \\.htm$ 1440 90% 129600 reload-into-ims
refresh_pattern -i \\.html$ 1440 90% 129600 reload-into-ims
refresh_pattern -i \\.shtml$ 1440 90% 129600 reload-into-ims
refresh_pattern -i \\.png$ 1440 90% 129600 reload-into-ims
refresh_pattern -i \\.jpg$ 1440 90% 129600 reload-into-ims
refresh_pattern -i \\.jpeg$ 1440 90% 129600 reload-into-ims
refresh_pattern -i \\.gif$ 1440 90% 129600 reload-into-ims
refresh_pattern -i \\.bmp$ 1440 90% 129600 reload-into-ims
refresh_pattern -i \\.js$ 1440 90% 129600 reload-into-ims
refresh_pattern -i \\.mp3$ 1440 50% 2880 ignore-reload
refresh_pattern -i \\.wmv$ 1440 50% 2880 ignore-reload
refresh_pattern -i \\.rm$ 1440 50% 2880 ignore-reload
refresh_pattern -i \\.swf$ 1440 50% 2880 ignore-reload
refresh_pattern -i \\.mpeg$ 1440 50% 2880 ignore-reload
refresh_pattern -i \\.wma$ 1440 50% 2880 ignore-reload
refresh_pattern -i \\.exe$ 1440 50% 2880 ignore-reload
refresh_pattern -i \\.rar$ 1440 50% 2880 ignore-reload
refresh_pattern -i \\.zip$ 1440 50% 2880 ignore-reload
refresh_pattern -i \\.gz$ 1440 50% 2880 ignore-reload
refresh_pattern -i \\.bz2$ 1440 50% 2880 ignore-reload
refresh_pattern -i \\.7z$ 1440 50% 2880 ignore-reload
client_lifetime 1 hours
half_closed_clients off
visible_hostname proxy.linuxbyte.org
cache_effective_user squid
cache_effective_group squid
cache_swap_low 75
cache_swap_high 95
dns_nameservers 192.168.0.254
acl QUERY urlpath_regex -i cgi-bin \\?
cache deny QUERY
acl all src 0.0.0.0/0
acl localnet src 192.168.0.0/24
http_access allow localnet
http_access deny all