iPlay / iTech · 2017年6月29日 0

搭建ShadowsocksR教程(Python版)

写在前面

先买一台ping值还差不多的vps,然后就开始折腾。推荐使用centos。

1.安装运行环境。

yum install python-setuptools && easy_install pip

yum install git

注意:easy_install pip 命令已经失效,请更改为yum -y install python-pip即可

2.安装ShadowsocksR

git clone -b manyuser https://github.com/shadowsocksr/shadowsocksr.git

默认安装位置会在root目录下。

进行服务器端配置

cd ~/shadowsocksr
bash initcfg.sh

3.把root目录的文件,转移到/usr/local目录下

然后在shadowsocksr/shadowsocks目录下创建一个config.json配置文件

内容如下:

{
"server":"0.0.0.0",
"server_ipv6":"::",
"local_address":"127.0.0.1",
"local_port":1080,
"port_password":{
"6388":{"protocol":"auth_aes128_md5","protocol_param":"xx","password":"xxxxxxxx", "obfs":"tls1.2_ticket_auth","obfs_param":"xxxxxxxx"},
"6389":{"protocol":"origin", "password":"xxxxxxxx"},
"6390":{"protocol":"origin", "password":"xxxxxxxx"}
},
"timeout":300,
"method":"aes-256-cfb",
"protocol": "auth_sha1_compatible",
"protocol_param": "",
"obfs": "http_simple_compatible",
"obfs_param": "",
"redirect": "",
"dns_ipv6": false,
"fast_open": false,
"workers": 1
}

创建方法:

进入shadowsocks目录:输入命令

cd /usr/local/shadowsocksr/shadowsocks

vi config.json

按i 进入编辑模式,粘贴后,按esc 退出编辑模式,输入 :wq 保存!

4.创建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) <min@utbhost.com>

name=shadowsocks
PY=/usr/bin/python
SS=/usr/local/shadowsocksr/shadowsocks/server.py
SSPY=server.py
conf=/usr/local/shadowsocksr/shadowsocks/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

进入/etc/init.d目录,创建shadowsocks文件

vi /etc/init.d/shadowsocks

5.加入开机自启动

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

该行为一行。

6.修改/etc/sysconfig 的iptables文件,对端口进行放行。

7.reboot。

教程结束。