在服务器上部署Shadowsocks

Github学生优惠包里面有一个DigitalOcean的50美元代金券,绑定信用卡充值5美元就可以用了,性价比还是非常高的。事实上我自己已经用了快一年了,一直没有总结过这个搭建步骤,今天姑且写下来吧,还是蛮简单的其实。。。

系统推荐Debian8,以下命令都在终端内执行即可,请先切换至root用户sudo -i

  1. 安装依赖项

    1
    apt-get install git build-essential
  2. 下载Shadowsocks源码并配置好

    1
    2
    3
    4
    git clone -b manyuser https://github.com/shadowsocksr/shadowsocksr.git
    cd shadowsocksr
    bash initcfg.sh
    vi user-config.json

    主要修改以下几项配置: server_port、password、method、protocol,配置具体意义参考[1]

    1
    2
    3
    4
    "server_port": 443
    "method": "chacha20"
    "protocol": "origin"
    "obfs": "tls1.2_ticket_auth_compatible"
  3. 配置脚本,vi /etc/init.d/shadowsocks && chmod +x /etc/init.d/shadowsocks,把以下内容复制进去:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    #!/bin/sh
    # chkconfig: 2345 90 10
    # description: Start or stop the Shadowsocks R server
    #
    ### BEGIN INIT INFO
    # Provides: Shadowsocks-R
    # Required-Start: $network $syslog
    # Required-Stop: $network
    # Default-Start: 2 3 4 5
    # Default-Stop: 0 1 6
    # Description: Start or stop the Shadowsocks R server
    ### END INIT INFO

    # Author: Yvonne Lu(Min) <min@utbhost.com>

    name=shadowsocks
    PY=/usr/bin/python
    SS=/root/shadowsocksr/shadowsocks/server.py
    SSPY=server.py
    conf=/root/shadowsocksr/user-config.json

    start(){
    $PY $SS -c $conf -d start
    RETVAL=$?
    if [ "$RETVAL" = "0" ]; then
    echo "$name start success"
    else
    echo "$name start failed"
    fi
    }

    stop(){
    pid=`ps -ef | grep -v grep | grep -v ps | grep -i "${SSPY}" | awk '{print $2}'`
    if [ ! -z "$pid" ]; then
    $PY $SS -c $conf -d stop
    RETVAL=$?
    if [ "$RETVAL" = "0" ]; then
    echo "$name stop success"
    else
    echo "$name stop failed"
    fi
    else
    echo "$name is not running"
    RETVAL=1
    fi
    }

    status(){
    pid=`ps -ef | grep -v grep | grep -v ps | grep -i "${SSPY}" | awk '{print $2}'`
    if [ -z "$pid" ]; then
    echo "$name is not running"
    RETVAL=1
    else
    echo "$name is running with PID $pid"
    RETVAL=0
    fi
    }

    case "$1" in
    'start')
    start
    ;;
    'stop')
    stop
    ;;
    'status')
    status
    ;;
    'restart')
    stop
    start
    RETVAL=$?
    ;;
    *)
    echo "Usage: $0 { start | stop | restart | status }"
    RETVAL=1
    ;;
    esac
    exit $RETVAL

  4. 编译libsodium

    1
    2
    3
    4
    5
    cd ~
    wget https://github.com/jedisct1/libsodium/releases/download/1.0.12/libsodium-1.0.12.tar.gz
    tar xf libsodium-1.0.12.tar.gz && cd libsodium-1.0.12
    ./configure && make -j2 && make install
    ldconfig

  5. 启动shadowsocks服务

    1
    /etc/init.d/shadowsocks start

  6. (推荐)配置BBR加速,具体参考[2]

    1
    2
    3
    4
    cd ~
    wget --no-check-certificate https://github.com/teddysun/across/raw/master/bbr.sh
    chmod +x bbr.sh
    ./bbr.sh


  1. 1.https://github.com/breakwa11/shadowsocks-rss/wiki/config.json ↩︎
  2. 2.https://teddysun.com/489.html ↩︎