SSR魔改后端安装过程

[v_blue]这篇文章是教你怎么搭建与ss-panel魔改版相结合的ssr服务端的教程,可能会遇到各种问题,我也会在我设置的过程中遇到的问题提出来。肯定会有很多漏洞之类的,还请谅解。[/v_blue]
[v_tips]Debian有一键操作脚本:具体请看菊花大佬的gayhub 反正我是没看懂。[/v_tips]
[v_blue]菊花大佬的通用一键脚本:
如果你是webapi请下载配置文件然后根据文件内容修改并上传到你的网站,然后将命令中的
file.digac.cc/SSR/Server/修改为你网站上存放配置文件的目录链接即可如果你是数据库,请直接使用下面的命令,之后进入主目录修改文件
[/v_blue]
cd /root && wget -O 55R.sh https://blog.wxlost.com/one/code/onepve/server/55R.sh && chmod +x 55R.sh && bash 55R.sh file.digac.cc/SSR/Server/
SSR服务端要求Centos 6系统(推荐64位);
安装基本组件和SSR后端
yum -y install python-setuptools && easy_install pip
pip install cymysql speedtest-cli
yum install git
[v_notice]不想一行一行输入?输入下面这个:[/v_notice]
yum -y install python-setuptools && easy_install pip && pip install cymysql speedtest-cli
yum -y install git unzip
CHACHA20加密方式支持:
如果要使用
salsa20或chacha20或chacha20 IETF标准的算法,请安装libsodium:[v_blue]参考https://github.com/breakwa11/shadowsocks-rss/wiki/Server-Setup[/v_blue]
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
[v_notice]
不想一行一行输入?输入下面这个:[/v_notice]
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 )下载程序源代码
wget https://file.digac.cc/SSR/Server/shadowsocks.zip
unzip shadowsocks.zip
进入
shadowsocksr 这个目录,安装依赖
yum -y install python-devel
yum -y install libffi-devel
yum -y install openssl-devel
Debian 请勿执行下面这个命令,直接
pip install cymysql
pip install -r requirements.txt
[v_notice]如果出现错误:
ERROR: Cannot uninstall 'requests'. It is a distutils installed project and thus we cannot accurately determine which files belong to it which would lead to only a partial uninstall.则输入
sudo pip install --ignore-installed requests[/v_notice]
配置程序
先得到你的配置文件
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
开始运行
[v_notice]到这里基本算是搞完了,接下来还有自启动和优化[/v_notice]
测试服务端是否有错误
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
然后编辑
/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 来使其生效。此处以
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://github.com/glzjin/ssshell-jar/raw/master/supervisord.conf -O /etc/supervisord.conf
wget https://github.com/glzjin/ssshell-jar/raw/master/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
开机自启动-2
echo 'bash /root/shadowsocks/logrun.sh' >> /etc/rc.local
nohup python /root/ServerStatus/clients/client-psutil.py
chmod +x /etc/rc.d/rc.local
Nat小鸡需要端口转发,使用逗比的脚本
wget -N --no-check-certificate https://softs.wtf/Bash/iptables-pf.sh && chmod +x iptables-pf.sh && bash iptables-pf.sh #主要下载
wget -N --no-check-certificate https://raw.githubusercontent.com/ToyoDAdoubi/doubi/master/iptables-pf.sh && chmod +x iptables-pf.sh && bash iptables-pf.sh #备用下载
./iptables-pf.sh
补充:
userapiconfig.py,解释下里面各项配置的意思
# Config
#节点ID
NODE_ID = 1
#自动化测速,为0不测试,此处以小时为单位,要和 ss-panel 设置的小时数一致
SPEEDTEST = 6
#云安全,自动上报与下载封禁IP,1为开启,0为关闭
CLOUDSAFE = 1
#自动封禁SS密码和加密方式错误的 IP,1为开启,0为关闭
ANTISSATTACK = 0
#是否接受上级下发的命令,如果你要用这个命令,请参考我之前写的东西,公钥放在目录下的 ssshell.asc
AUTOEXEC = 1
多端口单用户设置,看重大更新说明。
MU_SUFFIX = 'zhaoj.in'
多端口单用户设置,看重大更新说明。
MU_REGEX = '%5m%id.%suffix'
#不明觉厉
SERVER_PUB_ADDR = '127.0.0.1' # mujson_mgr need this to generate ssr link
#访问面板方式
API_INTERFACE = 'glzjinmod' #glzjinmod (数据库方式连接),modwebapi (http api)
#mudb,不要管
MUDB_FILE = 'mudb.json'
# HTTP API 的相关信息,看重大更新说明。
WEBAPI_URL = 'https://zhaoj.in'
WEBAPI_TOKEN = 'glzjin'
# Mysql 数据库连接信息
MYSQL_HOST = '127.0.0.1'
MYSQL_PORT = 3306
MYSQL_USER = 'ss'
MYSQL_PASS = 'ss'
MYSQL_DB = 'shadowsocks'
# 是否启用SSL连接,0为关,1为开
MYSQL_SSL_ENABLE = 0
# 客户端证书目录,请看 https://github.com/glzjin/shadowsocks/wiki/Mysql-SSL%E9%85%8D%E7%BD%AE
MYSQL_SSL_CERT = '/root/shadowsocks/client-cert.pem'
MYSQL_SSL_KEY = '/root/shadowsocks/client-key.pem'
MYSQL_SSL_CA = '/root/shadowsocks/ca.pem'
# API,不用管
API_HOST = '127.0.0.1'
API_PORT = 80
API_PATH = '/mu/v2/'
API_TOKEN = 'abcdef'
API_UPDATE_TIME = 60
# Manager 不用管
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
#安全设置,限制在线 IP 数所需,下面这个参数随机设置,并且所有节点需要保持一致。
IP_MD5_SALT = 'randomforsafety'
链接
链接:安装SSR魔改前端


