搭建一个大型网站架构的实验环境(Squid缓存服务器篇)第2/2页
六、squid缓存服务器的配置
squid缓存服务器在这个实验环境中有两台(192.168.10.30,192.168.10.31)做成squid集群,我们首先安装一台,然后复制一台,再做配置,这样省事,哈!
squid01服务器网络配置
# ee /etc/rc.conf
ifconfig_lnc0="inet 192.168.10.30 netmask 255.255.255.0"
defaultrouter="192.168.10.10"
192.168.10.30 squid01.rd.bj # ee /etc/resolv.conf
nameserver 192.168.10.40
网络配置好后,我们开始安装squid,先把的藏身处找到:
# whereis squid30
squid30: /usr/ports/www/squid30
# cd /usr/ports/www/squid30
===> The following configuration options are available for squid-3.0.1:
SQUID_LDAP_AUTH=off "Install LDAP authentication helpers"
SQUID_SASL_AUTH=off "Install SASL authentication helpers"
SQUID_DELAY_POOLS=off "Enable delay pools"
SQUID_SNMP=on "Enable SNMP support"
SQUID_CARP=on "Enable CARP support"
SQUID_SSL=off "Enable SSL support for reverse proxies"
SQUID_PINGER=off "Install the icmp helper"
SQUID_HTCP=on "Enable HTCP support"
SQUID_VIA_DB=off "Enable forward/via database"
SQUID_CACHE_DIGESTS=on "Enable cache digests"
SQUID_WCCP=on "Enable Web Cache Coordination Prot. v1"
SQUID_STRICT_HTTP=on "Be strictly HTTP compliant"
SQUID_IDENT=on "Enable ident (RFC 931) lookups"
SQUID_REFERER_LOG=on "Enable Referer-header logging"
SQUID_USERAGENT_LOG=on "Enable User-Agent-header logging"
SQUID_IPFW=off "Enable transparent proxying with IPFW"
SQUID_PF=off "Enable transparent proxying with PF"
SQUID_IPFILTER=off "Enable transp. proxying with IPFilter"
SQUID_ICAP=off "Enable ICAP client functionality"
SQUID_ESI=off "Enable ESI support (experimental)"
SQUID_COSS=off "Enable the COSS storage scheme"
SQUID_LARGEFILE=on "Support log and cache files >2GB"
SQUID_DEBUG=off "Enable debugging options"
===> Use 'make config' to modify these settings
# make install clean
漫长的安装过程又来了, 我该干点什么呢?看看新浪互联星空播客吧!速度挺快的,支持!!!
Squid 安装好了,现在开始配置她了。安装完后,在/usr/local/etc/squid下有squid的配置文件squid.conf和 squid.conf.default,这两个都是一样的,我们先删除掉squid.conf,在建个新的squid.conf,然后把我们的配置信息写 在里面,这样的话更加清晰一点,省得在原来的配置文件中改,里面内容那么多,改到后来,自己都不知道改了那些东西,糊涂了,如果对配置有什么不清楚的还是 可以参考squid.conf.default文件的。
# rm -rf squid.conf
# touch squid.conf
# ee squid.conf
http_port 192.168.10.30:3128 vhost vport defaultsite=www.rd.bj
cache_mem 64 MB
cache_swap_low 90
maximum_object_size 20 MB
minimum_object_size 0 KB
maximum_object_size_in_memory 5 MB
ipcache_size 1024
ipcache_low 90
fqdncache_size 1024
#acl all src 0.0.0.0/0.0.0.0 #好像squid30已经内置了
acl gsrc src 192.168.10.20 192.168.10.30 192.168.10.31 192.168.10.40
http_access allow gsrc
acl Manager proto cache_object
acl Localhost src 127.0.0.1
http_access allow Manager Localhost
acl Safe_ports port 3128 80 3130 3131
http_access allow all
cache_mgr admin@rd.bj
cache_effective_user squid
cache_effective_group squid
tcp_recv_bufsize 65536 bytes
cache_peer_access 192.168.10.31 allow all
cache_peer 192.168.10.40 parent 80 0 no-query originserver no-digest
access_log /usr/local/squid/logs/access.log
cache_dir diskd /usr/local/squid/cache 256 16 256 Q1=60 Q2=50
error_directory /usr/local/etc/squid/errors/Simplify_Chinese
icp_port 3130
htcp_port 0
icp_query_timeout 2000
icp_access allow all
digest_generation on
icp_hit_stale on
保存退出后,我们验证一下配置文件是否正确:
# rehash
# squid parse
OK,现在我们先根据配置文件创建缓存目录。
# squid -z
2007/12/27 12:43:55| Creating Swap Directories
2007/12/27 12:43:55| Making directories in /usr/local/squid/cache/00
2007/12/27 12:43:55| Making directories in /usr/local/squid/cache/01
2007/12/27 12:43:55| Making directories in /usr/local/squid/cache/02
2007/12/27 12:43:55| Making directories in /usr/local/squid/cache/03
2007/12/27 12:43:56| Making directories in /usr/local/squid/cache/05
2007/12/27 12:43:57| Making directories in /usr/local/squid/cache/06
2007/12/27 12:43:58| Making directories in /usr/local/squid/cache/07
2007/12/27 12:43:58| Making directories in /usr/local/squid/cache/08
2007/12/27 12:43:59| Making directories in /usr/local/squid/cache/0A
2007/12/27 12:43:59| Making directories in /usr/local/squid/cache/0C
2007/12/27 12:44:00| Making directories in /usr/local/squid/cache/0D
2007/12/27 12:44:01| Making directories in /usr/local/squid/cache/0F
这样就创建完成了。
在这里我补充一点,如果创建缓存目录失败的,多半是目录读写权限的问题。因为我们是ports安装的,所以系统会跟我们预先创建好squid用户和用户组。并把家目录指向/usr/local/squid。所以我们这里一般不会有问题。但是,如果大家是用下载的源码自行编译又想把缓存目录换到别的位置或是用个新硬盘存放,那改怎么办呢?我慢慢跟你道来。
首先我们格式化新硬盘
可以利用sysinstal来完成,具体操作可以参考FressBSD安装的那个章节有介绍,这里不说了。格式化好硬盘后,因为我们是用来存放缓存文件的,所以我们对该块硬盘做点小优化。
# newfs -b 8192 -f 1024 /dev/ad1s1d
# tunefs -n enable /dev/ad1s1d # 启用Soft Updates,必需在硬盘没有被挂载的时候或在单用户模式下才可以应用
# mount /dev/ad1s1d /cache
# ee /etc/fstab # 加载硬盘
补充小知识:
当 我们的分区主要存放大量小型文件时,我们会将block size 调小一点,如 8K 或是 4K。而在 newfs 时,我们也会指定fragment size,它的值最好是 block size 的八分之一,例如当block size 为8K 时,我们会使用newfs -b 8192 -f 1024 来格式化硬盘。如果您使用的是/stand/sysinstall 来格式化硬盘,您可以在格式化硬盘时按N来设置newfs option。
新硬盘安装好了以后,我们现在来做配置:
# pw groupadd squid
# pw useradd squid -s /usr/sbin/nologin -d /nonexistent -g squid
# mkdir /cache/www.rd.bj #建立缓存目录
# chown -R squid:squid /cache/www.rd.bj
好了,现在只需要把squid.conf里的
改成
cache_dir diskd /cache/www.rd.bj 256 16 256 Q1=60 Q2=50
# squid -z
好了就补充到这里吧,我们继续我们的探索之旅。
现在squid的配置文件已经测试无误了,那我们还等什么,赶紧测试一下服务叻!
# squid -CDNd1
2007/12/27 14:01:56| Starting Squid Cache version 3.0.STABLE1 for i386-portbld-freebsd6.3...
2007/12/27 14:01:56| Process ID 810
2007/12/27 14:01:56| DNS Socket created at 0.0.0.0, port 49839, FD 5
2007/12/27 14:01:56| Adding nameserver 192.168.10.40 from /etc/resolv.conf
2007/12/27 14:01:56| User-Agent logging is disabled.
2007/12/27 14:01:56| Referer logging is disabled.
2007/12/27 14:01:56| Unlinkd pipe opened on FD 9
2007/12/27 14:01:56| Local cache digest enabled; rebuild/rewrite every 3600/3600 sec
2007/12/27 14:01:56| Swap maxSize 262144 KB, estimated 20164 objects
2007/12/27 14:01:56| Target number of buckets: 1008
2007/12/27 14:01:56| Max Mem size: 8192 KB
2007/12/27 14:01:57| Rebuilding storage in /usr/local/squid/cache (DIRTY)
2007/12/27 14:01:57| Current Directory is /root
2007/12/27 14:01:57| Accepting accelerated HTTP connections at 192.168.10.30, port 3128, FD 11.
2007/12/27 14:01:57| Accepting ICP messages at 0.0.0.0, port 3130, FD 12.
2007/12/27 14:01:57| Configuring Sibling 192.168.10.31/3128/3131
2007/12/27 14:01:57| Configuring Parent 192.168.10.40/80/0
2007/12/27 14:02:04| Done scanning /usr/local/squid/cache swaplog (0 entries)
2007/12/27 14:02:04| Finished rebuilding storage from disk.
2007/12/27 14:02:04| 0 Invalid entries.
2007/12/27 14:02:04| 0 Objects loaded.
2007/12/27 14:02:04| 0 Objects expired.
2007/12/27 14:02:04| 0 Objects cancelled.
2007/12/27 14:02:04| 0 Duplicate URLs purged.
2007/12/27 14:02:04| 0 Swapfile clashes avoided.
2007/12/27 14:02:04| Took 6.97 seconds ( 0.00 objects/sec).
2007/12/27 14:02:04| Completed Validation Procedure
2007/12/27 14:02:04| Validated 25 Entries
2007/12/27 14:02:04| store_swap_size = 0
2007/12/27 14:02:04| storeLateRelease: released 0 objects
启动没有什么问题,来我们用浏览器访问一下吧!
正式启动可以使用:
OK,我们的Squid01的配置就到这里, 现在我们关闭虚拟机,然后拷贝一份squid01为squid02,用来配置另一台Squid服务器。
复制好squid02后,我们现在开始配置了, 应为squid01的大部分工作都已经做好了, 所以squid02的配置就比较方便了,只要是配置文件中IP地址和机器名的修改。
# ee /etc/rc.conf
defaultrouter="192.168.10.10"
hostname="squid02.rd.bj"
# ee /etc/hosts
192.168.10.31 squid02.rd.bj
# ee /usr/local/etc/squid/squid.conf
最后修改好的配置文件为:
http_port 192.168.10.31:3128 vhost vport defaultsite=www.rd.bj
cache_swap_low 90
cache_swap_high 95
minimum_object_size 0 KB
maximum_object_size_in_memory 5 MB
ipcache_size 1024
ipcache_low 90
ipcache_high 95
fqdncache_size 1024
#acl all src 0.0.0.0/0.0.0.0
http_access allow gsrc
acl Manager proto cache_object
acl Localhost src 127.0.0.1
http_access allow Manager Localhost
acl Safe_ports port 3128 80 3130 3131
http_access allow all
visible_hostname squid01.rd.bj
cache_mgr admin@rd.bj
cache_effective_group squid
tcp_recv_bufsize 65536 bytes
cache_peer 192.168.10.30 sibling 3128 3130
cache_peer 192.168.10.40 parent 80 0 no-query originserver no-digest
access_log /usr/local/squid/logs/access.log
cache_dir diskd /usr/local/squid/cache 256 16 256 Q1=60 Q2=50
icp_port 3131
icp_query_timeout 2000
icp_access allow all
digest_generation on
log_icp_queries on
最后,关于Squid,给大家推荐一本好书《Squid中文权威指南》虽然讲的是squid2.5版本的,但是有很好的指导意义,我相信大多数人都已经看过了,在此推荐是对作者辛勤劳动的无比崇敬。好,我们即将要踏上proxy服务器之旅。
相关文章
Linux初学(CnetOS7 Linux)之切换命令模式和图形模式的方法
本篇文章主要介绍了Linux初学(CnetOS Linux7)之切换命令模式和图形模式的方法,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧2018-03-03Linux之进程的虚拟地址空间,逻辑地址和物理地址,进程管理命令
这篇文章主要介绍了Linux之进程的虚拟地址空间,逻辑地址和物理地址,进程管理命令,具有很好的参考价值,希望对大家有所帮助。如有错误或未考虑完全的地方,望不吝赐教2023-03-03
最新评论