haproxy + Squid 3.3.3 安装与基本配置
haproxy + Squid 3.3.3 安装与基本配置
由于做测试开发用,搭建测试环境 haproxy + 2 * squid 3.3.3 方案, squid 2.7 比较稳定,性能高
服务器环境是centos 6.3
你可以直接使用命令安装haproxy 和squid
yum install haproxy
yum install squid
或者你可以手动编译安装, 由于只有一个haproxy 我就直接yum install haproxy ,squid 是手动编译的
1. 先安装haproxy
yum install haproxy
service haproxy start
[root@dev_node0 etc]# vim /etc/haproxy/haproxy.cfg
将默认的配置文件的部分内容,改成一下内容
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | #--------------------------------------------------------------------- # main frontend which proxys to the backends #--------------------------------------------------------------------- frontend main *: 80 acl url_static path_beg -i / static /images /javascript /stylesheets acl url_static path_end -i .jpg .gif .png .css .js default_backend app #--------------------------------------------------------------------- # static backend for serving up images, stylesheets and such #--------------------------------------------------------------------- #--------------------------------------------------------------------- # round robin balancing between the var ious backends #--------------------------------------------------------------------- backend app balance roundrobin server dev_node0 127.0 . 0.1 : 81 weight 3 check server dev_node0 127.0 . 0.1 : 82 weight 3 check |
大体意思就是 监听80端口,然后通过论询方式,将消息抛给81,82端口, haproxy 配置完成
[root@dev_node0 ~]# service haproxy start
Starting haproxy: [ OK ]
2. 编译安装squid
先从官网下载安装包,
[root@dev_node0 data]# ls
haproxy-1.4.22.tar.gz squid-3.3.3 squid-3.3.3.tar.gz
[root@dev_node0 data]# cd squid-3.3.3
[root@dev_node0 data]#./configure --prefix=/usr/local/squid
[root@dev_node0 data]# make all
[root@dev_node0 data]# make install
[root@dev_node0 data]# cd /usr/local/squid/etc/
[root@dev_node0 data]# vim squid.conf
1 2 3 4 5 6 7 8 9 10 | # Squid normally listens to port 3128 http_port 81 accel vhost vport= 80 allow-direct visible_hostname dev_node0 hosts_file /usr/local/squid/etc/hosts # Uncomment and adjust the following to add a disk cache directory. cache_dir ufs /usr/local/squid/ var /cache/squid 100 16 256 # Leave coredumps in the first cache dir coredump_dir /usr/local/squid/ var /cache/squid |
将配置文件部分内容改成上面形式, squid 监听81 端口
编译安装squid1(这里注意把原来的加压包删除,重新解压一份)
cd squid-3.3.3
./configure --prefix=/usr/local/squid1
make all
make install
cd /usr/local/squid1/etc/
1 2 3 4 5 6 7 8 9 10 | # Squid normally listens to port 3128 http_port 82 accel vhost vport= 80 allow-direct visible_hostname dev_node0 hosts_file /usr/local/squid1/etc/hosts # Uncomment and adjust the following to add a disk cache directory. cache_dir ufs /usr/local/squid1/ var /cache/squid 100 16 256 # Leave coredumps in the first cache dir coredump_dir /usr/local/squid1/ var /cache/squid |
上面配置hosts_file 所指向的hosts 的内容是 223.4.233.33 mai********.net ---- mai******.net 的源站IP
到这里haproxy 跟两个squid都已经配置完成,下面是启动,测试流程
3. 本机测试
绑定host
root@xieyugui:/home/xie# vim /etc/hosts
192.168.8.119 mai********.net
[root@dev_node0 squid]# tail -f /usr/local/squid/var/logs/access.log
[root@dev_node0 squid]# tail -f /usr/local/squid1/var/logs/access.log
分别打开两个终端 实时查看squid 的 access.log的日志
在浏览器中输入 mai********.net 发现方面页面正确,上面两个终端中,有一个显示的是
1363574578.218 163 127.0.0.1 TCP_MISS/200 1887 GET http://mai******.net/scripts/jquery.touchwipe.min.js - HIER_DIRECT/223.4.2*3.33 application/x-javascript
1363574578.266 319 127.0.0.1 TCP_MISS/200 11415 GET http://mai******.net/ - HIER_DIRECT/223.4.2*3.33 text/html
1363574578.298 28 127.0.0.1 TCP_MISS/200 3340 GET http://mai******.net/scripts/js_func.js - HIER_DIRECT/223.4.2*3.33 application/x-javascript
1363574578.942 640 127.0.0.1 TCP_MISS/200 243961 GET http://mai******.net/images/sliders/home_page_1/home1_slide_1.png - HIER_DIRECT/223.4.2*3.33 image/png
1363574579.024 1023 127.0.0.1 TCP_MISS/200 52117 GET http://mai******.net/stylesheets/responsive.css - HIER_DIRECT/223.4.2*3.33 text/css
1363574579.333 1331 127.0.0.1 TCP_MISS/200 95180 GET http://mai******.net/scripts/jquery.min.js - HIER_DIRECT/223.4.2*3.33 application/x-javascript
1363574579.981 921 127.0.0.1 TCP_MISS/200 275207 GET http://mai******.net/images/sliders/home_page_7/home7_slide_3.png - HIER_DIRECT/223.4.2*3.33 image/png
1363574580.199 37 127.0.0.1 TCP_MISS/200 1486 GET http://mai******.net/images/favicon.ico - HIER_DIRECT/223.4.2*3.33 text/plain
1363574580.450 53 127.0.0.1 TCP_MISS/200 501 GET http://mai******.net/images/text_bar.png - HIER_DIRECT/223.4.2*3.33 image/png
1363574580.579 1175 127.0.0.1 TCP_MISS/200 33638 GET http://mai******.net/images/testimonials/testimonials1.png - HIER_DIRECT/223.4.2*3.33 image/png
1363574580.639 81 127.0.0.1 TCP_MISS/200 2914 GET http://mai******.net/images/social/social_shadow.png - HIER_DIRECT/223.4.2*3.33 image/png
1363574580.736 87 127.0.0.1 TCP_MISS/200 3266 GET http://mai******.net/images/social/social_bg.png - HIER_DIRECT/223.4.2*3.33 image/png
1363574596.363 25 127.0.0.1 TCP_MISS/200 829 GET http://mai******.net/images/features/arrow.png - HIER_DIRECT/223.4.2*3.33 image/png
最好先关闭一下防火墙,你也可以设置安全端口
[root@dev_node0 logs]# /etc/init.d/iptables stop
[root@dev_node0 logs]# /etc/init.d/iptables status
iptables:未运行防火墙。
目录 返回
首页