侧边栏壁纸
  • 累计撰写 121 篇文章
  • 累计创建 25 个标签
  • 累计收到 1 条评论

目 录CONTENT

文章目录

搭建自己专属Shadowsocks

梁来福
2024-06-11 / 0 评论 / 0 点赞 / 44 阅读 / 9804 字
温馨提示:
本文最后更新于 2024-09-02,若内容或图片失效,请留言反馈。部分素材来自网络,若不小心影响到您的利益,请联系我们删除。

服务端

Centos7

# 安装依赖包
yum install python-setuptools && easy_install pip

# 安装Shadowsocks服务端
pip install shadowsocks

Debian / Ubuntu

# 安装依赖包
apt-get install python-pip

# 安装Shadowsocks服务端
pip install shadowsocks

配置文件

# 单SS账号配置
cat > /etc/shadowsocks.json << 'EOF'
{  
    "server":"0.0.0.0",  
    "server_port":8388,  
    "local_address": "127.0.0.1",  
    "local_port":1080,  
    "password":"mypassword",  
    "timeout":300,  
    "method":"aes-256-cfb",  
    "fast_open": false  
}
EOF

# 多SS账号配置
cat > /etc/shadowsocks.json << 'EOF'
{  
    "server":"0.0.0.0",  
    "port_password":{  
     "8381":"xxxxxxx",  
     "8382":"xxxxxxx",  
     "8383":"xxxxxxx",  
     "8384":"xxxxxxx"  
     },  
    "timeout":300,  
    "method":"aes-256-cfb",  
    "fast_open": false  
}
EOF

配置说明

字段

说明

server

ss服务端监听地址

server_port

ss服务端监听端口

local_address

本地监听地址

local_port

本地监听端口

password

账号秘密

timeout

超时时间,单位秒

method

加密方法,默认aes-256-cfb

fast_open

使用TCP_FASTOPEN, true / false

workers

workers数,只支持Unix/Linux系统

启动

# 前台启动
ssserver -c /etc/shadowsocks.json

# 后台启动与停止
ssserver -c /etc/shadowsocks.json -d start  
ssserver -c /etc/shadowsocks.json -d stop

# 开机自启动
echo "ssserver -c /etc/shadowsocks.json -d start " >> /etc/rc.local

# 日志文件的输出位置
tail -100f /var/log/shadowsocks.log

客户端下载地址

Windows   
https://github.com/shadowsocks/shadowsocks-windows/releases   
  
Mac OS X   
https://github.com/shadowsocks/ShadowsocksX-NG/releases 

Linux   
https://github.com/shadowsocks/shadowsocks-qt5/wiki/Installation   
https://github.com/shadowsocks/shadowsocks-qt5/releases  

IOS   
https://itunes.apple.com/app/apple-store/id1070901416?pt=2305194&ct=shadowsocks.org&mt=8   
https://github.com/shadowsocks/shadowsocks-iOS/releases

Android   
https://play.google.com/store/apps/details?id=com.github.shadowsocks   
https://github.com/shadowsocks/shadowsocks-android/releases

遇到问题

安装时

# pip安装shadowsocks时遇到以下问题
[root@vpn ~]# pip install shadowsocks
Collecting shadowsocks
  Could not fetch URL https://pypi.python.org/simple/shadowsocks/: There was a problem confirming the ssl certificate: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:618) - skipping
  Could not find a version that satisfies the requirement shadowsocks (from versions: )
No matching distribution found for shadowsocks

# 解决SSL 证书验证问题
[root@vpn ~]# pip install shadowsocks --trusted-host pypi.python.org --trusted-host pypi.org --trusted-host files.pythonhosted.org

升级时

# 升级时遇到以下问题
[root@vpn ~]# pip install --upgrade shadowsocks
Could not fetch URL https://pypi.python.org/simple/shadowsocks/: There was a problem confirming the ssl certificate: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:618) - skipping
Requirement already up-to-date: shadowsocks in /usr/lib/python2.7/site-packages

# 解决方法1:忽略SSL证书验证
pip install --upgrade shadowsocks --trusted-host pypi.python.org --trusted-host pypi.org --trusted-host files.pythonhosted.org

# 解决方法2:手动更新Shadowsocks
# 下载最新版本的 Shadowsocks
wget https://github.com/shadowsocks/shadowsocks/archive/master.zip
unzip master.zip
cd shadowsocks-master

# 安装
python setup.py install

修改加密方式时

# 讲默认的加密方式aes-256-cfb修改为其他加密方式时,启动ss服务日志出现以下错误
[root@vpn ~]# ssserver -c /etc/shadowsocks.json -d start
INFO: loading config from /etc/shadowsocks.json
2024-07-29 09:25:28 INFO     loading libcrypto from libcrypto.so.3
Traceback (most recent call last):
  File "/usr/local/bin/ssserver", line 33, in <module>
    sys.exit(load_entry_point('shadowsocks==3.0.0', 'console_scripts', 'ssserver')())
  File "/usr/local/lib/python3.9/site-packages/shadowsocks/server.py", line 34, in main
    config = shell.get_config(False)
  File "/usr/local/lib/python3.9/site-packages/shadowsocks/shell.py", line 355, in get_config
    check_config(config, is_local)
  File "/usr/local/lib/python3.9/site-packages/shadowsocks/shell.py", line 210, in check_config
    cryptor.try_cipher(config['password'], config['method'],
  File "/usr/local/lib/python3.9/site-packages/shadowsocks/cryptor.py", line 51, in try_cipher
    Cryptor(key, method, crypto_path)
  File "/usr/local/lib/python3.9/site-packages/shadowsocks/cryptor.py", line 98, in __init__
    self.cipher = self.get_cipher(
  File "/usr/local/lib/python3.9/site-packages/shadowsocks/cryptor.py", line 130, in get_cipher
    return m[METHOD_INFO_CRYPTO](method, key, iv, op, self.crypto_path)
  File "/usr/local/lib/python3.9/site-packages/shadowsocks/crypto/openssl.py", line 151, in __init__
    AeadCryptoBase.__init__(self, cipher_name, key, iv, op, crypto_path)
  File "/usr/local/lib/python3.9/site-packages/shadowsocks/crypto/aead.py", line 162, in __init__
    load_sodium(path)
  File "/usr/local/lib/python3.9/site-packages/shadowsocks/crypto/aead.py", line 81, in load_sodium
    libsodium = util.find_library('sodium', 'sodium_increment',
  File "/usr/local/lib/python3.9/site-packages/shadowsocks/crypto/util.py", line 80, in find_library
    path = ctypes.util.find_library(name)
  File "/usr/lib64/python3.9/ctypes/util.py", line 330, in find_library
    _get_soname(_findLib_gcc(name)) or _get_soname(_findLib_ld(name))
  File "/usr/lib64/python3.9/ctypes/util.py", line 147, in _findLib_gcc
    if not _is_elf(file):
  File "/usr/lib64/python3.9/ctypes/util.py", line 99, in _is_elf
    with open(filename, 'br') as thefile:
FileNotFoundError: [Errno 2] No such file or directory: b'liblibsodium.a'

# 日志可能出现如下提示
load libsodium failed with path None
2024-06-08 04:25:24 INFO     connecting www.google.com:443 from 120.245.113.36:34460
load libsodium failed with path None
load libsodium failed with path None

# 解决:安装libsodium库
# Centos
sudo yum install libsodium -y
yum install libsodium-devel -y

# Debian/Ubuntu
sudo apt-get install libsodium23

安装pip时

# 遇到以下错误,原因是在某些旧版Linux系统上,easy_install 和 setuptools 没有被更新,无法找到最新的包
[root@vpn ~]# easy_install pip
Searching for pip
Reading https://pypi.python.org/simple/pip/
Couldn't find index page for 'pip' (maybe misspelled?)
Scanning index of all packages (this may take a while)
Reading https://pypi.python.org/simple/
No local packages or download links found for pip
error: Could not find suitable distribution for Requirement.parse('pip')

# 解决
# 下载 get-pip.py 脚本,这里我们需要python2的
# python2
curl https://bootstrap.pypa.io/pip/2.7/get-pip.py -o get-pip.py
# 补充一个python3的
# python3
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py


# 运行脚本安装pip
python get-pip.py

函数引用错误

# 启动如下错误
[root@vpn ~]# ssserver -c /etc/shadowsocks.json -d start
AttributeError: /lib/x86_64-linux-gnu/libcrypto.so.1.1: undefined symbol: EVP_CIPHER_CTX_cleanup

# 这是由于在openssl 1.1.0中废弃了 EVP_CIPHER_CTX_cleanup() 函数而引入了EVE_CIPHER_CTX_reset() 函数所导致的
# 解决
定位到openssl.py文件,修改调用函数
vim ******local/lib/python3.9/site-packages/shadowsocks/crypto/openssl.py
搜索 cleanup 并将其替换为 reset
%s/cleanup/reset/g

0
  1. 支付宝打赏

    qrcode alipay
  2. 微信打赏

    qrcode weixin
博主关闭了所有页面的评论