标签:linux
squid(代理服务器)
-----------------------------------
client:192.168.4.1 virbr1 真实机
-----------------------------------
squid:192.168.4.5 network1
172.16.0.5 network2
------------------------------------
web:172.16.0.100 network2
-------------------------------------
环境配置
1.真实机(确认:virbr1(192.168.4.1)
2.设置squid服务器(2块网卡)
virt-manager设置(创建网络network2)
nic1:network1(192.168.4.5)
nic2:network2(172.16.0.5)
3.设置web服务器
nic:network2(172.16.0.100)
4.设置各虚拟机IP
squid虚拟机设置:
#ifconfig eth0 192.168.4.5
#ifconfig eth1 172.16.0.5
web虚拟机设置:
#ifconfig eth0 172.16.0.100
实验一:正向代理
squid服务器设置
#yum -y install squid
#vim /etc/squid/squid.conf
visible_hostname squid.example.com //主机名
http_access allow all //允许所有人访问
http_port 3128 //默认监听端口
cache_dir ufs /var/spool/squid 100 16 256
//缓冲位置/var/spool/squid
//100M的容量,自动创建16个一级子目录和256个二级子目录
#service squid start
#ls /var/spool/squid/
Web服务器设置:
#service httpd start
#echo "100" > /var/www/html/index.html
Client设置:
#firefox (编辑--首选项--高级--网络--设置)
手动设置代理,http代理:192.168.4.5,端口:3128
地址栏输入服务器的IP:172.16.0.100
++++++++++++++++++++++++++++
查看日志:
代理日志:/var/log/squid/access.log
HTTP日志:/var/log/httpd/access_log
实验二:反向代理
squid服务器设置:
#vim /etc/squid/squid.conf
http_port 80 vhost
cache_peer 172.16.0.100 parent 80 0 originserver
#service squid restart
注意端口冲突
客户端:取消实验一火狐浏览器的设置(代理)
#firefox http://192.168.4.5
#curl -I http://192.168.4.5/
++++++++++++++++++++
Squid访问控制
acl 名称 类型 内容
http_access allow acl名称
http_access deny acl名称
类型:
src 源地址dst 目标地址
port 目标端口dstdomain 目标域
time 访问时间maxconn 最大并发连接
url_regex 目标URL地址
urlpath_regex 整个目标URL路径
#vim /etc/squid/squid.conf
acl mytime time MTWHF 09:00-18:00
http_access deny mytime
#service squid restart
++++++++++++++++++++++++++
Varnish(Web加速服务器),缓存在内存
安装Varnish
#!/bin/bash
Varnish=varnish-3.0.6
yum -y install readline-devel pcre-devel
useradd -s /sbin/nologin varnish
tar -xzf $Varnish.tar.gz
cd $Varnish
./configure --prefix=/usr/local/varnish
make && make install
cp redhat/varnish.initrc /etc/init.d/varnish
cp redhat/varnish.sysconfig /etc/sysconfig/varnish
cp redhat/varnish_reload_vcl /usr/bin/
ln -s /usr/local/varnish/sbin/varnishd /usr/sbin/
#echo "111" >/etc/varnish/secret
#vim /etc/sysconfig/varnish 定义前端
VARNISH_VCL_CONF=/etc/varnish/default.vcl 定义后端配置文件位置及名称
VARNISH_LISTEN_PORT=80 //监听端口
VARNISH_STORAGE_SIZE=100M
//缓存大小
VARNISH_STORAGE="malloc,${VARNISH_STORAGE_SIZE}"
//使用内存缓冲,缓冲大小为100M
#mkdir /etc/varnish
#cp /usr/local/varnish/etc/varnish/default.vcl /etc/varnish/
#vim /etc/varnish/default.vcl 定义后端
backend default {
.host = "172.16.0.100";
.port = "80";
}
//定义,后台服务器是172.16.0.100,端口是80
#service varnish start
客户端验证:
#firefox http://192.168.4.5/
如果管理Varnish的缓冲
#ln -s /usr/local/varnish/bin/* /usr/bin/
#varnishadm -S /etc/varnish/secret 命令
#varnishadm
>help //查看所有命令
>start
>stop
>status
>backend.list
>ban.url
>ban.list
Varnish日志
#varnishncsa //访问日志
#varnishlog //程序日志
#varnishstat //查看状态
标签:linux
原文地址:http://13450661.blog.51cto.com/13440661/1978821