Cafemmo Club
← Quay lại danh sách

Tạo gateway proxy sử dụng nhiều random proxies với Tor

command22/09/2021380 lượt xem27 bình luận
Chào ae, Nhu cầu về random proxies thì khá nhiều (cần crawl dữ liệu mà), nhưng đôi khi bạn ko dùng dịch vụ random proxies vì giá đắt. Chắc đa số ae biết Tor rồi nhé, nhưng ko phải ai cũng biết trên cùng 1 VPS chúng ta có thể tạo nhiều Tor instances để từ đó có nhiều proxies hơn. Mình xin chia sẻ 1 cách dùng nhiều proxies với Tor trên 1 VPS 1GB RAM, cụ thể giải pháp này sẽ tạo cho bạn 1 gateway proxy, khi truy cập gateway này thì nó sẽ tự động chọn 1 trong những random proxies (trong ví dụ này là 20 random proxies) và nó sẽ tự động thay đổi IP trong các Tor IP network với lần truy cập tiếp theo nhé, lợi ích như rotator proxies vậy đó. Mình test nhiều lần thì với 1 GB RAM, bạn nên tạo tầm 15 random proxies, còn 2GB RAM thì tạo 20-30 proxies thôi. Hình minh họa 20 random proxies được tạo với Tor Mình test nhiều dịch vụ random proxies như Stormproxies thì việc sử dụng giải pháp Tor này trên Hetzner VPS CX11 (1 CPU core, 2GB RAM) thì tốc độ ko kém hơn mua Stormproxies đâu nhé và giá của 1 VPS thì rẽ hơn phí dịch vụ của Stormproxies rồi. Hướng dẫn cài VPS với multitor trên CentOS 8. Cập nhật lại các gói trên CentOS [QUOTE] # Turn on EPEL repo on CentOS 8 sudo yum -y install epel-release sudo yum repolist sudo yum update -y # Install htop nano # sudo yum search htop sudo yum install htop nano -y [/QUOTE] Cài đặt docker

#
# Docker
#
yum install -y yum-utils
dnf config-manager --add-repo=https://download.docker.com/linux/centos/docker-ce.repo
dnf install docker-ce docker-ce-cli containerd.io -y

systemctl start docker
systemctl enable docker
Bước chính: cài đặt multitor trên docker. Sourcode Github chính ở đây: github.com/evait-security/docker-multitor

dnf install git -y
git clone https://github.com/evait-security/docker-multitor
Nhưng bạn cài Dockerfile của github trên thì ko chạy đâu vì bản privoxy mới nhất ko hợp với code multitor :) , bạn lấy file Dockerfile sau nha:
nano Dockerfile

FROM alpine:3.11.11

ENV BUILD_PACKAGES="build-base openssl" \\
  PACKAGES="tor sudo bash git haproxy privoxy npm procps nano git"

# install requirements
RUN \\
  apk update && apk add --no-cache $BUILD_PACKAGES $PACKAGES && \\
  npm install -g http-proxy-to-socks

# fix certificate problem (avoid con reset by peer)
RUN \\
  apk add ca-certificates wget && \\
  update-ca-certificates

# install polipo
RUN \\
   wget https://github.com/jech/polipo/archive/master.zip -O polipo.zip && \\
   unzip polipo.zip && \\
  cd polipo-master && \\
  make && \\
  install polipo /usr/local/bin/ && \\
  cd .. && \\
  rm -rf polipo.zip polipo-master && \\
  mkdir -p /usr/share/polipo/www /var/cache/polipo

# clean build packages
RUN \\
  apk del $BUILD_PACKAGES

# install multitor
RUN git clone https://github.com/trimstray/multitor && \\
  cd multitor && \\
  ./setup.sh install && \\
# create log folders
  mkdir -p /var/log/multitor/privoxy/ && \\
  mkdir -p /var/log/polipo/ && \\
# let haproxy listen from outside, instand only in the docker container
  sed -i s/127.0.0.1:16379/0.0.0.0:16379/g templates/haproxy-template.cfg && \\
  sed -i s/127.0.0.1:16380/0.0.0.0:16380/g templates/haproxy-template.cfg && \\
  sed -i s/"maxconn  500"/"maxconn  2000"/g templates/haproxy-template.cfg && \\
  sed -i s/"# stats  auth ha_admin:__PASSWORD__"/"stats  auth admin:vuivenha@"/g templates/haproxy-template.cfg


COPY startup.sh /multitor/
RUN chmod +x /multitor/startup.sh

WORKDIR /multitor/
EXPOSE   16379

#CMD multitor --init 5 --user root --socks-port 9000 --control-port 9900 --proxy privoxy --haproxy --verbose --debug > /tmp/multitor.log; tail -f /tmp/multitor.log
CMD ["./startup.sh"]
Build container này
docker build -t my-multitor .
Start 20 tor instances (nếu VPS bạn nhiều RAM thì tăng số TOR instances này lên, với nhiều lần thử nghiệm thì với 2GB RAM, bạn tạo được tối đa 30 instances)
docker run -e "TOR_INSTANCES=20" --publish 19210:16379 --publish 19209:16380 --restart unless-stopped --detach --name my-multitor my-multitor
Vậy là có 1 gateway cho 20 random proxies rồi nhé. Bạn thử nhiều lệnh sau thì gateway này sẽ lần lượt sử dụng danh sách random proxies và tự đổi IP sau đó, nên giống như rotator proxies luôn. Gõ nhiều lệnh sau để thử xem hoạt động của rotator gateway này.
curl --proxy http://localhost:19210 http://ipinfo.io/ip
Để sử dụng thực tế thì ở lệnh trên, thay đổi localhost bằng IP của VPS. Kiểm tra tình trạng HAProxy quản lý 20 random proxies nhé (user: pass là admin:vuivenha@ -- cấu hình trong file Dockerfile ở bước trên á): http://<ip của VPS>:19209/stats Hết. P/S: Mình để post này ở box này vì ko muốn nhiều người dùng Tor IP để spam :)

Bình luận

Đang tải...

Đang kiểm tra đăng nhập...