前面https://zorz.cc/?p=190介绍了前端的搭建,这里记录一下后端的搭建。
相关资料
debian8搭建 sspanel v3 (new_master)魔改版前端
ocserv anyconnect(VPN freeradius)对接sspanel v3 mod
后端安装
安装 libsodium
apt-get install build-essential wget -y wget https://github.com/jedisct1/libsodium/releases/download/1.0.10/libsodium-1.0.10.tar.gz tar xf libsodium-1.0.10.tar.gz && cd libsodium-1.0.10 ./configure && make -j2 && make install ldconfig
下载SSR魔改版
apt-get install python-pip git -y git clone -b manyuser https://github.com/glzjin/shadowsocks.git cd shadowsocks chmod +x *.sh # 配置程序 cp apiconfig.py userapiconfig.py cp config.json user-config.json
使用glzjinmod模式
这个模式后端将直接连接到数据库。
安装 cymysql
pip install cymysql
修改shadowsocks目录中的userapiconfig.py
# Config #节点ID 对应前端节点列表的ID NODE_ID = 1 #自动化测速,为0不测试,此处以小时为单位,要和 ss-panel 设置的小时数一致 SPEEDTEST = 6 #云安全,自动上报与下载封禁IP,1为开启,0为关闭 CLOUDSAFE = 1 #自动封禁SS密码和加密方式错误的 IP,1为开启,0为关闭 ANTISSATTACK = 0 #是否接受上级下发的命令,如果你要用这个命令,请参考我之前写的东西,公钥放在目录下的 ssshell.asc AUTOEXEC = 1 #是否以多线程模式运行,关闭这个限速就会无效。请优先测试 1 ,开启试试,能运行没。 MULTI_THREAD = 0 #多端口单用户设置,看重大更新说明,此处应和前端的.config.php的配置相同。 MU_SUFFIX = 'zhaoj.in' #多端口单用户设置,看重大更新说明,此处应和前端的.config.php的配置相同。 MU_REGEX = '%5m%id.%suffix' #不明觉厉 SERVER_PUB_ADDR = '127.0.0.1' # mujson_mgr need this to generate ssr link #此处不要修改 API_INTERFACE = 'glzjinmod' #mudbjson, sspanelv2, sspanelv3, sspanelv3ssr, muapiv2(not support) #mudb,不要管 MUDB_FILE = 'mudb.json' # Mysql 数据库连接信息 MYSQL_HOST = '127.0.0.1' MYSQL_PORT = 3306 MYSQL_USER = 'ss' MYSQL_PASS = 'ss' MYSQL_DB = 'shadowsocks' MYSQL_UPDATE_TIME = 60 # 是否启用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
使用modwebapi模式
安装相关软件。
apt-get install libssl-dev python-dev libffi-dev python-setuptools -y pip install requests
修改shadowsocks目录中的userapiconfig.py
API_INTERFACE = 'modwebapi' # glzjinmod, modwebapi WEBAPI_URL = '网站URL,需要完整输入https://' WEBAPI_TOKEN = '需要和前端的.config.php中$System_Config['muKey'] = 'TOKEN';'相同。
其他设置参考上面的配置说明。
测试通讯:
curl 站点地址/mod_mu/func/ping?key=WEBAPI_TOKEN
其中 WEBAPI_TOKEN 为您网站 config/.config.php 内 muKey 的值
有返回pong就表明可以正常通讯了
使用此模式建议将nginx的keepalive修改为75。
修改/usr/local/nginx/conf/nginx.conf
keepalive_timeout 75;
面板会验证 api 请求的来源 IP 是否为节点 IP,如果用了 CDN,记得想办法把正确的 IP 传到面板上,比如用 nginx 的 real_ip 模块,这里简单说下 LNMP 重新安装 nginx 并开启real_ip 模块。这里以CDN为CLOUDFLARE为例,可以参考本博客的另外一篇文章:https://zorz.cc/post/nginx-cdn-real-ip.html
这里的修改是修改前端面板的NGINX配置:debian8搭建 sspanel v3 (new_master)魔改版前端
set_real_ip_from 103.21.244.0/22; set_real_ip_from 103.22.200.0/22; set_real_ip_from 103.31.4.0/22; set_real_ip_from 104.16.0.0/12; set_real_ip_from 108.162.192.0/18; set_real_ip_from 131.0.72.0/22; set_real_ip_from 141.101.64.0/18; set_real_ip_from 162.158.0.0/15; set_real_ip_from 172.64.0.0/13; set_real_ip_from 173.245.48.0/20; set_real_ip_from 188.114.96.0/20; set_real_ip_from 190.93.240.0/20; set_real_ip_from 197.234.240.0/22; set_real_ip_from 198.41.128.0/17; set_real_ip_from 199.27.128.0/21; set_real_ip_from 2400:cb00::/32; set_real_ip_from 2606:4700::/32; set_real_ip_from 2803:f800::/32; set_real_ip_from 2405:b500::/32; set_real_ip_from 2405:8100::/32; set_real_ip_from 2c0f:f248::/32; set_real_ip_from 2a06:98c0::/29; # use any of the following two # real_ip_header CF-Connecting-IP; real_ip_header X-Forwarded-For; real_ip_recursive on;
如果使用 nginx 的 real_ip 模块依旧报错, 面板验证不了请求来源的 IP, 这时候就需要修改 hosts 文件
vi /etc/hosts # 添加你的面板IP 和 网站域名 如: 1.2.3.4 ss.panel
如果您要使用这个对用户友好的审计规则阻断页面功能,请在 user-config.json 中将 friendly_detect 设置为 1(没有这个设置就自己添加一个),然后试着访问某个在审计规则里的 http 网页就可以看到效果了。当然目前仅对访问 80 端口的 http 请求有效。
如果您想自定义这个阻断页面的内容,可以复制 detect.html 为 user-detect.html 然后修改 user-detect.html ,重启后端即可自定义。
运行后端
运行的话, 有几种方式
python server.py 用于调错的
./run.sh 无日志后台运行
./logrun.sh 有日志后台运行
supervisord
这里说下 使用Supervisor守护进程启动ssr
# 安装 apt-get install supervisor -y # 写入配置 vi /etc/supervisor/conf.d/ssr.conf # 写入以下内容 [program:ssr] command=python /root/shadowsocks/server.py autorestart=true autostart=true user=root # 重启Supervisor服务。 /etc/init.d/supervisor restart # 重启 ssr supervisorctl restart ssr # 查看Supervisor服务运行状态。 supervisorctl status # 如果遇到问题,可以检查日志: supervisorctl tail -f ssr stderr # 如果使用supervisor进程守护,需要修改文件vi /etc/default/supervisor,添加一行: ulimit -n 1024000