本文介绍使用Squid 中的 basic_db_auth + mysql 作为Squid的用户权限认证模块,便于后期扩展与管理维护
由于我们需要构建的是一个代理池,机器的数量可能很多,所以比较方便的做法是使用Azure的自定义镜像功能。一次搭建,多次复制。
Squid安装:
sudo apt-get install squid -y
sudo systemctl status squid
如果看到squid正在运行的状态,则Squid安装成功
Squid 配置文件路径: /etc/squid/squid.conf, 建议修改前先备份一份。基础配置可以参照:http://wiki.ubuntu.org.cn/Squid。
下面为本次我所用到的配置文件,配置文件中的连接字符串配置需要根据自己的需要更改。
auth_param basic program /usr/lib/squid/basic_db_auth --dsn "DBI:mysql:host=host;port=3306;database=database" --user "user" --password "pwd" --plaintext --persist --debug
auth_param basic children 1 startup=1 idle=1
auth_param basic realm gsbw proxy-caching web server
auth_param basic credentialsttl 10 minute
acl dbauth proxy_auth REQUIRED
acl SSL_ports port 443
acl Safe_ports port 80 # http
acl Safe_ports port 21 # ftp
acl Safe_ports port 443 # https
acl Safe_ports port 70 # gopher
acl Safe_ports port 210 # wais
acl Safe_ports port 1025-65535 # unregistered ports
acl Safe_ports port 280 # http-mgmt
acl Safe_ports port 488 # gss-http
acl Safe_ports port 591 # filemaker
acl Safe_ports port 777 # multiling http
acl CONNECT method CONNECT
http_access allow !Safe_ports
http_access deny CONNECT !SSL_ports
http_access allow localhost manager
http_access deny manager
http_access allow localhost
http_access allow dbauth
http_access deny all
http_port 3128
via off
forwarded_for transparent
注意使用Mysql认证的话需要安装perl的DBI包:
cpan
cpan>install DBI
配置好之后需要重启squid服务或者重新加载配置文件:
sudo systemctl restart squid
然后也不要忘记了在Azure安全组里面需要添加对 配置文件中 http_port 端口的入站权限。权限添加好之后就可以尝试下能否通过代理访问成功。
在目标机器上取消设置源 VM
sudo waagent -deprovision+user -force
exit
然后使用azure cli操作,以下环境为azure cli 1.0:
azure config mode arm
azure login -e AzureChinaCloud -u username
azure vm deallocate -g myResourceGroup -n myVM
azure vm generalize -g myResourceGroup -n myVM
azure vm capture -g myResourceGroup -n myVM -p myVHDNamePrefix -t myTemplate.json
至此 我们的原始镜像已经创建成功。
azure group create myResourceGroup1 -l "chinaeast"
azure network vnet create myResourceGroup1 myVnet -l "chinaeast"
azure network vnet subnet create myResourceGroup1 myVnet mySubnet
azure network public-ip create myResourceGroup1 myPublicIP -l "chinaeast"
azure network nic create myResourceGroup1 myNIC -k mySubnet -m myVnet -p myPublicIP -l "chinaeast"
azure network nic show myResourceGroup1 myNIC
azure group deployment create myResourceGroup1 MyDeployment -f MyTemplate.json
我们还可以使用资源模板来创建更多的虚拟机。这部分可以参照官方文档。