Linux 部署 shadowsocks-libev 服务端
后知后觉 暂无评论

在常见的 Linux 发行版上部署 shadowsocks-libev 服务端

shadowsocks 的 libev 版本相比于 python 版本

具有以下特性:


先决条件

获取最新源码

使用以下命令获取最新源码,并更新其子模块:

git clone https://github.com/shadowsocks/shadowsocks-libev.git
cd shadowsocks-libev
git submodule update --init --recursive

编译安装 libsodium 加密支持库

最低需要 libsodium 1.0.8,但是强烈推荐使用最新版本进行编译安装。详情请看 在 UNIX-like 系统上进行直接安装 一章。

安装过程

快速链接指南

预备编译的配置工作

其他可用配置选项的完整列表,请尝试使用 configure --help 命令。

Debian & Ubuntu

从仓库安装官方构建版

shadowsocks-libev 现在可在官方仓库中安装(版本相对较旧)

小贴士:虽然不限定版本,但是只推荐在相对较新的版本中进行编译和构建。
sudo apt update
sudo apt install shadowsocks-libev

从源码自行构建 DEB 安装包

支持的发行版:

你可以使用以下脚本构建 shadowsocks-libev 和其全部所需依赖:

mkdir -p ~/build-area/
cp ./scripts/build_deb.sh ~/build-area/
cd ~/build-area
./build_deb.sh
注意:对于更加古老的 Debian 版本,不支持构建 .deb 包。

对于部分稍微老旧的版本,需要注意。

配置并启动服务

# 修改配置文件
sudo vim /etc/shadowsocks-libev/config.json

# 修改默认配置
sudo vim /etc/default/shadowsocks-libev

# 启动服务进程
sudo /etc/init.d/shadowsocks-libev start    # for sysvinit, or
sudo systemctl start shadowsocks-libev      # for systemd

Fedora & RHEL & CentOS

支持的发行版:

从仓库中安装

启用仓库 dnf,然后通过 dnf 安装 shadowsocks-libev

su -c 'dnf copr enable librehat/shadowsocks'
su -c 'dnf update'
su -c 'dnf install shadowsocks-libev'

或从 Fedora Copr 下载放置到 /etc/yum.repos.d/,然后从 yum 安装。

su -c 'yum update'
su -c 'yum install shadowsocks-libev'
小贴士:此仓库由 @librehat 维护,问题请 点击此处反馈

CentOS 上的编译安装

如果使用 CentOS 7,则需要安装以下所需依赖。

yum install epel-release -y
yum install gcc gettext autoconf libtool automake make pcre-devel asciidoc xmlto c-ares-devel libev-devel libsodium-devel mbedtls-devel -y

ArchLinux

sudo pacman -S shadowsocks-libev

请参考下游 PKGBUILD

Linux

默认需要以下依赖:

注意(*):Fedora 26 libsodium 版本 >= 1.0.12,所以需要通过 dnf 安装 libsodium 而不是从源码编译安装。

对于部分旧版本系统,请使用以下命令安装依赖:

# Installation of basic build dependencies
## Debian / Ubuntu
sudo apt-get install --no-install-recommends gettext build-essential autoconf libtool libpcre3-dev asciidoc xmlto libev-dev libc-ares-dev automake libmbedtls-dev libsodium-dev
## CentOS / Fedora / RHEL
sudo yum install gettext gcc autoconf libtool automake make asciidoc xmlto c-ares-devel libev-devel
## Arch
sudo pacman -S gettext gcc autoconf libtool automake make asciidoc xmlto c-ares libev

# Installation of Libsodium
export LIBSODIUM_VER=1.0.13
wget https://download.libsodium.org/libsodium/releases/libsodium-$LIBSODIUM_VER.tar.gz
tar xvf libsodium-$LIBSODIUM_VER.tar.gz
pushd libsodium-$LIBSODIUM_VER
./configure --prefix=/usr && make
sudo make install
popd
sudo ldconfig

# Installation of MbedTLS
export MBEDTLS_VER=2.6.0
wget https://tls.mbed.org/download/mbedtls-$MBEDTLS_VER-gpl.tgz
tar xvf mbedtls-$MBEDTLS_VER-gpl.tgz
pushd mbedtls-$MBEDTLS_VER
make SHARED=1 CFLAGS=-fPIC
sudo make DESTDIR=/usr install
popd
sudo ldconfig

# Start building
./autogen.sh && ./configure && make
sudo make install

FreeBSD

直接构建即可

su
cd /usr/ports/net/shadowsocks-libev
make install

编辑 config.json 文件,在默认情况下,配置文件位于 /usr/local/etc/shadowsocks-libev

启用 shadowsocks-libev ,添加如下的 rc 变量至 /etc/rc.conf 文件中即可。

shadowsocks_libev_enable="YES"

启动服务端

service shadowsocks_libev start

OpenWRT

直接使用 OpenWRT 专属的 shadowsocks 版本即可,需要配合 luci-app-shadowsocks 使用。

用法

有关所有支持参数的详细、完整列表,可以分别参考应用程序的手册页。

    ss-[local|redir|server|tunnel|manager]

       -s <server_host>           host name or ip address of your remote server

       -p <server_port>           port number of your remote server

       -l <local_port>            port number of your local server

       -k <password>              password of your remote server

       -m <encrypt_method>        Encrypt method: rc4-md5,
                                  aes-128-gcm, aes-192-gcm, aes-256-gcm,
                                  aes-128-cfb, aes-192-cfb, aes-256-cfb,
                                  aes-128-ctr, aes-192-ctr, aes-256-ctr,
                                  camellia-128-cfb, camellia-192-cfb,
                                  camellia-256-cfb, bf-cfb,
                                  chacha20-poly1305, chacha20-ietf-poly1305
                                  salsa20, chacha20 and chacha20-ietf.

       [-f <pid_file>]            the file path to store pid

       [-t <timeout>]             socket timeout in seconds

       [-c <config_file>]         the path to config file

       [-i <interface>]           network interface to bind,
                                  not available in redir mode

       [-b <local_address>]       local address to bind

       [-u]                       enable udprelay mode,
                                  TPROXY is required in redir mode

       [-U]                       enable UDP relay and disable TCP relay,
                                  not available in local mode

       [-L <addr>:<port>]         specify destination server address and port
                                  for local port forwarding,
                                  only available in tunnel mode

       [-d <addr>]                setup name servers for internal DNS resolver,
                                  only available in server mode

       [--fast-open]              enable TCP fast open,
                                  only available in local and server mode,
                                  with Linux kernel > 3.7.0

       [--acl <acl_file>]         config file of ACL (Access Control List)
                                  only available in local and server mode

       [--manager-address <addr>] UNIX domain socket address
                                  only available in server and manager mode

       [--executable <path>]      path to the executable of ss-server
                                  only available in manager mode

       [--plugin <name>]          Enable SIP003 plugin. (Experimental)
       [--plugin-opts <options>]  Set SIP003 plugin options. (Experimental)

       [-v]                       verbose mode

注意:

    ss-redir 提供透明代理功能,仅可用于
    Linux 发行版 with iptables.

编译 SIP003 插件

simple-obfs (Deprecated)

准备

构建

预备编译的配置工作,其他可用配置选项的完整列表,请尝试使用 configure --help 命令。

用法

有关所有支持的参数的详细和完整的列表,可分别参考应用程序的手册页。


附录

参考链接

本文撰写于一年前,如出现图片失效或有任何问题,请在下方留言。博主看到后将及时修正,谢谢!
禁用 / 当前已拒绝评论,仅可查看「历史评论」。