跳至主要内容

linux tcp 优化

Step 1, increase the maximum number of open file descriptors

To handle thousands of concurrent TCP connections, we should increase the limit of file descriptors opened.
Edit the limits.conf
vi /etc/security/limits.conf
Add these two lines
* soft nofile 51200
* hard nofile 51200
Then, before you start the shadowsocks server, set the ulimit first
ulimit -n 51200

Step 2, Tune the kernel parameters

The priciples of tuning parameters for shadowsocks are
  1. Reuse ports and conections as soon as possible.
  2. Enlarge the queues and buffers as large as possible.
  3. Choose the TCP congestion algorithm for large latency and high throughput.
Here is an example /etc/sysctl.conf of our production servers:
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
Of course, remember to execute sysctl -p to reload the config at runtime.

评论

此博客中的热门博文

debian 禁用笔记本盒盖休眠功能

编辑 Login Manager 的配置文件( logind.conf )。 打开终端,运行下面的命令打开 logind.conf 文件。 sudo vi /etc/systemd/logind.conf 打开文件后修改下面这行: #HandleLidSwitch=suspend 改成这样: HandleLidSwitch=ignore 保存文件,重启 Login Manager 服务: sudo restart systemd-logind 工作完成!

linux 禁止控制台黑屏和休眠

通过GRUB的引导参数设置: consoleblank=0 控制台多长时间无操作后黑屏,默认值是600秒,设为0表示禁止黑屏。 no_console_suspend 永远也不要将控制台进入休眠状态。因为当控制台进入休眠之后,所有内核的消息就都看不见了(包括串口与VGA)。开启此参数有助于调试系统在休眠/唤醒中发生的故障。

obfsproxy 混淆代理

1、安装2.7以上版本python 2、pip install obfsproxy 如果顺利的话,自动安装完成。 如果失败可以在Pypi官网手动下载包,解压后运行:setup.py install 3、执行服务端命令 setsid obfsproxy --data-dir ~/.obfs/ scramblesuit --dest 127.0.0.1:8388 --password 密码 server 0.0.0.0:443 > ~/.obfs/log 2>&1 & 注:密码由32位的大写字母和数字组成 4、客户端运行 obfsproxy scramblesuit --dest X.X.X.X:443 --password 密码 client 127.0.0.1:8443 混淆代理完成。