基于认证的代理平台搭建配置squid-20130730

功能:通过squid代理实现

(1)基于用户名密码认证的出口ip路由选择

(2)基于client源ip的出口ip路由选择

(3)基于连接本机ip的出口ip路由选择

(4)实现高度匿名代理

(5)通过snmp使用cacti监控squid的状态

一、squid 安装过程

wget http://www.squid-cache.org/Versions/v3/3.3/squid-3.3.8.tar.gz

tar xzvf squid-3.3.8.tar.gz 

cd squid-3.3.8

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

make

make install

二、开启多个公网ip

公网网卡挂接多个ip地址

# cp /etc/sysconfig/network-scripts/ifcfg-em2   /etc/sysconfig/network-scripts/ifcfg-em2:1

# cp /etc/sysconfig/network-scripts/ifcfg-em2   /etc/sysconfig/network-scripts/ifcfg-em2:2

# cp /etc/sysconfig/network-scripts/ifcfg-em2   /etc/sysconfig/network-scripts/ifcfg-em2:3

修改里面的DEVICE和ip行,如下:

# more ifcfg-em2:1

DEVICE=em2:1

BOOTPROTO=none

HWADDR=90:b1:1c:37:a9:16

IPV6INIT=no

NM_CONTROLLED=yes

ONBOOT=yes

TYPE=Ethernet

UUID="db3f67fb-b389-4b64-a765-92ada4f0ce0a"

USERCTL=no

IPADDR=1.1.134.117

NETMASK=255.255.255.224

重启网络

# /etc/init.d/network restart

查看公网ip是否在线

# ifconfig

三、安装所需软件包

因用户认证需要htpasswd及ab压力测试需要,故需要安装httpd

# yum install httpd

因squid的snmp功能需要通过net-snmp代理,故需安装

yum install -y net-snmp-utils

四、squid配置文件:

# more /usr/local/squid/etc/squid_multi_instance_conf/squid_multi_instance.conf 

####configured by laijingli

###only listen on private ip 

http_port 192.168.0.6:65500

#http_port 1.1.134.122:65500

###允许使用代理的ip段

acl ip_allow src 1.1.134.0/24 2.2.235.0/24 192.168.0.0/24

###lable for debugging

visible_hostname squid_inst_30

cache_mgr laijingli

##auth

auth_param basic program /usr/local/squid/libexec/basic_ncsa_auth /usr/local/squid/etc/squid_multi_instance_conf/users.txt

auth_param basic children 10

auth_param basic realm  proxy server

auth_param basic credentialsttl 12 hours

auth_param basic casesensitive off

##enable auth,and only allow ip_allow and authed user to use this proxy

acl ncsa_users proxy_auth REQUIRED

http_access allow all

#http_access allow ip_allow ncsa_users

#http_access allow ncsa_users

##route outgoing ip address by authed user name

acl u1 proxy_auth u1

acl u2 proxy_auth u2

acl u3 proxy_auth u3

tcp_outgoing_address 1.1.134.117 u1

tcp_outgoing_address 1.1.134.118 u2

tcp_outgoing_address 1.1.134.119 u3

##route outgoing ip address by connected ip or client's source ip

#acl ip1  myip 1.1.134.123 

acl ip1  src 192.168.0.200

tcp_outgoing_address 1.1.134.107 ip1

#acl ip2  src 192.168.0.15

#tcp_outgoing_address 1.1.134.124 ip2

#acl ip3  src 192.168.0.0/24

#tcp_outgoing_address 1.1.134.125 ip3

###logs

pid_filename /usr/local/squid/var/logs/squid_30.pid

cache_log /usr/local/squid/var/logs/cache_30.log 

access_log /usr/local/squid/var/logs/access_30.log

###snmp monitor by cacti

acl CactiServer src 127.0.0.1 #写本机,因为要用net-snmp做代理

acl SNMP snmp_community community_cacti

snmp_port 3401

snmp_access allow SNMP CactiServer

snmp_access deny ALL

### anonymous 匿名代理

#forwarded_for off #HTTP_X_FORWARDED_FOR: unknown

request_header_access Allow allow all

request_header_access Authorization allow all

request_header_access WWW-Authenticate allow all

request_header_access Proxy-Authorization allow all

request_header_access Proxy-Authenticate allow all

request_header_access Cache-Control allow all

request_header_access Content-Encoding allow all

request_header_access Content-Length allow all

request_header_access Content-Type allow all

request_header_access Date allow all

request_header_access Expires allow all

request_header_access Host allow all

request_header_access If-Modified-Since allow all

request_header_access Last-Modified allow all

request_header_access Location allow all

request_header_access Pragma allow all

request_header_access Accept allow all

request_header_access Accept-Charset allow all

request_header_access Accept-Encoding allow all

request_header_access Accept-Language allow all

request_header_access Content-Language allow all

request_header_access Mime-Version allow all

request_header_access Retry-After allow all

request_header_access Title allow all

request_header_access Connection allow all

request_header_access Proxy-Connection allow all

request_header_access User-Agent allow all

request_header_access Cookie allow all

request_header_access All deny all

五、start、stop命令

squid启动脚本

# more /usr/local/squid/etc/squid_multi_instance_conf/start_squid.sh 

#!/bin/bash

/usr/local/squid/sbin/squid -f /usr/local/squid/etc/squid_multi_instance_conf/squid_multi_instance.conf 

netstat -anp|grep LIST|grep squid

squid关闭脚本

# more /usr/local/squid/etc/squid_multi_instance_conf/stop_squid.sh 

#!/bin/bash

ps aux|grep squid|grep -v grep|awk '{print $2}'|xargs kill -9

六、检查squid运行是否正常

检查squid是否正常启动

# netstat -anp|grep LIST|grep squid

tcp        0      0 192.168.0.6:65500           0.0.0.0:*                   LISTEN      31077/(squid-1)

检查squid是否正常启动

# ps uax|grep squid                

root     31074  0.0  0.0  50184  1796 ?        Ss   15:59   0:00 /usr/local/squid/sbin/squid -f

/usr/local/squid/etc/squid_multi_instance_conf/squid_multi_instance.conf

nobody   31077  0.1  0.1  88824 19820 ?        S    15:59   0:00 (squid-1) -f

/usr/local/squid/etc/squid_multi_instance_conf/squid_multi_instance.conf

root     31091  0.0  0.0 103244   832 pts/1    S+   15:59   0:00 grep squid

检查squid snmp支持是否

snmpwalk -v 1 -c community_cacti 127.0.0.1:3401 .1.3.6.1.4.1.3495.1

配置使用snmp代理

# more /etc/snmp/snmpd.conf 

##snmp proxy

proxy -v 1 -c community_cacti 127.0.0.1:3401 .1.3.6.1.4.1.3495.1

检查使用snmp代理后是否可以获取oid信息

snmpwalk -v 1 -c community_cacti localhost:161 .1.3.6.1.4.1.3495.1

安装cacti监控模板(略)

https://github.com/dezwart/cacti-squid

cacti监控截图

测试代理是否正确工作

curl -U u4:123456  -x 192.168.0.32:65500 --proxy-basic  http://1.1.134.112/myip.php;echo

测试是否使用了匿名代理

http://www.iprivacytools.com/proxy-checker-anonymity-test/

七、代理性能测试

测试页面:

# more /var/www/app1/myip.php 

<?php

$iipp=$_SERVER["REMOTE_ADDR"];

echo $iipp;

?>

ab -c 100 -n 10000  http://1.1.134.112/myip.php      

ab -c 100 -n 10000 -X 192.168.0.6:65500 http://1.1.134.112/myip.php

 
 ab -c 1 -n 10000  耗时(秒) 请求丢失个数 平均每秒请求数(约) 平均每个并发请求耗时(毫秒)
不使用代理 6.5 0 1538 0.65
使用代理 13 0 769 1.3
         
 ab -c 10 -n 10000  耗时(秒) 请求丢失个数 平均每秒请求数(约) 平均每个并发请求耗时(毫秒)
不使用代理 4.8 0 2083 0.048
使用代理 4.2 0 2380 0.042
         
 ab -c 50 -n 10000  耗时(秒) 请求丢失个数 平均每秒请求数(约) 平均每个并发请求耗时(毫秒)
不使用代理 3.6 0 2777 0.0072
使用代理 3.5 0 2857 0.007
         
 ab -c 100 -n 10000  耗时(秒) 请求丢失个数 平均每秒请求数(约) 平均每个并发请求耗时(毫秒)
不使用代理 3.4 0 2941 0.0034
使用代理 3.6 0 2777 0.0036

结论:

使用显示ip地址的简单php页面做了一下测试:ab并发100连续请求10000次,直接测试耗时3.4秒,使用代理测试耗时3.5秒,多次测试都没有出现请求失败的

情况,平均每秒可以处理2800个请求。

基于认证的代理平台搭建配置squid-20130730的更多相关文章

  1. 基于locust的性能测试平台搭建

    前段时间加入性能测试组,并参与搭建基于locust的性能测试平台,我分到的任务相对独立,开发locust的启动接口和停止运行接口,现开发的差不多了,做一个总结 一.locust运行的相关内容 二.lo ...

  2. 基于Docker在Win10平台搭建Ruby on Rails 6.0框架开发环境

    原文转载自「刘悦的技术博客」https://v3u.cn/a_id_170 2020年,"非著名Web框架"–Ruby on Rails已经15岁了.在今年,Rails 6.0趋于 ...

  3. 基于Ubuntu的ESP32平台搭建

    提要:针对于Ubuntu下的ESP32搭建,网上有很多博文,乐鑫官网也有指导手册,对于到家都知道的部分我就一带而过,我主要描述搭建过程中遇到的问题和细节. 1.创建一个ESP的目录 I)在家目录下创建 ...

  4. 基于Livy的Spark提交平台搭建与开发

    为了方便使用Spark的同学提交任务以及加强任务管理等原因,经调研采用Livy比较靠谱,下图大致罗列一下几种提交平台的差别. 本文会以基于mac的单机环境搭建一套Spark+Livy+Hadoop来展 ...

  5. 基于token的多平台身份认证架构设计

    基于token的多平台身份认证架构设计 1   概述 在存在账号体系的信息系统中,对身份的鉴定是非常重要的事情. 随着移动互联网时代到来,客户端的类型越来越多, 逐渐出现了 一个服务器,N个客户端的格 ...

  6. 基于Moodle的IT课程辅助教育平台搭建

    基于Moodle的IT课程辅助教育平台搭建 Moodle是一个开源课程管理系统(CMS),也被称为学习管理系统(LMS)或虚拟学习环境(VLE).它已成为深受世界各地教育工作者喜爱的一种为学生建立网上 ...

  7. 基于MyEclipse+9.0+++Tomcat+7.0的SSH+平台搭建

    基于MyEclipse+9.0+++Tomcat+7.0的SSH+平台搭建 http://wenku.baidu.com/view/96fbfe0f581b6bd97f19ea1d.html 用MyE ...

  8. Linux 笔记 - 第十九章 配置 Squid 正向代理和反向代理服务

    一.简介 Squid 是一个高性能的代理缓存服务器,对应中文的乌贼,鱿鱼的意思.Squid 支持 FTP,gopher 和 HTTP 协议.和一般的代理缓存软件不同,Squid 用一个单独的,非模块化 ...

  9. Spring Cloud Config(三):基于JDBC搭建配置中心

    1.简介 本文主要内容是基于jdbc搭建配置中心,使应用从配置中心读取配置信息并成功注册到注册中心,关于配置信息表结构仅供参考,大家可以根据具体需要进行扩展. 2.Config Server 搭建 2 ...

随机推荐

  1. 网络资源(10) - Eclipse开发项目

    2014_08_26 http://www.360doc.com/content/13/0403/14/11843499_275730704.shtml Eclipse 下搭建struts2开发环境

  2. Mobile开发的饕餮盛宴-Zoomla!波CMS2 x2.1正式宣布

    饕餮 [tāo tiè] 古代汉族神话传说中龙的第五子,是一种存在于传说.想象的神奇怪兽. 古书<山海经>介绍其特点是:其形状如羊身人面,其目在腋下,虎齿人爪.其音如婴儿. 作为中国本土软 ...

  3. winform屏幕截图

    原文:winform屏幕截图 屏幕截图是一个比较常用的功能,在项目中出现的比例也比较高,至少我做过的每个项目都有屏幕截图这个功能,从全屏截图到区域截图都有出现过.当然区域截图已然包含了全屏截图. 全屏 ...

  4. 杭电dp题集,附链接还有解题报告!!!!!

    Robberies 点击打开链接 背包;第一次做的时候把概率当做背包(放大100000倍化为整数):在此范围内最多能抢多少钱  最脑残的是把总的概率以为是抢N家银行的概率之和- 把状态转移方程写成了f ...

  5. DevExpress asp.net 导出Excel 自动开启迅雷问题,默认保存为aspx页面

    目前采取曲线救国策略: 利用MVC ..... <dx:ASPxGridView ID="ASPxGridView1" runat="server" Au ...

  6. AngularJS之使用控制器封装业务逻辑

    AngularJS之使用控制器封装业务逻辑 控制器的作用 我们知道,在AngularJS中,实现数据绑定的核心是scope对象.那么控制器又有什么用呢? 简单地说,没有控制器/controller,我 ...

  7. 客户端程序通过TCP通信传送"小文件"到服务器

    客户端程序通过TCP通信传送"小文件"到服务器 [c#源码分享]客户端程序通过TCP通信传送"小文件"到服务器 源码  (不包含通信框架源码,通信框架源码请另行 ...

  8. asp.net mvc3 数据验证(四)—Remote验证的一个注意事项

    原文:asp.net mvc3 数据验证(四)-Remote验证的一个注意事项         前几篇把asp.net mvc3 中基于Model的主要数据验证的方法都已经讲完了,本节纯粹只是讲一个我 ...

  9. HTML静态分页(形如:首页,上一页,下一页,尾页)

    在HTML中有时候我们会用到静态分页,一次拿回一定量的数据结果条目,我们会以形如:第2页,共12页  首页 上一页 下一页 尾页 的方式进行静态分页,以下是该种静态分页的代码,供兄弟姐妹们参考. &l ...

  10. Appium根据xpath获取控件实例随笔

    如文章<Appium基于安卓的各种FindElement的控件定位方法实践>所述,Appium拥有众多获取控件的方法.其中一种就是根据控件所在页面的XPATH来定位控件. 本文就是尝试通过 ...