提高 OpenVPN 性能

12 linux vpn performance openvpn performance-tuning

我一直在努力提高我的 OpenVPN 性能,这是我当前的设置:

 cat /etc/openvpn/server.conf
port 443 #- port
proto tcp #- protocol
dev tun
#tun-mtu 1500
tun-mtu-extra 32 
#mssfix 1450
tun-mtu 64800
mssfix 1440
reneg-sec 0
ca /etc/openvpn/easy-rsa/2.0/keys/ca.crt
cert /etc/openvpn/easy-rsa/2.0/keys/server.crt
key /etc/openvpn/easy-rsa/2.0/keys/server.key
dh /etc/openvpn/easy-rsa/2.0/keys/dh1024.pem
plugin /etc/openvpn/openvpn-auth-pam.so /etc/pam.d/login
#plugin /usr/share/openvpn/plugin/lib/openvpn-auth-pam.so /etc/pam.d/login #- Comment this line if you are using FreeRADIUS
#plugin /etc/openvpn/radiusplugin.so /etc/openvpn/radiusplugin.cnf #- Uncomment this line if you are using FreeRADIUS
client-to-client
client-cert-not-required
username-as-common-name
server 10.8.0.0 255.255.255.0
push "redirect-gateway def1"
push "dhcp-option DNS 8.8.8.8"
push "dhcp-option DNS 8.8.4.4"
keepalive 5 30
comp-lzo
persist-key
persist-tun
status 1194.log
verb 3
Run Code Online (Sandbox Code Playgroud)

客户:

client
dev tun
proto tcp
remote 18.4.26.8 443
resolv-retry infinite
nobind
tun-mtu 64800
tun-mtu-extra 32
mssfix 1440
persist-key
persist-tun
auth-user-pass
comp-lzo
verb 3
Run Code Online (Sandbox Code Playgroud)

我根据我在网上找到的内容对 MTU 和 MSSFIX 进行了一些更改。

我可以进行任何内核更改吗?这是一个 CentOS 6.x 盒子。我找到了一些基于 BSD 的东西,但对 Linux 没有任何作用。

我知道 TCP 比 UDP 慢,但我需要看起来像 SSL 流量才能通过网络上的防火墙。

其他想法?

PING 到我 RDP 进入的网络上的另一个客户端。

Pinging 10.8.0.6 with 32 bytes of data:
Reply from 10.8.0.6: bytes=32 time=152ms TTL=128
Reply from 10.8.0.6: bytes=32 time=565ms TTL=128
Reply from 10.8.0.6: bytes=32 time=152ms TTL=128
Reply from 10.8.0.6: bytes=32 time=782ms TTL=128

Ping statistics for 10.8.0.6:
    Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
    Minimum = 152ms, Maximum = 782ms, Average = 412ms
Run Code Online (Sandbox Code Playgroud)

有什么方法可以提高性能或降低一些 ping 吗?

编辑:设置碎片设置会有所帮助吗?

小智 15

简短回答:禁用comp-lzo

我意识到这是一篇旧帖子,但我也饱受 OpenVPN 性能不佳的困扰。我已经尝试了所有方法,调整 MTU,更改 snd 和 rcv 缓冲区,mss 钳位,应有尽有。CPU 负载可以忽略不计。

一时兴起,我禁用了压缩(comp-lzo从客户端和服务器中删除),性能提高了 2-4 倍。

因此,comp-lzo启用后我的最大性能约为 25-30 Mbit/s,没有它我达到 120 Mbit/s(我的互联网连接速度)。

服务器是Xeon E5-2650,客户端是Core i5-3320M。两者都运行 OpenVPN 2.3.10、AES-256-CBC、SHA512。我的英特尔 Chromebook 也让我的网速达到了极限。我的 Android 客户端的性能翻了一番(14 Mbit/s -> 30 Mbit/s),与 IKEv2 隧道速度相匹配。


小智 6

由于TCP-over-TCP问题,TCP将比 UDP 慢/很多/ 。基本上,TCP 依靠丢包/拥塞来识别连接参数,而您的 TCP-over-OpenVPN 连接不会遇到任何一种情况。但你说过那不是一个选择。

您还可以尝试mtu-disc自动发现连接的最佳 MTU 设置的选项。不同地方有轻微的不匹配,例如OpenVPN的MTU设置包括以太网头的大小。[ 1 ]

您的tun-mtu设置非常庞大,因为 65KB 数据包在通过 Internet 时会有很多延迟问题(IPv4 巨型数据包大小约为 9000 字节,并且主要在本地网络上工作)。尝试使用 1460 以下的东西,比如 1300,看看 MTU 是否是你的问题。

  • 谢谢,这解决了我让 postgresql 查询通过 OpenVPN 工作的问题。它在查询单个列时有效,但不适用于整个列。显然这是由默认的 MTU-Size 1500 引起的。将其设置为 1300 有帮助! (2认同)