文章

debian8上ShadowsocksR 单用户服务端安装教程。

  编辑于:2018-01-21
文章目录

安装相关软件

更新系统,安装相关软件。

apt-get install git
git clone -b manyuser https://github.com/shadowsocksr-backup/shadowsocksr.git
cd shadowsocksr
bash initcfg.sh

进入单用户版子目录 cd ~/shadowsocksr/shadowsocks

运行

快速运行

python server.py -p 443 -k password -m aes-256-cfb -O auth_sha1_v4 -o http_simple

#说明:-p 端口 -k 密码  -m 加密方式 -O 协议插件 -o 混淆插件

后台运行

python server.py -p 443 -k password -m aes-256-cfb -O auth_sha1_v4 -o http_simple -d start
#如果要停止/重启:
python server.py -d stop/restart

查看日志:

tail -f /var/log/shadowsocksr.log

用 -h 查看所有参数

利用配置文件运行


修改shadowsocksR配置文件 user-config.json

{
    "server": "0.0.0.0",
    "server_ipv6": "::",
    "server_port": 443,  //端口
    "local_address": "127.0.0.1",
    "local_port": 1080,

    "password": "password",  //密码
    "method": "aes-256-ctr",
    "protocol": "auth_aes128_md5",
    "protocol_param": "",
    "obfs": "tls1.2_ticket_auth_compatible",
    "obfs_param": "",
    "speed_limit_per_con": 0,
    "speed_limit_per_user": 0,

    "additional_ports" : {}, // only works under multi-user mode
    "additional_ports_only" : false, // only works under multi-user mode
    "timeout": 120,
    "udp_timeout": 60,
    "dns_ipv6": false,
    "connect_verbose_info": 0,
    "redirect": "",
    "fast_open": false
}

客户端设置要和服务端一致。
自启动:
以下启动脚本均假定shadowsocks-rss安装于/root/shadowsocksr目录,配置文件为/root/shadowsocksr/user-config.json,请按照实际情况自行修改
SysVinit启动脚本,适合CentOS/RHEL6系以及Ubuntu 14.x,Debian7.x
创建文件:vi /etc/init.d/shadowsocks

#!/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) 

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

CentOS/RHEL6 执行:

chmod 755 /etc/init.d/shadowsocks && chkconfig --add shadowsocks && service shadowsocks start

Ubuntu 14.x,Debian7.x 执行:

chmod 755 /etc/init.d/shadowsocks ; update-rc.d shadowsocks defaults ; service shadowsocks start

systemd脚本,适用于CentOS/RHEL7以上,Ubuntu 15以上,Debian8以上
创建脚本: vi /etc/systemd/system/shadowsocksr.service
单用户版

[Unit]
Description=ShadowsocksR server
After=network.target
Wants=network.target

[Service]
Type=forking
PIDFile=/var/run/shadowsocksr.pid
ExecStart=/usr/bin/python /root/shadowsocksr/shadowsocks/server.py --pid-file /var/run/shadowsocksr.pid -c /root/shadowsocksr/user-config.json -d start
ExecStop=/usr/bin/python /root/shadowsocksr/shadowsocks/server.py --pid-file /var/run/shadowsocksr.pid -c /root/shadowsocksr/user-config.json -d stop
ExecReload=/bin/kill -HUP $MAINPID
KillMode=process
Restart=always

[Install]
WantedBy=multi-user.target

多用户版

[Unit]
Description=ShadowsocksR server
After=syslog.target
After=network.target

[Service]
LimitCORE=infinity
LimitNOFILE=512000
LimitNPROC=512000
Type=simple
WorkingDirectory=/root/shadowsocksr
ExecStart=/usr/bin/python /root/shadowsocksr/server.py
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s TERM $MAINPID
Restart=always

[Install]
WantedBy=multi-user.target

保存后执行:

systemctl enable shadowsocksr.service && systemctl start shadowsocksr.service

libsodium

如果要使用 salsa20 或 chacha20 或 chacha20-ietf 算法,请安装 libsodium :
centos:

yum install epel-release
yum install libsodium

如果想自己编译,那么可以用以下的命令

yum -y groupinstall "Development Tools"
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
echo /usr/local/lib > /etc/ld.so.conf.d/usr_local_lib.conf
ldconfig

ubuntu/debian:

apt-get install build-essential
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

如果曾经安装过旧版本,亦可重复用以上步骤更新到最新版,仅1.0.4或以上版本支持chacha20-ietf
参考链接:https://github.com/shadowsocksr-backup/shadowsocks-rss/wiki/Server-Setup

发表回复