ShadowSocks go mu + ss panel 添加节点

之前布置Panel+ss后台的时候遇上了不少麻烦

现需要在一台CentOS 7.2的机器上布置ss go mu并使用web api方式连接一台已经配置好的机器,通过redis授权。

首先

[code language=”bash”]yum install go screen git curl redis emacs[/code]

设置Go path:

[code language=”bash”]export PATH=$PATH:/usr/local/go/bin
export GOPATH=~/.go[/code]

安装ss go mu:

[code language=”bash”]go get github.com/orvice/shadowsocks-go
cd ~/.go/src/github.com/orvice/shadowsocks-go/mu
go get
go build[/code]

如果显示:package github.com/orvice/shadowsocks-go: no buildable Go source files in /root/.go/src/github.com/orvice/shadowsocks-go 请忽略

搞个配置文件出来:

[code language=”bash”]cp example.conf ~/.go/bin/config.conf
emacs ~/.go/bin/config.conf[/code]

其中client后为webapi方式连接(根据作者文档第二选择是mysql,如果使用了webapi,不用理会sql设置)
1. url填入sspanel的url,注意不要漏掉/mu,node_id顺延,如果之前是1,那就2,3,以此类推(用于流量统计api)
2. key填入sspanel根目录下.env文件中输入的mu key,用于mu与panel的交互
sql不用理会
3. redis中host设置panel机器的ip+端口 并且用#注释掉pass”” 保存

这时候尝试Debug

[code language=”bash”]cd ~/.go/bin/
./mu -debug[/code]

如果不出所料的话连接会被拒绝,因为Redis默认只允许localhost的连接
在sspanel的机器

[code language=”bash”]netstat -nlpt | grep 6379[/code]

以后得到

[code language=”bash”]tcp 0 0 127.0.0.1:6379 0.0.0.0:* LISTEN 916/redis-server 12[/code]

编辑sspanel机器上的redis-server
emacs /etc/redis.conf
找到bind 127.0.0.1 加#注释掉
在文件后半部分找到SECURITY部分,找到requirepass,去掉注释,输入密码。
然后重启redis
service redis restart

进入ss panel主目录
cd /usr/share/nginx/html/ss-panel/
emacs .env
修改redis区域对应的密码

修改go mu的redis密码设定,重启supervisor
emacs ~/.go/bin/config.conf
supervisorctl reload

回到新节点的机器,添加相应的密码字段

折腾了一个小时 发现redis如果设置了密码,ss mu一定报错(BUG?也有可能是引号的锅),如果不设置密码,用redis限定访问的ip,但是发现了和Stackoverflow上一样的问题:
Redis bind to more than one IP

按官方文档说明 应该是可以bind ip1 ip2的,但是本机的3.2版本不行(应该是socket 同端口监听的问题?)
当你尝试搜索redis如何指定ip的时候,会发现不知道哪个缺德的傻逼程序员让你直接注释掉bind,又不设置密码,等于整个密码库在公网上裸X(呵呵)

那么唯一的路就是用iptables来实现允许指定ip通过特定端口访问:

[code language=”bash”]iptables -I INPUT -s 45.XX.X.XXX -p tcp –dport 6379 -j ACCEPT
service iptables save
service iptables restart[/code]

然后修改redis配置

[code language=”bash”]emacs /etc/redis.conf[/code]

#注释掉bind字段,将protected-mode 由yes 改成 no ,(这是因为redis对无任何安全保护的情况下默认限制不可被其他服务器访问)

[code language=”bash”]service redis restart[/code]

然后在新节点机器上尝试debug

[code language=”bash”]cd ~/.go/bin/
./mu -debug[/code]

没有问题的话 安装supervisor,使mu后台运行

[code language=”bash”]yum install supervisor
emacs /etc/supervisord.conf[/code]

在尾部添加

[code language=”bash”][program:ssserver]
command = /root/.go/bin/mu
directory = /root/.go/bin/
user = root
autostart = true
autorestart = true
stdout_logfile = /var/log/supervisor/ssserver.log
stderr_logfile = /var/log/supervisor/ssserver_err.log[/code]

启动服务:

[code language=”bash”]service supervisord start[/code]

重启:

[code language=”bash”]supervisorctl reload
[/code]

开机启动:

[code language=”bash”]systemctl enable supervisord
[/code]

最后一步 返回SS面板 添加节点 完工~

至于firewall/iptables请自行修改

References:

https://sspanel.xyz/docs/intro/config
http://bitzhi.com/2016/03/install-ss-go-mu-and-ss-panel-v3
http://stackoverflow.com/questions/8537254/redis-connect-to-remote-server
http://blog.csdn.net/zyz511919766/article/details/42268219
http://blog.csdn.net/kinginblue/article/details/51619445
http://stackoverflow.com/questions/16120287/redis-bind-to-more-than-one-ip
http://longkm.blog.163.com/blog/static/116662640201661532321338/

Donations are welcome & appreciated :  1FGb7uZoLUixERf2e9fQPHsiTGGwhz3kW5

Leave a Reply

Your email address will not be published. Required fields are marked *