视频1 视频21 视频41 视频61 视频文章1 视频文章21 视频文章41 视频文章61 推荐1 推荐3 推荐5 推荐7 推荐9 推荐11 推荐13 推荐15 推荐17 推荐19 推荐21 推荐23 推荐25 推荐27 推荐29 推荐31 推荐33 推荐35 推荐37 推荐39 推荐41 推荐43 推荐45 推荐47 推荐49 关键词1 关键词101 关键词201 关键词301 关键词401 关键词501 关键词601 关键词701 关键词801 关键词901 关键词1001 关键词1101 关键词1201 关键词1301 关键词1401 关键词1501 关键词1601 关键词1701 关键词1801 关键词1901 视频扩展1 视频扩展6 视频扩展11 视频扩展16 文章1 文章201 文章401 文章601 文章801 文章1001 资讯1 资讯501 资讯1001 资讯1501 标签1 标签501 标签1001 关键词1 关键词501 关键词1001 关键词1501 专题2001
利用squid加速apache
2020-11-09 08:23:06 责编:小采
文档


安装apache

tar zxvf httpd-2.2.14.tar.gz

cd httpd-2.2.14

./configure --prefix=/usr/local/apache2

make&&make install

配置参数可以根据自己的需求来

apache配置如下:
Listen 81
NameVirtualHost *


Options FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
Satisfy all


ServerName www.zhlinux.com
ServerAdmin wenmin@wvuu.net
DocumentRoot "/usr/local/apache2/htdocs/"
DirectoryIndex index.html
# ErrorLog "/usr/local/apache/logs/abc-error_log"
# SetEnvIf Remote_Addr "::1" dontlog
# CustomLog "/usr/local/apache/logs/abc-access_log" combined env=!dontlog

启动apache
查看监听端口

netstat -ntpl | grep 81

安装squid

useradd squid
tar zxvf squid-3.0.STABLE4.tar.gz

cd squid-3.0.STABLE4

./configure --prefix=/usr/local/squid --disable-carp --with-aufs-threads=32 --with-pthreads --enable-storeio='ufs,aufs,coss,null' --enable-disk-io='AIO,Blocking' --enable-removal-policies='heap,lru' --disable-w --enable-kill-parent-hack --disable-snmp --disable-poll --disable-select --enable-auth=basic --with-aio --disable-ident-lookup --with-filedescriptors=65536

make&&make install

cd /usr/local/squid/var/logs/
touch cache.log
chmod 755 cache.log
chown squid:squid cache.log
touch page_zs_access_log
chmod 755 page_zs_access_log
chown squid:squid page_zs_access_log

配置squid.conf文件

vi /usr/local/squid/etc/squid.conf

visible_hostname www.zhlinux.com
http_port 80 vhost vport
cache_mem 512 MB
maximum_object_size_in_memory 2048 KB
memory_replacement_policy lru
cache_dir ufs /tmp 512 16 256
max_open_disk_fds 0
minimum_object_size 0 KB
maximum_object_size 32768 KB
logformat combined %>a %ui %un [%tl] "%rm %ru HTTP/%rv" %Hs %h" "%{User-Agent}>h" %Ss:%Sh
access_log /usr/local/squid/var/logs/page_zs_access_log combined
pid_filename /usr/local/squid/var/logs/squid.pid
cache_store_log none
cache_peer 127.0.0.1 parent 81 0 no-query no-digest originserver name=www
cache_peer_domain www www.zhlinux.com
cache_peer_access www allow all
http_access allow all
acl QUERY urlpath_regex cgi-bin .php .cgi .avi .wmv .rm .ram .mpg .mpeg .zip .exe
cache deny QUERY
cache_effective_user squid
cache_effective_group squid

验证squid.conf配置是否正确
/usr/local/squid/sbin/squid -k parse

如果没有问题会显示
/usr/local/squid/etc/squid.conf (depth 0)

/usr/local/squid/sbin/squid -z
用来Creating Swap Directories

创建squid启动脚本

vi squid.sh

#!/bin/sh
#
ulimit -HSn 15000
# this script starts and stops Squid
echo 15000 > /proc/sys/fs/file-max
case "$1" in
start)
/usr/local/squid/sbin/squid -s
echo -n ' Squid'
;;
stop)
/usr/local/squid/sbin/squid -k shutdown
;;
esac
赋予执行权限

chmod x squid.sh

./squid.sh start

查看有没有启动
#ps fax|grep squid
13750 pts/3 S 0:00 \_ grep squid
30474 ? Ss 0:00 /usr/local/squid/sbin/squid -s
30476 ? S 0:01 \_ (squid) -s
则证明OK

more /usr/local/squid/var/logs/page_zs_access_log |grep TCP_MEM_HIT
该指令可以看到在squid运行过程中,有那些文件被squid缓存到内存中,并返回给访问用户

more /usr/local/squid/var/logs/page_zs_access_log |grep TCP_HIT
该指令可以看到在squid运行过程中,有那些文件被squid缓存到cache目录中,并返回给访问用户

可以查看下命中率及其他相关信息
#/usr/local/squid/bin/squidclient -p 80 -h localhost mgr:info

说明:本文档是参照网络上一些文档而写。

下载本文
显示全文
专题