搭建一个大型网站架构的实验环境(Squid缓存服务器篇)

news/2024/5/9 0:37:32/文章来源:https://blog.csdn.net/wmlunge/article/details/7715906
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"           
hostname="squid01.rd.bj"

# ee /etc/hosts
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
# make config     #配置安装选项
sq_1
# make showconfig    #我的配置选项
===> 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_DNS_HELPER=off "Use the old 'dnsserver' 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_WCCPV2=on "Enable Web Cache Coordination Prot. v2"
     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_ARP_ACL=off "Enable ACLs based on ethernet address"
     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_AUFS=off "Enable the aufs storage scheme"
     SQUID_COSS=off "Enable the COSS storage scheme"
     SQUID_KQUEUE=on "Use kqueue(2) (experimental)"
     SQUID_LARGEFILE=on "Support log and cache files >2GB"
     SQUID_STACKTRACES=off "Create backtraces on fatal errors"
     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文件的。
# cd /usr/local/etc/squid
# 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
cache_swap_high 95
maximum_object_size 20 MB
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 #好像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 deny !Safe_ports
http_access allow all

visible_hostname squid01.rd.bj
cache_mgr admin@rd.bj

cache_effective_user squid
cache_effective_group squid
tcp_recv_bufsize 65536 bytes

cache_peer 192.168.10.31 sibling 3128 3131
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
log_icp_queries 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| /usr/local/squid/cache exists
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/04
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/09
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/0B
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:00| Making directories in /usr/local/squid/cache/0E
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     # 加载硬盘
/dev/ad1s1d             /cache            ufs     rw              2       2
补充小知识:
FreeBSD 系统在block size 为8K或16K时有最好的表现,而使用newfs 进行格式化时,预设的 block size 为16K。然而,当我们的服务器是做为数据库用途时,由于数据库的存取是随机存取,所以在 block size 为 8K 时会有比较好的表现。如果我们将block size设为 16K 以上,比较容易造成空间浪费及空间破碎的问题,进而造成效能低落。
当我们的分区主要存放大量小型文件时,我们会将block size 调小一点,如 8K 或是 4K。而在 newfs 时,我们也会指定fragment size,它的值最好是 block size 的八分之一,例如当block size 为8K 时,我们会使用newfs -b 8192 -f 1024 来格式化硬盘。如果您使用的是/stand/sysinstall 来格式化硬盘,您可以在格式化硬盘时按N来设置newfs option。
当我们的分区主要用来存放少量大文件时,例如数据库,我们可以使用 newfs 参数 -i 设定 inode 所占空间大一点以减少 inode 的数量 (也就是可以建立的文件及目录数量),让系统在不正常关机后,开机时进行 fsck 时可以快一点。不过在修改inode 数量时要注意,否则您可能会遇到硬盘空间明明未满却无法新增文件的窘境。若要使用大型的inode,FreeBSD建议的inode 大小为32768、65536、或 262144,再大的话只会降低效能。
新硬盘安装好了以后,我们现在来做配置:
# 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 /usr/local/squid/cache 256 16 256 Q1=60 Q2=50
改成
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| With 32768 file descriptors available
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| Using 8192 Store buckets
2007/12/27 14:01:56| Max Mem size: 8192 KB
2007/12/27 14:01:56| Max Swap size: 262144 KB
2007/12/27 14:01:57| Rebuilding storage in /usr/local/squid/cache (DIRTY)
2007/12/27 14:01:57| Using Least Load store dir selection
2007/12/27 14:01:57| Current Directory is /root
2007/12/27 14:01:57| Loaded Icons.
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| HTCP Disabled.
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:01:57| Ready to serve requests.
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 Entries scanned
2007/12/27 14:02:04|         0 Invalid entries.
2007/12/27 14:02:04|         0 With invalid flags.
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| Beginning Validation Procedure
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

启动没有什么问题,来我们用浏览器访问一下吧!
 
看到这样的页面说明Squid服务器是正常的,之所以出现错误页面,那是因为我们那台提供web服务的虚拟机没有启动的原因。
正式启动可以使用:
# squid -D

OK,我们的Squid01的配置就到这里, 现在我们关闭虚拟机,然后拷贝一份squid01为squid02,用来配置另一台Squid服务器。

复制好squid02后,我们现在开始配置了, 应为squid01的大部分工作都已经做好了, 所以squid02的配置就比较方便了,只要是配置文件中IP地址和机器名的修改。
服务器网络配置
# ee /etc/rc.conf
ifconfig_lnc0="inet 192.168.10.31 netmask 255.255.255.0"
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_mem 64 MB
cache_swap_low 90
cache_swap_high 95
maximum_object_size 20 MB
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
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 deny !Safe_ports
http_access allow all

visible_hostname squid01.rd.bj
cache_mgr admin@rd.bj
cache_effective_user squid                           
cache_effective_group squid                          
tcp_recv_bufsize 65536 bytes                         
cache_peer 192.168.10.30 sibling 3128 3130           
cache_peer_access 192.168.10.30 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 3131
htcp_port 0
icp_query_timeout 2000
icp_access allow all
digest_generation on
log_icp_queries on
icp_hit_stale on

保存退出后,按照squid01的测试方法,对squid02进行测试,如果结果和squid01一样,那我们的squid缓存服务器也就暂告一段落了。

最后,关于Squid,给大家推荐一本好书《Squid中文权威指南》虽然讲的是squid2.5版本的,但是有很好的指导意义,我相信大多数人都已经看过了,在此推荐是对作者辛勤劳动的无比崇敬。好,我们即将要踏上proxy服务器之旅。

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.luyixian.cn/news_show_899416.aspx

如若内容造成侵权/违法违规/事实不符,请联系dt猫网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

12个顶级开发者社区网站帮助程序员走上人生巅峰

公元二十一世纪,世界迎来了大互联网时代,程序员这个行当已然成为了医生、律师等高端中产阶级职业之外的又一高薪职业。不过既然是技术职业,自然也 就会分三六九等,没理想的程序员只能写着自己擅长的代码,加着没玩没了的…

[转载]说说大型高并发高负载网站的系统架构

| 评论 # yueguoliang发表于2007-09-29 16:08:37IP: 211.94.149.* ju ti dian shuo ming fang an cai hao # fxbird发表于2007-09-29 16:19:19IP: 59.44.72.* 这才是高质量的文章。 # oldmoon发表于2007-09-29 17:36:43IP: 116.252.70.* 受益匪浅 # irplay发表于2007-09-30 09:…

互联网网站的反爬虫策略浅析(收藏)

关键字: crawler 因为搜索引擎的流行,网络爬虫已经成了很普及网络技术,除了专门做搜索的Google,Yahoo,微软,百度以外,几乎每个大型门户网站都有自己的搜索引擎,大大小小叫得出来名字得就几十种&…

LAMP网站架构方案分析

LAMP(Linux-Apache-MySQL-PHP)网站架构是目前国际流行的Web框架,该框架包括:Linux操作系统,Apache网络服务器,MySQL数据库,Perl、PHP或者Python编程语言,所有组成产品均是开源软件&a…

【转】使用 Nginx 提升网站访问速度【反向代理】

Nginx 简介 Nginx ("engine x") 是一个高性能的 HTTP 和 反向代理 服务器,也是一个 IMAP/POP3/SMTP 代理服务器。 Nginx 是由 Igor Sysoev 为俄罗斯访问量第二的 Rambler.ru 站点开发的,它已经在该站点运行超过两年半了。 Igor 将源代码以类 …

HTML——简单的网站首页

学习记录帖&#xff08;一&#xff09; 简单的网站首页 这是我的一个记录帖&#xff0c;我是按照黑马程序员的视频学习的。 使用的是HBuilder&#xff0c;学习了html & css & js & jq & bootstrap。 成果 代码 <!DOCTYPE html> <html><head…

Web网站服务(Apache)

Apache网站服务基础 Apache HTTP server 是广泛应用的Web应用之一 Apache简介 Apache HTTP server 是开源软件项目的杰出代表&#xff0c;基于标准的HTTP网络协议提供网页浏览器&#xff0c;Apache服务器可以运行在Linux&#xff0c;UNIX&#xff0c;Windows等多种操作系统平…

使用 HttpWebRequest 向网站提交数据

转自&#xff1a;http://www.cnblogs.com/webman/archive/2006/11/17/564106.html HttpWebRequest 是 .net 基类库中的一个类&#xff0c;在命名空间 System.Net 下面&#xff0c;用来使用户通过 HTTP 协议和服务器交互。 HttpWebRequest 对 HTTP 协议进行了完整的封装&#x…

创建springboot项目时改为国内网站

总结 &#xff1a; 第一点&#xff1a;今天进行了蓝桥杯 的竞赛&#xff0c;说一说我的感悟&#xff0c;还是练得不够&#xff0c;其实有挺多熟悉的题&#xff0c;可是还是没做出来&#xff0c;还是征战明年的蓝桥杯吧&#xff0c;还有就是&#xff0c;电脑的问题&#xff0c;…

IISphpstudy搭建网站之:IIS切换phpstudy

为节省内存消耗&#xff0c;在同一台windows2003上搭建了IIS和phpstudy两种类型网站&#xff0c;但一次只开一种。 开启服务时发现&#xff0c;因都是使用80端口&#xff0c;所以会有冲突现象&#xff0c;一般IIS会开机自启&#xff0c;而启动phpstudy时经常报错显示端口被占用…

网站项目管理-如何做好需求分析(转)

前言 随着技术的不断发展和用户对网站功能性的需求不断提高&#xff0c;如今网站项目的设计已经不能再仅仅简单地利用静态Html文件来实现&#xff0c;与前几年网站设计由一两名网页设计师自由的创作相比&#xff0c;网站项目的设计和开发越来越像一个软件工程&#xff0c;也越来…

一个网站的LOGO

今天董事长叫我去谈了话&#xff0c;有了一个网站的构想 于是就先做一个LOGO也来了&#xff0c;好久没有做美工方面的东东了 希望这个LOGO能用上&#xff0c;把网站做起来 像我这种人天生就是为做网站的 董事长也说以前让我们做那些&#xff0c;对我们来说也是和自己的专长搭不…

什么是SSL加密证书?SSL加密证书在网站中有什么作用?SSL加密证书怎么做?SSL证书在网站中有什么好处?

标题什么是SSL加密证书&#xff1f;SSL加密证书在网站中有什么作用&#xff1f;SSL加密证书怎么做&#xff1f;SSL证书在网站中有什么好处&#xff1f;SSL证书又叫做数据加密证书&#xff0c;是保证网站在客户端和服务之前数据传输的安全性&#xff0c;反正我们的网站内容在数据…

通过request对象获取访问网站用户的 IP 访问者的浏览器名 操作系统名 从哪里转过来 以及 Url 上的所有参数...

通过request对象获取访问网站用户的 IP 访问者的浏览器名 操作系统名 从哪里转过来 以及 Url 上的所有参数 可用于jsp 或者 servlet

DIV与Table布局在大型网站的可用性比较

DIV与Table布局在大型网站的可用性比较

使用nginx实现网站负载均衡测试实例

本文版权归学IT网(www.xueit.com)所有&#xff0c;任何单位与个人转载必须保留此段声明&#xff0c;且在文章页面明显位置给出原文连接&#xff0c;否则保留追究法律责任的权利。 如果你关注过nginx&#xff0c;必定知道nginx这个软件有什么用的&#xff0c;如果你的网站访问量…

wordpress企业网站模板

设计精美的wordpress企业网站主题模板 国潮好物wordpress主题模板 国潮好物&#xff0c;配国产主题&#xff0c;为中国制造加油、助力&#xff0c;适合生产、加工、制造业官网的WordPress主题。 WordPress是啥&#xff1f; WordPress是使用PHP语言开发的博客平台&#xff0c…

wordpress企业网站主题

制造业WordPress网站模板 为中国制造2025加油打Call&#xff0c;适合用于生产加工制造行业的WordPress网站模板。 用wordpress主题模板&#xff0c;可以快速搭建起企业官方网站。 wordpress是最好的CMS建站系统 中小微企业建展示型企业官方网站&#xff0c;用wordpress是最佳…

适合外贸建站的wordpress模板

一个好的模板是一个wordpress企业网站的核心和灵魂&#xff0c;强大的wordpress内核足够任何一个中小企业的建站需求。程序方面完全不需要考虑&#xff0c;wordpress外贸建站需要考虑的就是选择一款适合自己的wordpress外贸网站模板。 下面整理了一些非常不错的wordpress网站模…