基于认证的代理平台搭建配置squid-20130730
基于認證的代理平臺搭建配置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的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Linux内核 sysctl.conf
- 下一篇: 破天荒的有些想法想做医生,长这么大了都没