【原创】windows xp squ…

来源:互联网 发布:js requestanimframe 编辑:程序博客网 时间:2024/06/05 00:45

基于 windowsXP/Linux 搭建高可用代理服务器集群

  • 1 需求:

    • 爬虫需要代理服务, 突破网站限制. 要求IP可变\稳定\节约\
  • 2 方案:

    • 购买N台云服务器 VPS, 需要有固定 IP, 公网可访问.用于代理上游.
    • 购买 N 个电信/移动/联通拨号资源.要求可拨号/可远程(RDP
  • 3 注意事项:

    • 拨号资源 IP 不固定, 拨号后需要能够通过公网访问.
    • 客户端, WindowsXP, 下游代理服务器
    • VPS-Server, 服务端,管理代理服务器VPS和客户端.
    • VPS-Proxy, 代理服务器, 绑定客户端做为代理下游
  • 4 整体流程

    • 准备文件, 包含 squid 绿色安装包/客户端程序(python,打包成 exe)/一些自动化脚本/
    • 首次使用 RDP连接 XP, 使用 FTP 或者使用磁盘共享功能,使得程序能够运行在XP 上.
      • 方案1: 直接使用磁盘共享, 所有文件通过远程磁盘拷贝. 在 XP进去磁盘, 运行即可
      • 方案2: 磁盘共享 FTP 脚本, FTP 服务器共享其余文件. 在XP 进入磁盘, 运行即可.
      • 方案3: 所有文件共享在 FTP 服务器上. 进入 XP, 手动执行CMD, 粘贴 FTP/运行命令.
      • 方案4: 使用磁盘共享或者 FTP, RDP支持初始化执行程序. 不可行, 需要 RDP 后设置可执行成立列表
  • 5 客户端程序流程

    • 启动
    • 将squid绿色安装包(压缩文件) 复制解压到C:\squid\
    • 将客户端程序/相关文件复制到桌面
    • 识别拨号账号/密码. 不能使用轮训, 因为多个 XP同时测试拨号会有造成拨号失败. 手动输入模式. 成功保存在文件中.
    • 和初始化服务器通信, 获取 代理服务器VPS IP,用于绑定代理服务器.
    • 把 代理服务器 IP 写入 squid 配置文件,用于权限管理.
    • 启动 squid 服务.
    • 向 代理服务器 发送心跳包, 获取下一次重新启动时间.
    • 心跳包返回内容可以有下次拨号时间\重启\退出
  • 6 服务器程序流程

    • 服务器程序分为两部分.
      • a, VPS-Server, 代理服务器 VPS向服务器注册\注销操作; 客户端获取代理服务器 VPS 的 IP.
      • b, VPS-Proxy, 代理服务器 VPS.
    • 初始化配置
      • 关闭防火墙, 安装 iptables-services,配置/etc/sysconfig/iptables 并启动 iptables
      • 安装 http-tools(htpasswd, 管理 squid账号授权)
      • 安装 squid 服务
    • 启动 VPS-Server.
    • 启动 VPS-Proxy.
    • VPS-Proxy 访问 VPS-Server,注册/注销代理服务器.
    • VPS-Server 收到客户端申请代理服务器请求时, 返回可用的VPS-Proxy IP.
    • VPS Server 将 N 个 VPS-Proxy 和 M个客户端绑定信息持久化.
    • VPS-Proxy 每隔固定时间清除服务端 Squid.conf下游配置.
    • VPS-Proxy 在重新启动 squid 之前, 根据客户端时间和VPS-Proxy squid重启时间矫正为客户端下次心跳时间, 返回给客户端.
    • VPS-Proxy 到重启 Squid 时间后,把客户端列表作为代理下游 写入 Squid.conf(含 squid 账号管理), 重新启动 Squid 服务.
  • VPS-Proxy 把绑定的客户端列表持久化.

生成 RDP 文件(txt 文本), 重要参数如下

  • fulladdress:s:{WindowsXP-IP}:{WindowsXP-Port}
  • username:s:{WindowsXP-UserName}
  • password 51:b:{Windows Password, forbyte}
  • drivestoredirect:s:{LocalDriver,Ex:E:\};
  • connection type:i:6
  • authentication level:i:0
    这里需要注意, WindowsPassword 是哈希, 用工具可以生成

===
客户端的一些文件

客户端 start.bat

cd "C:\Documents and Settings\Administrator\桌面\"clsif exist "C:\Documents and Settings\Administrator\桌面\socket_client.exe" (    cls    echo file has exists...    xcopy /E /y "\\tsclient\E\adsl\client\dist\socket_client.exe" "C:\Documents and Settings\Administrator\桌面\socket_client.exe"    xcopy /E /y "\\tsclient\E\adsl\client\dist\scripts\run_client.bat" "C:\Documents and Settings\Administrator\桌面\") else (    :: copy 压缩squid包, 可以替换为 ftp 形式    copy \\tsclient\F\adsl\client\soft\squid.zip C:\squid.zip    :: 解压文件到指定目录, 静默解压    "C:\Program Files\WinRAR\winRar.exe" -o+ x -ibck C:\squid.zip C:\    ::  递归/覆盖copy程序文件    xcopy /E /y "\\tsclient\E\adsl\client\dist\*" "C:\Documents and Settings\Administrator\桌面\")"C:\Documents and Settings\Administrator\桌面\socket_client.exe" --clientpause

管理 squid

net stop squid:: 撤销 squid 服务C:\squid\sbin\squid.exe -r:: 注册 squid 服务C:\squid\sbin\squid.exe -i:: 检查 squid 配置C:\squid\sbin\squid.exe -znet start squid:: pause

拨号管理

rasdial /disconnect:: 暂停2ping 0  -n 2 -w 1000 > /nullrasdial 宽带连接 adsl账号 adsl密码

客户端 squid 版本是2.7, 重要配置如下

acl remove_server src 111.11.111.111        # server iphttp_access allow remove_server# 关闭日志文件信息access_log nonecache_log nonecache_store_log none# 关闭源 IP 设置via offcache_vary offforwarded_for off

Py2exe 打包 python 程序

import sysfrom distutils.core import setup import py2exesys.argv.append('py2exe')options = {"py2exe":            {"compressed": 1,             "optimize": 2,            # "ascii": 1,            #"includes":["encodings", "encodings.*"],            #'dll_excludes': ['w9xpopen.dll', "SHELL32.dll"],             "bundle_files": 1            }} setup(    options = options,    console=[{"script": "socket_client.py"},],    #windows=[{"script": "socket_client.py"},],    data_files=[        ("scripts",["scripts\\start_client_squid.bat", "scripts\\connect_adsl.bat",  "scripts\\account.exe", "run_client.bat",]),        ("templates", ["templates\\squid.client.template", "templates\\adsl.client.template"])        ],    name = "socket client",    author="zhipeng",    zipfile=None,)

===
服务端的一些文件

服务器初始化

SQUID_USER="squid_user"SQUID_PASSWD="squid_passwd"service squid stop# install htpasswd agent, squid server, iptables manageryum install -y screen httpd-tools squid iptables-services# change owner squid.conf# chown zhipeng /etc/squid/squid.confsquid -k parsesquid -z# create password filehtpasswd -c -b /etc/squid/passwd $SQUID_USER $SQUID_PASSWD# 获取本地公网 ip. 仅限ali云. 如果不可以, 考虑其他方式.ifconfig eth1 |grep inet|awk '{print $2}' > net_ip# copy iptables to syscp iptables.template /etc/sysconfig/iptablessystemctl stop firewalldsystemctl mask firewalldsystemctl enable iptablesservice iptables restartservice squid start

启动 squid

service squid stop/etc/squid/squid.conf.default > /etc/squid/squid.confsquid -k parse > /dev/nullsquid -z > /dev/nullservice squid startcat /etc/squid/squid.conf |grep -e "^cache_peer" | awk '{print $2}' | xargs echo "reset adsl ip:"

server 管理

loc_ip=`ifconfig eth1 |grep inet|awk '{print $2}'`loc_port=4000daemon=""server=""restart=""setexit=""for i in "$@"do    echo check args: [$i]    if [[ "$i" == "--daemon" || "$i" == "-d" ]]    then        daemon="--daemon"        echo use daemon ..    elif [[ $i == "--server" ]]    then        server="--server"        echo "run server .."    elif [[ $i == "--restart" ]]    then        restart="--restart"        echo "restart server .."    elif [[ "$i" == "--exit" ]]    then        setexit="--exit"        echo "exit server .."    fidoneif [[ $setexit == "--exit" && $restart == "--restart" ]]then    echo exit:  params error, please input --exit or --restartelse    echo python socket_server.py $loc_ip $loc_port $server $daemon $restart $setexitfi

代理服务器 squid 重要配置

# 关闭代理跳转信息request_header_access Via deny allrequest_header_access X-Forwarded-For deny all# 用户授权auth_param basic program /usr/lib64/squid/basic_ncsa_auth /etc/squid/passwdacl auth_user proxy_auth REQUIREDhttp_access allow auth_user# 设置上游代理(本文理解为下游)# set parent{cache_peer}#cache_peer 11.111.11.111 sibling 3128 0 no-query default#cache_peer  parent 3128 0 no-query default login=user:passwordnever_direct allow all

服务器 iptables ,开放某个端口

-A INPUT -p tcp -m state --state NEW -m tcp --dport 3828 -j ACCEPT

参考

RDP “alternate shell” not working
Configurethe server that will host RemoteAppprograms.aspx#BKMK_ConfigureHostServer)- https://technet.microsoft.com/en-us/library/cc730673(v=ws.10).aspx#BKMK_ConfigureHostServer
Can RDP clients launch remote applications and notdesktops
How to enable RemoteApp
Directly access Windows XP applications from Windows 8
RemoteApp for Windows XP and Windows Vista, the missingpieces
RemoteAppon Windows 7, run app
RDPfile setting
RDP file setting
how rdp passwords are encrypted
download rdppassword builder file. rdp.zip
如何在批次檔(Batch)中實現 sleep 命令讓任務暫停執行 n 秒
winrar压缩和解压的cmd命令
How to check if a file exists from inside a batch file

0 0