-
Notifications
You must be signed in to change notification settings - Fork 21
DigitalOcean 搭建Shadowsocks
安装命令
# yum -y install epel-release
# yum update
# yum -y install python-setuptools supervisor
# easy_install pip
# pip install shadowsocks
执行一下命令
# vi /etc/shadowsocks.json
复制一下命令到 /etc/shadowsocks.json中(请自行修改server-portserver-port和password,其他参数不用修改)
{
"server": "0.0.0.0",
"server_port": 5080,
"local_address": "127.0.0.1",
"local_port": 1080,
"password": "123456",
"timeout": 500,
"method": "rc4-md5",
"fast_open": true
}
配置文件说明
- server:服务监听的地址,服务端可填写的0.0.0.0
- server-port:服务器端口
- local-port:本地端的端口
- local-address:本地端监听的地址
- password:用于加密的密码
- timeout:超时时间
- method:加密方式,建议rc4-md5,因为这个速度快
- fast-open:
##配置:Supervisor
配置Supervisor是为了方便管理Supervisor进程 执行如下命令:
# vi /etc/supervisord.conf
用方向键将光标调整至文件部的空行处,然后一次性复制一下的内容到下面:
[program:shadowsocks]
command=ssserver -c /etc/shadowsocks.json
autostart=true
autorestart=true
user=root
添加服务冰启动supervisord
# systemctl enable supervisord
# systemctl start supervisord
# supervisorctl reload
重启:
reboot
到这一步done:
远程登陆VPS
ssh root@ip
之后添加:https://github.com/gfwlist/gfwlist
前几天,自己搭建了一个vps,通过shadowsocks的方式,可以实现科学上网。基本的原理就是,通过shadowsocks的客户端,修改代理服务器的地址。将代理服务器的ip地址设置到远程vps的地址。并通过设置端口号,来实现vpn的功能。
这里主要讲一下shadowsock配置多用户的过程和失败的原因。
网上很多用户vps安装的linux是debian或ubuntu的,所以可以通过修改/etc/shadowsock.json文件,通过添加端口号以及密码的方法,进行多用户配置。这种配置方案,网上可以搜出很多。我这里也粘贴一下具体修改json文件的方法.示例如下:
{
"server":"my_server_ip",
"local_address": "127.0.0.1",
"local_port":1080,
"port_password": {
"8381": "foobar1",
"8382": "foobar2",
"8383": "foobar3",
"8384": "foobar4"
},
"timeout":300,
"method":"aes-256-cfb",
"fast_open": false
}
其中,port_password就是将之前的服务器端口和对应的密码结合起来。然后通过使用以下命令,就可以启动多端口多用户了。
启动:/etc/init.d/shadowsocks start
停止:/etc/init.d/shadowsocks stop
重启:/etc/init.d/shadowsocks restart
状态:/etc/init.d/shadowsocks status
你可以将之shadowsocks.json添加到开机自启动的中。具体方法如下:
修改rc.local文件,运行命令 vi /etc/rc.local,编辑rc.local文件,添加字段
ssserver -c /etc/shadowsocks.json -d start
然后重启vps就可以完成开机自启动。
重点在于下面,如果你是debian或ubuntu的用户,基本上可以忽略了。因为这样配置完之后,重启vps就能够实现多端口多用户。但是,如果你的是centos用户的话,这样肯定还是不能够多端口多用户。我们通过命令看一下各个端口的运行情况,具体命令为:netstat -antu。可以查看各个端口的运行情况。我发现我新增的端口其目的地址一直是0.0.0.0,具体如图,而且其状态一直为listen。所以,基本可以断定是端口问题。
centos默认的防火墙机制,会阻隔掉我们的多端口配置。所以,解决方法就是,将这个端口打开tcp和udp通信。这里需要说明的事,在centos版本的更新迭代过程中,centos7和centos6之间的差异性较大。在centos7,采用的是最新的防火墙filewall而不是传统的iptables。所以,为了更加合理的提供端口号解决方案,我这里提供两种方法,个人推荐第2种。
第一种:
具体操作为:iptables -A INPUT -p tcp –dport 443 -j ACCEPT。//443为示例端口,你可以改为你需要的。
然后重启防火墙:service iptables restart。这个时候我们可以再通过netstat -antu 查看一下,就会发现那个端口能够正常工作了。然后就可以科学上网啦。
第二种:
具体操作为,先进入firewalled的配置端口目录,路径为etc/firewalled/zones/。打开public.xml文件进行端口的编辑,例如 <port protocol="tcp" port="449"/> <portprotocol="udp" port="443"/>。即添加了tcp和udp的权限。
然后systemctrl firewall restart。重启防火墙,端口就添加到防火墙的白名单中啦。这个时候就能科学上网啦,同时,其他的端口如果需要通过防火墙的白名单,也都是通过这里添加。
如果没有对服务器进行优化的话,代理的速度可能不是很理想,我们可以安装以下锐速进行加速,具体如下:
rpm -ivh http://soft.91yun.org/ISO/Linux/CentOS/kernel/kernel-3.10.0-229.1.2.el7.x86_64.rpm --force
查看是否成功:
rpm -qa | grep kernel
重启:
reboot
查看当前内核:
uname -r
wget -N --no-check-certificate https://raw.githubusercontent.com/91yun/serverspeeder/master/serverspeeder-all.sh && bash serverspeeder-all.sh
可能会提示内核版本问题,选择一个最接近的版本即可
如需要卸载锐速:
chattr -i /serverspeeder/etc/apx* && /serverspeeder/bin/serverSpeeder.sh uninstall -f
https://www.digitalocean.com/community/questions/ssh-connect-to-host-port-22-operation-timed-out