Shadowsocks安装与环境设置
Shadowsocks安装与环境设置
Shadowsocks是我们常用的代理工具,它使用socks5协议,而终端很多工具目前只支持http和https等协议, 正因为如此,我们在 使用shadowsocks的时候,最为开发人员的我们,需要让我们的终端也支持翻墙功能.
对于shadowsocks的服务,可以自己搭建shadowsocks server 或者 购买网上的服务, 服务正常启动后,我们先配置我们的开发环境.
Mac 端环境配置
我目前使用的是Mac OSX 10.11, 所以需要在Mac下安装 polipo
$ brew install polipo
然后创建配置文件 ~/Library/LaunchAgents/homebrew.mxcl.polipo.plist
如下
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>homebrew.mxcl.polipo</string>
<key>RunAtLoad</key>
<true/>
<key>KeepAlive</key>
<true/>
<key>ProgramArguments</key>
<array>
<string>/usr/local/opt/polipo/bin/polipo</string>
<string>socksParentProxy=localhost:1080</string>
</array>
<!-- Set `ulimit -n 20480`. The default OS X limit is 256, that's
not enough for Polipo (displays 'too many files open' errors).
It seems like you have no reason to lower this limit
(and unlikely will want to raise it). -->
<key>SoftResourceLimits</key>
<dict>
<key>NumberOfFiles</key>
<integer>20480</integer>
</dict>
</dict>
</plist>
文件保存后, 我们需要载入它,以便服务能随着机器重启时自启动
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.polipo.plist
好了, 这时,我们的终端还不能使用ss的, 我们需要再进行一些环境变量的配置
$ export https_proxy=http://localhost:8123
$ export http_proxy=http://localhost:8123
ok, 我们在终端上运行命令
$ curl ip.gs
当前 IP:xx.xx.xx.xx 来自:中国香港 xxx.net
或
curl -i --verbose https://www.facebook.com
如果能正常返回”内容”, 则证明我们终端的协议转换成功,能正常使用了
Linux 端环境配置
由于大部分开发者会在自己的mac上运行虚拟机来部署Linux的操作系统, 所以我们也希望除了Mac终端能翻墙外,我们虚拟机上的Linux 也能翻墙. 不过一般的方法都是更改网络策略,使用网桥的方式.
我觉得这种方式不够好,甚至影响了虚拟机上的一个依赖网络的服务的功能.所以为了网虚拟机上的linux操作系统也支持shadowsock,我们要 进行环境安装.
下面我以我的ubuntu为例
$ apt-get install python-pip
$ pip install shadowsocks
成功安装后, 编辑shadowsocks配置文件
vim /etc/shadowsocks.json
填写代理信息:
{
"server":"xxx.xxx.xxx.net",
"server_port":8388,
"local_address": "127.0.0.1",
"local_port":1080,
"password":"12345678987654321",
"timeout":300,
"method":"rc4-md5",
"fast_open": false
}
设置后,重启shadowsocks
$ sslocal -c /etc/shadowsocks.json -d stop
$ sslocal -c /etc/shadowsocks.json -d start
接下来跟mac一样,安装polipo
$ sudo apt-get install polipo
如下打开配置文件:
$ sudo vim /etc/polipo/config
加入以下内容
proxy:socksParentProxy = "localhost:1080"
socksProxyType = socks5
logFile=/var/log/polipologLevel=4
保存后,重启polipo服务 :)
$ sudo service polipo stop
$ sudo service polipo start
然后跟我们的mac一样设置http proxy的环境配置
$ export https_proxy=http://localhost:8123
$ export http_proxy=http://localhost:8123
好了,这是我们可以使用命令验证服务是否正常
$ curl ip.gs
当前 IP:xx.xx.xx.xx 来自:中国香港 xxx.net
或
curl -i --verbose https://www.facebook.com
最后
如果我们想暂停我们终端的代理服务, 可以重新情况我们的代理环境配置, 如下:
$ export https_proxy=
$ export http_proxy=