由于Ubuntu Server是不带用户界面的,所以要为Server配置Shadowsocks还是稍显麻烦。本文就是我配置Shadowsocks的一些经验,以待参考。
安装 Shadowsocks
由于shadowsocks是基于python开发的,所以必须安装python:
royakon@royakon-storage:~$ apt-get install python
接着安装python的包管理器pip:(由于Ubuntu Server 20.04 lts 默认为python3)
royakon@royakon-storage:~$ sudo apt-get install python3-pip
通过pip3直接安装 Shadowsocks
royakon@royakon-storage:~$ sudo pip3 install shadowsocks
配置 Shadowsocks
新建配置文件
royakon@royakon-storage:~$ mkdir shadowsocks
royakon@royakon-storage:~$ touch ./shadowsocks/ss.json
royakon@royakon-storage:~$ vim ./shadowscoks/ss.json
{
"server": "{your-server}",
"server_port": 40002,
"local_port": 1080,
"password": "{your-password}",
"timeout": 600,
"method": "aes-256-cfb"
}
启动Shadowsocks
royakon@royakon-storage:~$ sudo sslcoal -c ./shadowsocks/ss.json -d start
Shadowsocks启动报错undefined symbol: EVP_CIPHER_CTX_cleanup
royakon@royakon-storage:~$ sudo sslcoal -c ./shadowsocks/ss.json -d start
AttributeError: /usr/local/ssl/lib/libcrypto.so.1.1: undefined symbol: EVP_CIPHER_CTX_cleanup
shadowsocks start failed
修改Shadowsocks内的openssl.py文件
royakon@royakon-storage:~$ sudo vim /usr/local/lib/python3.8/dist-packages/shadowscoks/crypto/openssl.py
# 修改libcrypto.EVP_CIPHER_CTX_cleanup.argtypes,注意以下为 VIM命令
:%s/cleanup/reset/
:x
由于 Shadowsocks 为 Sock5 代理,并不能直接用于系统全局及命令行,配合Privoxy将sock5代理映射为http代理
安装Privoxy
安装
royakon@royakon-storage:~$ sudo apt-get install privoxy
配置
royakon@royakon-storage:~$ sudo vim /etc/privoxy/config
listen-address 127.0.0.1:8118
forward-socks5 / 127.0.0.1:1080 . #此处端口号与Shadowsocks配置文件内local_port一致
重启服务
royakon@royakon-storage:~$ sudo service privoxy restart
配置全局代理
配置命令行全局代理及测试
royakon@royakon-storage:~$ export http_proxy='http://127.0.0.1:8118'
royakon@royakon-storage:~$ export https_proxy='http://127.0.0.1:8118'
royakon@royakon-storage:~$ curl -v https://www.google.com