优化

显示标签为“优化”的博文。显示所有博文
显示标签为“优化”的博文。显示所有博文

2016年6月2日星期四

搬瓦工SS速度优化可行方案


Bandwagonhost搬瓦工vps属于OpenVZ架构,所以不能安装锐速来优化速度,安装netspeeder对流量的消耗是成倍的,所以要是一边做站一边ss不建议使用。

后期跟进:发现openvz优化并没有什么卵用速度还是那个样!唯一有效的方法是安装netspeederFinalSpeed,后者加速更明显

首先修复一下否则会报错,只要删除原来的sysctl并且新建一个软连接就行了。(注意,在删除前请备份/sbin/sysctl)
rm -f /sbin/sysctl
ln -s /bin/true /sbin/sysctl

有些朋友还喜欢添加net bridge相关命令在sysctl中并且得到下面的错误,
error: "net.bridge.bridge-nf-call-ip6tables" is an unknown key
error: "net.bridge.bridge-nf-call-iptables" is an unknown key
error: "net.bridge.bridge-nf-call-arptables" is an unknown key

可以运行如下命令解决,
modprobe bridge
lsmod|grep bridge

如果继续得到如下错误,
FATAL: Module bridge not found.

还是用同样的方法新建软链接来解决。(注意,在删除前请备份/sbin/modprobe)
rm -f /sbin/modprobe
ln -s /bin/true /sbin/modprobe

TCP优化

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 = 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_mem = 25600 51200 102400

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

优化以后搬瓦工ss速度明显提升,白天油管720p不卡。

2016年5月19日星期四

Centos下搭建Ss加sysctl.conf优化速度


一、安装命令:
yum install python-setuptools && easy_install pip
pip install shadowsocks

二、创建shadowsock的配置文件(多用户多端口)
vi /etc/shadowsocks.json

配置内容:
{
"server":"your_server_ip",
"local_address": "127.0.0.1",
"local_port":1080,
"port_password":{
"8383":"password0",
"8384":"password1",
"8385":"password2",
"8386":"password3",
},
"timeout":300,
"method":"aes-256-cfb",
"fast_open": false
}

三、服务端启动命令
ssserver -c /etc/shadowsocks.json

如果想在后台一直运行Shadowsocks,启动命令如下:
nohup ssserver -c /etc/shadowsocks.json > /dev/null 2>&1 &

四、优化shadowsock加速

我们通过修改 /etc/sysctl.conf 来达到调整的目的,命令:
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 = 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_mem = 25600 51200 102400
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

备注,可以让防火墙放行这些ss端口,命令如下:
vi /etc/sysconfig/iptables
-A INPUT -m state --state NEW -m tcp -p tcp --dport 8989 -j ACCEPT
service iptables restart

也可以修改下limits.conf达到TCP上限足够
* soft nofile 51200
* hard nofile 51200

然后使用一下命令让其生效:
ulimit -n 51200

至此,就可以愉快的玩耍shadowsocks啦。