本文讲述一个开源的IP代理服务golang-proxy的搭建步骤。IP代理服务有商业的,若不想花钱,只能寻找开源的服务自己来搭建。但是很多开源的IP代理服务几乎无法使用,本文介绍的这个开源项目有在实际项目中实践过,感觉不错。
# 1. 目录结构
如下是已经部署好的程序目录结构,ipProxy是程序根目录:
IDC:: root@uy01-05-v03:~# tree ./ipProxy/
./ipProxy/
├── config.yml
├── golang-proxy_linux_amd64
├── source
│ ├── nimadaili.com.https.yml
│ ├── nimadaili.com.http.yml
│ ├── xiladaili.com.https.yml
│ └── xiladaili.com.http.yml
└── start.sh
1 directory, 7 files
IDC:: root@uy01-05-v03:~#
config.yml
IDC:: root@uy01-05-v03:~# cat ./ipProxy/config.yml
MYSQL:
HOST: "192.168.10.48"
PORT: "3306"
USER: "recipe"
PASS: "recipe1234"
DB: "ip_proxy"
CHARSET: "utf8mb4"
需要事先创建好数据库,然后配置到该配置文件中。
官网文档对config.yml的说明 (opens new window)
IDC:: root@uy01-05-v03:~# cat ./ipProxy/source/nimadaili.com.https.yml
# "."命名开头的文件将不会被载入
page:
entry: "http://www.nimadaili.com/https/?page=1"
template: "http://www.nimadaili.com/https/?page={page}"
from: 1
to: 2000
selector:
iterator: ".fl-table tr"
ip: "td:nth-child(1)"
port: ""
category:
parallelnumber: 3
delayRange: [10, 30]
interval: "@every 10m"
debug: true
IDC:: root@uy01-05-v03:~# cat ./ipProxy/source/nimadaili.com.http.yml
# "."命名开头的文件将不会被载入
page:
entry: "http://www.nimadaili.com/http/?page=1"
template: "http://www.nimadaili.com/http/?page={page}"
from: 1
to: 2000
selector:
iterator: ".fl-table tr"
ip: "td:nth-child(1)"
port: ""
category:
parallelnumber: 3
delayRange: [10, 30]
interval: "@every 10m"
debug: true
IDC:: root@uy01-05-v03:~# cat ./ipProxy/source/xiladaili.com.https.yml
# "."命名开头的文件将不会被载入
page:
entry: "http://www.xiladaili.com/https/1/"
template: "http://www.xiladaili.com/https/{page}/"
from: 0
to: 2000
selector:
iterator: ".fl-table tr"
ip: "td:nth-child(1)"
port: ""
category:
parallelnumber: 3
delayRange: [10, 30]
interval: "@every 10m"
debug: true
IDC:: root@uy01-05-v03:~# cat ./ipProxy/source/xiladaili.com.http.yml
# "."命名开头的文件将不会被载入
page:
entry: "http://www.xiladaili.com/http/1/"
template: "http://www.xiladaili.com/http/{page}/"
from: 0
to: 2000
selector:
iterator: ".fl-table tr"
ip: "td:nth-child(1)"
port: ""
category:
parallelnumber: 3
delayRange: [10, 30]
interval: "@every 10m"
debug: true
IDC:: root@uy01-05-v03:~#
- start.sh是程序启动脚本
因为程序启动需要启动多个服务,为了启动方便,将启动命令统一使用一个shell脚本来管理。
IDC:: root@uy01-05-v03:~# cat ./ipProxy/start.sh
nohup /root/ipProxy/golang-proxy_linux_amd64 -mode=producer >/dev/null 2>&1 &
nohup /root/ipProxy/golang-proxy_linux_amd64 -mode=consumer >/dev/null 2>&1 &
nohup /root/ipProxy/golang-proxy_linux_amd64 -mode=assessor >/dev/null 2>&1 &
nohup /root/ipProxy/golang-proxy_linux_amd64 -mode=service >/dev/null 2>&1 &
IDC:: root@uy01-05-v03:~#
# 2. 参考资料
官方英文文档 (opens new window) 官方中文文档 (opens new window) 再推荐一个开源IP代理服务henson/proxypool (opens new window),该项目的start数要比golang-proxy多,而且更新频繁,但是当时在部署时遇到些问题,所以就搁置了,以后有时间了再继续研究下。