-
-
Save amcclosky/3427419 to your computer and use it in GitHub Desktop.
Anonymous Rotating Proxies with Monit, Tor, Haproxy and Delegated. Idea by http://blog.databigbang.com/running-your-own-anonymous-rotating-proxies/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
0 - Read http://blog.databigbang.com/running-your-own-anonymous-rotating-proxies/ | |
1 - Install monit, haproxy, tor and delegated. | |
2 - Setup your environment in the setup.rb file | |
3 - Just run > ruby setup.rb | |
4 - ........... | |
5 - PROFIT! > http://www.southparkstudios.com/clips/151040/the-underpants-business |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
global | |
daemon | |
maxconn 256 | |
defaults | |
mode http | |
timeout connect 5000ms | |
timeout client 50000ms | |
timeout server 50000ms | |
frontend rotatingproxies | |
bind *:<%= haproxy_port %> | |
default_backend tors | |
option http_proxy | |
backend tors | |
option http_proxy | |
<% tors_count.times.each do |c| %> | |
server tor<%= c %> localhost:<%= delegated_base_port + c %> | |
<% end %> | |
balance roundrobin |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# monitrc template file | |
set daemon 60 | |
set pidfile <%= install_path %>/pids/monit.pid | |
# gmail or google apps account | |
<% if gmail_username && gmail_password %> | |
set mailserver smtp.gmail.com port 587 | |
username "<%= gmail_username %>" password "<%= gmail_password %>" | |
using tlsv1 with timeout 60 seconds | |
<% end %> | |
set mail-format { from: <%= email %> } | |
set alert <%= email %> with reminder on 10 cycles | |
# Monit web panel | |
set httpd port 44102 | |
allow admin:"password" | |
# tor | |
<% tors_count.times.each do |c| %> | |
check process tor<%= c %> with pidfile <%= install_path %>/pids/tor<%= c %>.pid | |
group proxy | |
start program = "/bin/sh -c '<%= tor_path %> --RunAsDaemon 1 --CookieAuthentication 0 --PidFile <%= install_path %>/pids/tor<%= c %>.pid --SocksPort <%= tor_base_port + c %> --DataDirectory <%= install_path %>/caches/tor<%= c %>'" as uid <%= user %> and gid <%= user %> | |
stop program = "/bin/sh -c '/bin/kill -s SIGTERM `cat <%= install_path %>/pids/tor<%= c %>.pid` && rm \"<%= install_path %>/pids/tor<%= c %>.pid\"'" as uid <%= user %> and gid <%= user %> | |
if mem > 32 MB for 3 cycles then restart | |
if cpu > 30% for 5 cycles then restart | |
<% end %> | |
# delegated | |
<% tors_count.times.each do |c| %> | |
check process delegated<%= c %> with pidfile <%= install_path %>/pids/delegated<%= c %>.pid | |
group proxy | |
start program = "/bin/sh -c '<%= delegated_path %> -P<%= delegated_base_port + c %> SERVER=http SOCKS=localhost:<%= tor_base_port + c %> PIDFILE=<%= install_path %>/pids/delegated<%= c %>.pid LOGFILE=<%= install_path %>/log/delegated.log ADMIN=<%= email %>'" as uid <%= user %> and gid <%= user %> | |
stop program = "/bin/sh -c '/bin/kill -s SIGTERM `cat <%= install_path %>/pids/delegated<%= c %>.pid` && rm \"<%= install_path %>/pids/delegated<%= c %>.pid\"'" as uid <%= user %> and gid <%= user %> | |
if mem > 8 MB for 3 cycles then restart | |
if cpu > 30% for 5 cycles then restart | |
depends on tor<%= c %> | |
<% end %> | |
# haproxy | |
check process haproxy with pidfile <%= install_path %>/pids/haproxy.pid | |
group proxy | |
start program = "/bin/sh -c '<%= haproxy_path %> -f <%= install_path %>/etc/haproxy.cfg -p <%= install_path %>/pids/haproxy.pid'" as uid <%= user %> and gid <%= user %> | |
stop program = "/bin/sh -c '/bin/kill `cat <%= install_path %>/pids/haproxy.pid` && rm \"<%= install_path %>/pids/haproxy.pid\"'" as uid <%= user %> and gid <%= user %> | |
if mem > 8 MB for 3 cycles then restart | |
if cpu > 40% for 5 cycles then restart | |
depends on <%= tors_count.times.map{ |c| "delegated#{c}" }.join(', ') %> | |
# monitrc to restart monit itself | |
check file monitrc path <%= install_path %>/etc/monitrc | |
if changed md5 checksum | |
then exec "<%= monit_path %> reload" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'erb' | |
# Setup variables | |
monit_path = "/usr/bin/monit" | |
tor_path = "/usr/bin/tor" | |
delegated_path = "/usr/local/bin/delegated" | |
haproxy_path = "/usr/local/bin/haproxy" | |
install_path = "/Users/mauroasprea/rotating-tors" | |
user = "username" | |
email = "[email protected]" # where moint and delegated will send mails. | |
tors_count = 4 | |
haproxy_port = 3128 | |
delegated_base_port = 3129 | |
tor_base_port = 9050 | |
tor_control_base_port = 8118 | |
# Optional: setup gmail smtp for monit outgoing alerts | |
gmail_username = "[email protected]" | |
gmail_password = "password" | |
# Prepare paths | |
`mkdir -p #{install_path}/etc` | |
`mkdir -p #{install_path}/caches` | |
`mkdir -p #{install_path}/pids` | |
# haproxy.cfg | |
c = ERB.new(File.read("haproxy.cfg.erb")) | |
File.write("#{install_path}/etc/haproxy.cfg", c.result(binding)) | |
`chmod 600 #{install_path}/etc/haproxy.cfg` | |
# monitrc | |
c = ERB.new(File.read('monitrc.erb')) | |
File.write("#{install_path}/etc/monitrc", c.result(binding)) | |
`chmod 600 #{install_path}/etc/monitrc` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment