Ubuntu20配置Shadowsocks全局代理
服务器 VPN 搭建参考:https://github.com/sucong426/ssr-bbr-vpn
想让本地开发环境,拉取 GitHub 和安装某些软件时下载速度更快,于是整理了一个配置步骤。
# 查看系统版本
❯ cat /etc/lsb-release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=20.04
DISTRIB_CODENAME=focal
DISTRIB_DESCRIPTION="Ubuntu 20.04.5 LTS"
1
2
3
4
5
2
3
4
5
# 安装shadowsocks
# 安装python
由于 shadowsocks 是基于 python 开发的,所以必须安装 python:
sudo apt-get install python3
1
接着安装python的包管理器pip:
sudo apt-get install python3-pip
1
安装完毕之后,通过pip直接安装shadowsocks:
sudo pip install shadowsocks
1
# 配置shadowsocks
新建一个配置文件 shawdowsocks.json
,然后配置相应的参数:
❯ cat shawdowsocks.json
{
"server" : "95.169.25.12",
"server_port" : 18610,
"localPort" : 1080,
"password" : "1qaz@WSX3edc",
"timeout" : 600,
"method" : "aes-256-cfb"
}
1
2
3
4
5
6
7
8
9
2
3
4
5
6
7
8
9
上面的参数需要你的 shawdowsocks 服务提供商为你提供,当然你也可以自己搭建一个。
配置完成后就可以启动shawdowsocks服务:
sudo sslocal -c shawdowsocks.json -d start
1
# 错误问题解决
启动时可能会出现错误:
❯ sudo sslocal -c shawdowsocks.json -d start
INFO: loading config from shawdowsocks.json
2024-04-27 10:15:49 INFO loading libcrypto from libcrypto.so.1.1
Traceback (most recent call last):
File "/usr/local/bin/sslocal", line 8, in <module>
sys.exit(main())
File "/usr/local/lib/python3.8/dist-packages/shadowsocks/local.py", line 39, in main
config = shell.get_config(True)
File "/usr/local/lib/python3.8/dist-packages/shadowsocks/shell.py", line 262, in get_config
check_config(config, is_local)
File "/usr/local/lib/python3.8/dist-packages/shadowsocks/shell.py", line 124, in check_config
encrypt.try_cipher(config['password'], config['method'])
File "/usr/local/lib/python3.8/dist-packages/shadowsocks/encrypt.py", line 44, in try_cipher
Encryptor(key, method)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
解决方案:
这是因为在openssl 1.1.0中废弃了 EVP_CIPHER_CTX_cleanup() 函数而引入了 EVE_CIPHER_CTX_reset() 函数,具体可以查看官方文档 (opens new window), 修复如下
# 在错误日志中找到 openssl.py 文件路径, 通过 vim 修改
❯ sudo vim /usr/local/lib/python3.8/dist-packages/shadowsocks/crypto/openssl.py
# 替换关键字
:%s/cleanup/reset/g
# 保存退出
:wq
1
2
3
4
5
6
2
3
4
5
6
再运行 sslocal,成功。
❯ sudo vim /usr/local/lib/python3.8/dist-packages/shadowsocks/crypto/openssl.py
❯ sudo sslocal -c shawdowsocks.json -d start
INFO: loading config from shawdowsocks.json
2024-04-27 10:18:01 INFO loading libcrypto from libcrypto.so.1.1
started
1
2
3
4
5
6
7
2
3
4
5
6
7
# 配置全局代理
# 安装polipo
启动 shawdowsocks 服务后,发现并不能翻墙上网,这是因为 shawdowsocks 是 socks 5代理,需要客户端配合才能翻墙。
为了让整个系统都走 shawdowsocks 通道,需要配置全局代理,可以通过 polipo 实现。
首先是安装polipo:
sudo apt-get install polipo
1
接着修改 polipo 的配置文件 /etc/polipo/config:
logSyslog = true
logFile = /var/log/polipo/polipo.log
proxyAddress = "0.0.0.0"
socksParentProxy = "127.0.0.1:1080"
socksProxyType = socks5
chunkHighMark = 50331648
objectHighMark = 16384
serverMaxSlots = 64
serverSlots = 16
serverSlots1 = 32
1
2
3
4
5
6
7
8
9
10
11
12
13
14
2
3
4
5
6
7
8
9
10
11
12
13
14
重启 polipo 服务:
sudo /etc/init.d/polipo restart
1
为终端配置 http 代理:
export http_proxy="http://127.0.0.1:1080/"
1
接着测试下能否翻墙:
wget http://www.google.com 如果收到index.html则终端代理成功!
1
# 错误问题解决
提示找不到 polipo 软件包:
❯ sudo apt-get install polipo
Reading package lists... Done
Building dependency tree
Reading state information... Done
E: Unable to locate package polipo
1
2
3
4
5
6
2
3
4
5
6
解决方案:
下载 deb 软件包进行安装:
wget http://archive.ubuntu.com/ubuntu/pool/universe/p/polipo/polipo_1.1.1-8_amd64.deb
sudo dpkg -i polipo_1.1.1-8_amd64.deb
1
2
2
# 注意事项
服务器重启后,下面两句需要重新执行:
sudo sslocal -c shawdowsocks.json -d start
export http_proxy="http://127.0.0.1:1080/"
1
2
2