自备SS梯子

2016-11-30 廖小正

撸了个Linode VPS (CentOS 7)

1. 登录VPS

wget --no-check-certificate https://raw.githubusercontent.com/teddysun/shadowsocks_install/master/shadowsocks.sh
chmod +x shadowsocks.sh
./shadowsocks.sh 2>&1 | tee shadowsocks.log    

2. 安装完成后,脚本提示如下

Congratulations, shadowsocks install completed!

Your Server IP:your_server_ip
Your Server Port:8989
Your Password:your_password
Your Local IP:127.0.0.1
Your Local Port:1080
Your Encryption Method:aes-256-cfb

Welcome to visit:http://teddysun.com/342.html
Enjoy it!   

3. 卸载方法

./shadowsocks.sh uninstall    

4. 配置文件

vi /etc/shadowsocks.json   

单用户配置:

{
	"server":"your_server_ip",
	"server_port":8989,
	"local_address":"127.0.0.1",
	"local_port":1080,
	"password":"yourpassword",
	"timeout":300,
	"method":"aes-256-cfb",
	"fast_open": false
}

多用户配置:

{
	"server":"your_server_ip",
	"local_address": "127.0.0.1",
	"local_port":1080,
	"port_password":{
     	"8989":"password0",
     	"9001":"password1",
     	"9002":"password2",
     	"9003":"password3", 
     	"9004":"password4"
	},
	"timeout":300,
	"method":"aes-256-cfb",
	"fast_open": false
}

5. 相关使用命令

/etc/init.d/shadowsocks start/stop/restart/status  

6. 防火墙设置

在centos版本的更新迭代过程中,centos7和centos6之间的差异性较大。在centos7,采用的是最新的防火墙filewall而不是传统的iptables

1. Iptables

iptables -A INPUT -p tcp –dport 443 -j ACCEPT

service iptables restart

2. firewall

firewall-cmd --zone=public --add-port=8989/tcp --permanent
firewall-cmd --reload
firewall-cmd --zone=public --list-ports
systemctl restart firewalld.service 

7. TCP优化

1. 增加tcp连接数量

vi /etc/security/limits.conf

add * soft nofile 51200
	* hard nofile 51200

开启ss服务之前,先设置一下ulimit

ulimit -n 51200

2. 调整内核参数

vi /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 = 3240000
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
#net.ipv4.tcp_congestion_control = hybla

sysctl -p