开发需要对接google,facebook接口调试代码需要一个代理,找一网centos7.3 服务器来安装代理:
[[email protected] ~]yum install python-pip
[[email protected] ~]$pip install shadowsocks
在后台启动 ss 客户端命令:
nohup sslocal -s your_server_ip -p your_server_port -l 1080 -k your_server_passwd -t 600 -m rc4-md5 > /dev/null 2>&1 &
注意:
使用的是 sslocal 这个命令,表示 shadowsocks 以客户端模式工作
将上述命令里的 your_server_ip, your_server_port, your_server_passwd 换成自己的, 这三个分别代表服务器ip, 服务器上 shadowsocks 的端口以及密码.后面的 rc4-md5 加密方式也要换成跟 server 端一致。
前面的nohub 和最后的 & 表示后台执行且关闭 session 后仍然在后台执行,否则将会阻塞shell端口.
为了更方便, 建议新建一个.json的文件, 将上述信息放里面,如新建/etc/shadowsocks.json文件, 内容为:
{
"server":"your_server_ip", #ss服务器IP
"server_port":your_server_port, #端口
"local_address": "127.0.0.1", #本地ip
"local_port":1080, #本地端口
"password":"your_server_passwd",#连接ss密码
"timeout":300, #等待超时
"method":"rc4-md5", #加密方式 可能不一样需要修改
"fast_open": false, # true 或 false。如果你的服务器 Linux 内核在3.7+,可以开启 fast_open 以降低延迟。开启方法: echo 3 > /proc/sys/net/ipv4/tcp_fastopen 开启之后,将 fast_open 的配置设置为 true 即可
"workers": 1 # 工作线程数
}
然后运行一下命令启动shadowsocks
nohup sslocal -c /etc/shadowsocks.json /dev/null 2>&1 &
如果想增加开启自动启动,执行:echo “ nohup sslocal -c /etc/shadowsocks.json /dev/null 2>&1 &” /etc/rc.local
执行ps aux |grep sslocal |grep -v “grep”查看后台sslocal是否运行
安装Privoxy
上述安好了shadowsocks,但它是 socks5 代理,我门在 shell 里执行的命令,发起的网络请求现在还不支持 socks5 代理,只支持 http/https 代理。为了我门需要安装 privoxy 代理,它能把电脑上所有http请求转发给 shadowsocks
[[email protected] ~] yum install privoxy -y
查看 vim /usr/local/etc/privoxy/config 或者/etc/privoxy/config文件,
先搜索关键字 listen-address 找到 listen-address 127.0.0.1:8118 这一句,保证这一句没有注释,8118就是将来http代理要输入的端口。
然后搜索 forward-socks5t, 将forward-socks5t / 127.0.0.1:9050 改为#forward-socks5t / 127.0.0.1:1080 . 此句前面的注释去掉, 意思是转发流量到本地的1080端口, 而1080端口正是 ss 监听的端口
启动privoxy
systemctl restart privoxy
systemctl enable privoxy
或者:
privoxy /etc/privoxy/config
配置/etc/profile
vim /etc/profile
export http_proxy=http://127.0.0.1:8118
export https_proxy=http://127.0.0.1:8118
source /etc/profile
当前session执行:
export http_proxy=http://127.0.0.1:8118
export https_proxy=http://127.0.0.1:8118
执行vim /etc/profile,添加如下二句:
export http_proxy=http://127.0.0.1:8118 export https_proxy=http://127.0.0.1:8118
修改后使配置生效source /etc/profile
lsof –i:1080
[[email protected] /etc/privoxy]$lsof -i:1080
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
sslocal 9551 root 3u IPv4 6099160 0t0 TCP localhost:socks (LISTEN)
sslocal 9551 root 4u IPv4 6099161 0t0 UDP localhost:socks
shadsockets正常监听;
[[email protected] /etc/privoxy]$lsof -i:8118
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
privoxy 9196 privoxy 4u IPv4 6072039 0t0 TCP localhost:privoxy (LISTEN)
privoxy正常监听;
[[email protected] /etc/privoxy]$echo $http_proxy
http://127.0.0.1:8118
[[email protected] /etc/privoxy]$echo $https_proxy
http://127.0.0.1:8118
测试:
wget www.google.com
--2018-11-14 11:43:30-- http://www.google.com/
Connecting to 127.0.0.1:8118... connected.
Proxy request sent, awaiting response... 200 OK
Length: unspecified [text/html]
Saving to: ‘index.html.1’
[ <=> ] 12,084 --.-K/s in 0s
2018-11-14 11:43:30 (51.7 MB/s) - ‘index.html.1’ saved [12084]
执行wget www.google.com判断是否成功
如果不能访问,请重启机器,依次打开shadowsocks和privoxy再测试
Ps:如果不需要用代理了,记得把bash里的配置注释上,免得把流量跑完了
测试:
Curl https://www.google.com
curl www.google.com
<!doctype html><html itemscope="" itemtype="http://schema.org/WebPage"><head><meta content="Search the world's information, including webpages, images, videos and more. Google has many special features to help you find exactly what you're looking for." name="description"><meta content="noodp" name="robots"><meta content="text/html; charset=UTF-8" http-equiv="Content-Type"><meta content="/images/branding/googleg/1x/googleg_standard_color_128dp.png" itemprop="image"><title>Google</title><script nonce="PwL0WCIukKULM1vnDzi81w==">(function(){window.google={kEI:'rpnrW5uHCIar8APVhIvwCg',kEXPI:'0,1353746,58,1957,583,434,281,344,494,287,697,528,731,31,111,183,293,879,301,30,524,27,275,401,101,140,107,389,2336367,190,32,68,329226,1294,12383,4855,32691,15248,867,317,10444,1402,6381,3335,2,2,4605,2196,369,1212,2102,5505,
……
Note:
503 - Forwarding failure (Privoxy@localhost)报错时候,应该转发失败,应该是json中配置的ip
"local_address": "127.0.0.1", #127.0.0.1可能写成机器内网ip了改为127.0.0.1即可;
不能访问,重启下机器,依次打开shadowsocks和privoxy再测试
nohup sslocal -c /etc/shadowsocks.json /dev/null 2>&1 &
privoxy --user privoxy /usr/local/etc/privoxy/config
转自:https://bodyno.com/tool/2017/09/03/centos-ss.html