Proxypool代理池搭建
字数 1089 2025-08-11 08:36:22

ProxyPool代理池搭建教程

1. 项目概述

ProxyPool是一个基于Python爬虫的代理池项目,能够定时获取免费可用代理并存入Redis数据库。项目地址:https://github.com/jhao104/proxy_pool

2. 环境准备

2.1 Redis安装与配置

ProxyPool依赖Redis数据库存储代理信息,Redis安装有两种方式:

方法一:指令安装(推荐)

apt-get install redis-server

方法二:手动安装

  1. 从官网下载最新Redis安装包
  2. 执行以下命令:
tar -zxvf redis-6.2.6.tar.gz
cd redis-6.2.6/
make
make install
cd /usr/local/bin
mkdir config
cp /opt/redis-6.2.6/redis.conf config

Redis配置修改

修改redis配置文件(自动安装路径为/etc/redis/redis.conf,手动安装路径为/opt/redis-6.2.6/redis.conf):

daemonize yes          # 开启守护进程
protected-mode no      # 关闭保护模式
# bind 127.0.0.1 ::1   # 注释掉此条以允许远程访问
port 6379             # Redis开放端口

Redis启动与停止

启动Redis:

redis-server config/redis.conf
redis-cli

停止Redis:

shutdown
exit

3. ProxyPool部署

3.1 Docker部署(推荐)

docker pull jhao104/proxy_pool
docker run --env DB_CONN=redis://:[password]@[ip]:[port]/[db] -p 5010:5010 jhao104/proxy_pool:latest

参数说明:

  • password: Redis密码(没有可为空)
  • ip: Redis服务器IP
  • port: Redis端口
  • db: Redis数据库(默认0)

3.2 手动部署

  1. 克隆项目:
git clone https://github.com/jhao104/proxy_pool.git
  1. 安装依赖:
pip install -r requirements.txt
  1. 修改配置文件setting.py中的Redis连接信息
  2. 运行:
python3 proxyPool.py schedule  # 启动调度程序
python3 proxyPool.py server    # 启动API服务

4. 代理使用

4.1 生成Proxifier配置文件

  1. 安装Redis Python包:
pip install redis
  1. 使用以下Python脚本生成Proxifier配置文件(注意修改第8行的Redis IP和端口):
# -*- coding:utf8 -*-
import redis
import json
from xml.etree import ElementTree

def RedisProxyGet():
    ConnectString = []
    pool = redis.ConnectionPool(host='[ip]', port=[port], db=0, decode_responses=True)
    use_proxy = redis.Redis(connection_pool=pool)
    key = use_proxy.hkeys('use_proxy')
    for temp in key:
        try:
            ConnectString.append(json.loads(use_proxy.hget('use_proxy',temp)))
        except json.JSONDecodeError:
            pass
    return ConnectString

def xmlOutputs(data):
    i = 101
    ProxyIDList = []
    ProxifierProfile = ElementTree.Element("ProxifierProfile")
    ProxifierProfile.set("version", str(i))
    ProxifierProfile.set("platform", "Windows")
    ProxifierProfile.set("product_id", "0")
    ProxifierProfile.set("product_minver", "310")
    
    # 配置文件详细结构(省略部分代码)
    # ...
    
    tree = ElementTree.ElementTree(ProxifierProfile)
    tree.write("ProxifierConf.ppx", encoding="UTF-8", xml_declaration=True)

if __name__ == '__main__':
    proxy_data = RedisProxyGet()
    xmlOutputs(proxy_data)
    print("ProxifierConf.ppx配置文件创建完成....")
  1. 运行脚本后会生成ProxifierConf.ppx文件,可导入Proxifier使用

注意:建议使用Proxifier 3.3.1版本,高版本可能会报错

5. 常见问题

  1. Redis连接问题

    • 确保Redis服务已启动
    • 检查防火墙是否开放6379端口
    • 确认配置文件中的protected-mode已设置为no
  2. 代理不可用

    • ProxyPool会定期验证代理可用性,不可用代理会自动移除
    • 可手动调用API接口获取新代理
  3. Proxifier导入失败

    • 确保使用兼容版本(建议3.3.1)
    • 检查生成的ppx文件格式是否正确

6. API接口

ProxyPool提供以下API接口(默认端口5010):

  • GET /get:获取一个代理
  • GET /pop:获取并删除一个代理
  • GET /all:获取所有代理
  • GET /count:获取代理数量

7. 进阶配置

可在项目配置文件setting.py中调整以下参数:

  • 代理验证周期
  • 代理获取频率
  • 代理验证超时时间
  • 代理分数设置

通过合理配置这些参数可以优化代理池的性能和稳定性。

ProxyPool代理池搭建教程 1. 项目概述 ProxyPool是一个基于Python爬虫的代理池项目,能够定时获取免费可用代理并存入Redis数据库。项目地址: https://github.com/jhao104/proxy_ pool 2. 环境准备 2.1 Redis安装与配置 ProxyPool依赖Redis数据库存储代理信息,Redis安装有两种方式: 方法一:指令安装(推荐) 方法二:手动安装 从官网下载最新Redis安装包 执行以下命令: Redis配置修改 修改redis配置文件(自动安装路径为 /etc/redis/redis.conf ,手动安装路径为 /opt/redis-6.2.6/redis.conf ): Redis启动与停止 启动Redis: 停止Redis: 3. ProxyPool部署 3.1 Docker部署(推荐) 参数说明: password : Redis密码(没有可为空) ip : Redis服务器IP port : Redis端口 db : Redis数据库(默认0) 3.2 手动部署 克隆项目: 安装依赖: 修改配置文件 setting.py 中的Redis连接信息 运行: 4. 代理使用 4.1 生成Proxifier配置文件 安装Redis Python包: 使用以下Python脚本生成Proxifier配置文件(注意修改第8行的Redis IP和端口): 运行脚本后会生成 ProxifierConf.ppx 文件,可导入Proxifier使用 注意 :建议使用Proxifier 3.3.1版本,高版本可能会报错 5. 常见问题 Redis连接问题 : 确保Redis服务已启动 检查防火墙是否开放6379端口 确认配置文件中的 protected-mode 已设置为 no 代理不可用 : ProxyPool会定期验证代理可用性,不可用代理会自动移除 可手动调用API接口获取新代理 Proxifier导入失败 : 确保使用兼容版本(建议3.3.1) 检查生成的ppx文件格式是否正确 6. API接口 ProxyPool提供以下API接口(默认端口5010): GET /get :获取一个代理 GET /pop :获取并删除一个代理 GET /all :获取所有代理 GET /count :获取代理数量 7. 进阶配置 可在项目配置文件 setting.py 中调整以下参数: 代理验证周期 代理获取频率 代理验证超时时间 代理分数设置 通过合理配置这些参数可以优化代理池的性能和稳定性。