SSR魔改后端安装过程(手动)

SSR 服务端要求Centos 6 系统(推荐 64 位)

安装基本组件和 SSR 后端

yum -y install python-setuptools && easy_install pip
easy_install pip==9.0.3
pip install cymysql speedtest-cli
yum install git
不想一行一行输入?输入下面这个:
yum -y install python-setuptools && easy_install pip && pip install cymysql speedtest-cli && yum install git

CHACHA20 加密方式支持:

如果要使用salsa20chacha20chacha20 IETF标准的算法,请安装libsodium

yum -y groupinstall "Development Tools"
wget https://github.com/jedisct1/libsodium/releases/download/1.0.13/libsodium-1.0.13.tar.gz
tar xf libsodium-1.0.13.tar.gz && cd libsodium-1.0.13
./configure && make -j2 && make install
echo /usr/local/lib > /etc/ld.so.conf.d/usr_local_lib.conf
ldconfig
rm -rf /root/libsodium-1.0.13.tar.gz
cd /root
不想一行一行输入?输入下面这个:
yum -y groupinstall "Development Tools" && wget https://github.com/jedisct1/libsodium/releases/download/1.0.13/libsodium-1.0.13.tar.gz && tar xf libsodium-1.0.13.tar.gz && cd libsodium-1.0.13 && ./configure && make -j2 && make install && echo /usr/local/lib > /etc/ld.so.conf.d/usr_local_lib.conf && ldconfig && rm -rf /root/libsodium-1.0.13.tar.gz && cd /root

(如果提示 cannot import name OrderedDict,可能需要给服务器打补丁:第三方插件 ordereddict easy_install ordereddict )

下载程序源代码

git clone  https://github.com/wggwcn/ssr_manyu.git
cd ssr_manyu

进入 Shadowsocks 这个目录,安装依赖

yum -y install python-devel
yum -y install libffi-devel
yum -y install openssl-devel

Debian 请勿执行下面这个命令,直接 pip install cymysql

pip install -r requirements.txt

配置程序

先得到你的配置文件

cd shadowsocks
cp apiconfig.py userapiconfig.py
cp config.json user-config.json

编辑参数

然后主要编辑userapiconfig.py,只需要修改以下 2 个大类

#节点 ID-和你网站添加的节点分配的 ID 一致!
NODE_ID = 1
#这里必须填,要么选择数据库要么选择 httpapi(大多数使用的是数据库,httpapi 不知怎么弄,2333)
API_INTERFACE = 'glzjinmod' #glzjinmod (数据库方式连接),modwebapi (http api)
# Mysql 数据库连接信息
MYSQL_HOST = '127.0.0.1'
MYSQL_PORT = 3306
MYSQL_USER = 'ss'
MYSQL_PASS = 'ss'
MYSQL_DB = 'shadowsocks'
MYSQL_UPDATE_TIME = 60
#这个虽然可填可不填,但是还是建议把 127.0.0.1 改成你这台服务器的 IP 地址
# Manager (ignore this)
MANAGE_PASS = 'ss233333333'
#if you want manage in other server you should set this value to global ip
MANAGE_BIND_IP = '127.0.0.1'
#make sure this port is idle
MANAGE_PORT = 23333

开始运行

到这里基本算是搞完了,接下来还有自启动和优化

测试服务端是否有错误

cd /root/shadowsocks
python server.py

如果报错,那就再仔细看看到底是哪里的问题。

出现(1042, u”Can’t get hostname for your address”)错误

my.cnf里,[mysqld]项目下
添加

skip-name-resolve

#忽略主机名的方式访问
如果添加了之后且重启之后同样提示1042, u”Can’t get hostname for your address”那么就直接修改 hosts,把 hosts 中全部删除,然后输入

127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6

我们优化下

编辑 /etc/security/limits.conf
最后添加

* soft nofile 51200
* hard nofile 51200

然后在运行之前执行

ulimit -n 51200
或者直接执行
wget https://raw.githubusercontent.com/wggwcn/ssr_manyu/master/centos7/limits.conf -O /etc/security/limits.conf && ulimit -n 51200

然后编辑 /etc/sysctl.conf

fs.file-max = 51200
net.core.rmem_max = 67108864
net.core.wmem_max = 67108864
net.core.netdev_max_backlog = 250000
net.core.somaxconn = 4096
net.ipv4.tcp_syncookies = 1
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_tw_recycle = 0
net.ipv4.tcp_fin_timeout = 30
net.ipv4.tcp_keepalive_time = 1200
net.ipv4.ip_local_port_range = 10000 65000
net.ipv4.tcp_max_syn_backlog = 8192
net.ipv4.tcp_max_tw_buckets = 5000
net.ipv4.tcp_fastopen = 3
net.ipv4.tcp_rmem = 4096 87380 67108864
net.ipv4.tcp_wmem = 4096 65536 67108864
net.ipv4.tcp_mtu_probing = 1

sysctl -p 来使其生效。

或者直接执行

wget https://raw.githubusercontent.com/wggwcn/ssr_manyu/master/centos7/sysctl.conf -O /etc/sysctl.conf && sysctl -p

此处以 centos 6 x64 下配置 supervisord 为例。

rpm -Uvh http://download.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm --quiet
yum install supervisor python-pip -y
pip install supervisor==3.1
chkconfig supervisord on
wget https://raw.githubusercontent.com/wggwcn/ssr_manyu/master/centos7/supervisord.conf -O /etc/supervisord.conf
wget  https://raw.githubusercontent.com/wggwcn/ssr_manyu/master/centos7/supervisord -O /etc/init.d/supervisord

编辑 /etc/supervisord.conf 最后一段改成如下的,以 /root/shadowsocks/ 为例

[program:mu]
command=python /root/shadowsocks/server.py
directory=/root/shadowsocks
autorestart=true
startsecs=10
startretries=36
redirect_stderr=true
user=root ; setuid to this UNIX account to run the program
log_stdout=true ; if true, log program stdout (default true)
log_stderr=true ; if true, log program stderr (def false)
logfile=/var/log/mu.log ; child log path, use NONE for none; default AUTO
;logfile_maxbytes=1MB ; max # logfile bytes b4 rotation (default 50MB)
;logfile_backups=10 ; # of logfile backups (default 10)

编辑 /etc/init.d/supervisord 在这两行之间添加 ulimit -n 51200

echo -n $"Starting supervisord: "
ulimit -n 51200
daemon supervisord -c /etc/supervisord.conf

然后

service supervisord start #开始运行守护程序

其他指令

测速

speedtest-cli

关闭防火墙

chkconfig iptables off
service iptables stop

关于升级

cd shadowsocks
git pull

如果出现git clone 项目错误,一般是ssl错误 

解决办法

yum update -y nss curl libcurl

出现 pip install cymysql 错误的问题 ,是因为pip的库太低了,或者pip的问题,以下是直接通过yum 安装 cymysql的库

yum install mysql-devel

科学上网教程~节点 希望大家喜欢快乐