在路上 ……

Linux系统运维与架构

简单原理说明:
squid可以缓存经常访问的静态页面,图片等,因此加上squid以后,客户端再访问这些页面的时候就会直接从squid的缓存中读取,而不再去向apache请求了
服务器上先按照正常安装好apache,确保能够正常访问,然后安装squid
下载squid,地址:http://www.squid-cache.org/Versions/v2/2.5/squid-2.5.STABLE10.tar.gz(这是当前稳定版的最新一个)
解压缩

tar zxvf squid-2.5.STABLE10.tar.gz
cd squid-2.5.STABLE10

使用如下的命令行来配置squid

./configure --enable-useragent-log --enable-referer-log --disable-icmp --disable-delay-pools --enable-default-err-language=Simplify_Chinese --enable-err-languages="Simplify_Chinese English" --disable-internal-dns --enable-async-io=160 --enable-cahce-digests --enable-underscore --enable-kill-parent-hack --enable-gnuregex

关于每一项参数的说明,请参考./configure --help
然后make,确认编译正常没有报错信息,就make install 安装,默认的安装路径是/usr/local/squid
添加squid用户和组

groupadd squid
useradd squid -g squid -s /sbin/nologin

创建高速缓存目录和log目录

cd /var/
mkdir squid
cd squid
mkdir cache
mkdir logs
chown -R squid:squid /var/squid

修改squid配置文件squid.conf为以下内容

http_port 80
icp_port 0
hierarchy_stoplist cgi-bin ?
acl QUERY urlpath_regex cgi-bin \? \.asp \.php \.jsp \.cgi
no_cache deny QUERY
cache_mem 128 MB
log_icp_queries off
half_closed_clients off
cache_swap_low 60
cache_swap_high 95
maximum_object_size 1024 KB
minimum_object_size 0 KB
maximum_object_size_in_memory 8 KB
ipcache_size 1024
ipcache_low 90
ipcache_high 95
cache_dir ufs /var/squid/cache 4096 16 256
cache_access_log none
cache_log /var/squid/logs/cache.log
cache_store_log none
pid_filename /var/squid/logs/squid.pid
quick_abort_min 16 KB
quick_abort_max 16 KB
quick_abort_pct 95
connect_timeout 120 seconds
read_timeout 15 minutes
request_timeout 30 seconds
client_lifetime 60 minutes
pconn_timeout 120 seconds
dns_children 20
redirect_children 20
refresh_pattern ^ftp: 1440 20% 10080
refresh_pattern ^gopher: 1440 0% 1440
refresh_pattern -i .html 0 40% 60 ignore-reload
refresh_pattern -i .hml 0 40% 60 ignore-reload
refresh_pattern -i .gif 10 40% 60 ignore-reload
refresh_pattern -i .swf 10 40% 60 ignore-reload
refresh_pattern -i .jpg 10 40% 60 ignore-reload
refresh_pattern -i .js$ 10 40% 60 ignore-reload
refresh_pattern -i .css 10 40% 60 ignore-reload
refresh_pattern . 0 20% 60
acl all src 0.0.0.0/0.0.0.0
acl manager proto cache_object
acl localhost src 127.0.0.1/255.255.255.255
acl to_localhost dst 127.0.0.0/8
acl SSL_ports port 443 563
acl Safe_ports port 80 # http
acl Safe_ports port 21 # ftp
acl Safe_ports port 443 563 # https, snews
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 Safe_ports port 8080
acl CONNECT method CONNECT
acl conncount maxconn 20
http_access deny conncount 
http_access allow manager localhost
http_access deny manager
http_access deny !Safe_ports
http_access deny CONNECT !SSL_ports
http_access allow all
http_reply_access allow all
icp_access allow all
cache_effective_user squid
cache_effective_group squid
visible_hostname 192.168.18.114
redirect_rewrites_host_header off
httpd_accel_port 8080
httpd_accel_host virtual
httpd_accel_uses_host_header on
buffered_logs on
icp_access allow all
cache_mgr lilu@zhongsou.com
coredump_dir /var/squid/cache
logfile_rotate 2

为了能够和squid相配合,修改apache的配置文件httpd.conf
一,修改apache监听端口

port 8080

二,修改虚拟主机设置的端口,举例如下

NameVirtualHost 192.168.18.114:8080
<VirtualHost 192.168.18.114:8080>
ServerAdmin webmaster@dummy-host.example.com
DocumentRoot /zhongsou
ServerName test.test.com
</VirtualHost>
<VirtualHost 192.168.18.114:8080>
ServerAdmin webmaster@dummy-host.example.com
DocumentRoot /usr/local/apache/htdocs
ServerName test.example.com
</VirtualHost>

所有的虚拟主机都要修改
其次为了能够正确记录来访者的IP,需要修改CustomLog
将%h改为%{X-Forwarded-For}i,其余不变
然后分别起动apache和squid

/usr/local/apache/bin/apachectl start
/usr/local/squid/sbin/squid -z
/usr/local/squid/sbin/squid -D

然后netstat -na|grep LISTEN查看一下80端口和8080端口是否已经处在监听状态了
然后就可以进行测试了。


人活着究竟是为了什么?
这个问题我好像一直没想过,今天看了S的blog,突然在问自己这个问题。
为了自己?好像是,人不为己,天诛地灭。为了自己能活得更好,我们在不停的奔波忙碌,可结果却并不一定如己所愿,更多的时候是失望大于希望,“人生不如意,十有八九啊”。
为了父母?可能是,父母的养育之恩,无以为报,只能尽自己的能力在有生之年好好报答。但这只是生活的一个组成部分,而不是活着的目的。
为了朋友?不会吧,朋友只是生活中的一些点缀,就像是果仁巧克力中的果仁,给生活增加一些味道,使生活不至于平淡乏味。
想了半天,我觉得我活着谁也不为,活着就是活着,活着就是为了活着。


新的公司,一切都是新鲜的。新的开始,我要一切都从头做好!

Add at 2014-4-13:
正好今年也新换了公司,真的又是一个新的开始!
这个blog也是新的,我要把原来的blog全都转过来!


Typecho 强力驱动