linux(ubuntu)下运行shadowsocks客户端

最终一键脚本:ssc-1key-linux

系统: Ubuntu 22.04

shadowsocks相关

  1. 将系统更新到最新版
  2. 安装shadowsocks及必要组件
    pip install https://github.com/shadowsocks/shadowsocks/archive/master.zip -U
    sudo apt-get install -y libsodium*
  3. 配置shadowsocks client
    sudo vi /etc/shadowsocks.json
{
  "server": "您服务器地址",
  "server_port": 9999,
  "local_address": "127.0.0.1",
  "local_port": 1080,
  "password": "密码",
  "timeout": 600,
  "method": "aes-256-cfb"
}
  1. 解决sodium库问题
    sudo ln -s /usr/lib/x86_64-linux-gnu/libsodium.a /usr/lib/x86_64-linux-gnu/liblibsodium.a

  2. 设置路径权限
    sudo chmod 777 /var/log
    sudo chmod 777 /var/run

  3. shadowsocks 开机自启动
    sudo vim /etc/systemd/system/shadowsocks.service:

    Description=Shadowsocks Client Service
    After=network.target
    [Service]
    Type=simple
    User=root
    ExecStart=/usr/local/bin/sslocal -c /etc/shadowsocks.json restart
    [Install]
    WantedBy=multi-user.target

    systemctl enable shadowsocks.service

HTTP全局代理

实现全局代理,我们可以使用polipo

  1. polipo 安装
    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
    配置 vi /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

    polipo安装后会自动运行。

  2. 通过polipo设置本地http代理

    export http_proxy=http://127.0.0.1:8123
    export https_proxy=http://127.0.0.1:8123

    取消代理
    unset http_proxy
    unset https_proxy

pac代理

如果想使用http下的pac机制,可以考虑用provoxy替换polipo

  1. provoxy 安装
    安装:sudo apt-get install -y privoxy
    cp /etc/privoxy/config /etc/privoxy/config.bak
    vim /etc/privoxy/config
    确保 listen-address 127.0.0.1:8118 打开
    在/etc/profile, ~/.bashrc,~/.bash_profile 中添加:

    proxy="http://127.0.0.1:8118"
    export https_proxy=$proxy
    export http_proxy=$proxy
    export ftp_proxy=$proxy

    systemctl enable privoxy
    systemctl restart privoxy

  2. GFWList2Privoxy 制作pac条目
    pip install gfwlist2privoxy
    添加自定义域名:在生成的gfwlist.action文件中添加需要通过proxy访问的域名
    使pac生效:在/etc/privoxy/config文件中加上actionsfile gfwlist.action,然后重启privoxy服务

issue shooting:

  1. AttributeError: module 'collections' has no attribute 'MutableMapping'
    解决:/home/zcj/.local/lib/python3.10/site-packages/shadowsocks/lru_cache.py 34行 MutableMapping前面加上abc.
  2. [Errno 2] No such file or directory: b'liblibsodium.a'
    解决:sudo ln -s /usr/lib/x86_64-linux-gnu/libsodium.a /usr/lib/x86_64-linux-gnu/liblibsodium.a

参考:

  1. https://github.com/enpenguc/linux-backup/blob/master/doc/Ubuntu%20Server%E5%AE%89%E8%A3%85shadowsocks%E5%AE%A2%E6%88%B7%E7%AB%AF.md

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注