注册 登录
自由的生活_软路由 返回首页

心想事成的个人空间 https://bbs.routerclub.com/?681 [收藏] [复制] [分享] [RSS]

日志

How to enable BBR in OpenVZ

已有 349 次阅读2024-10-3 14:33 |个人分类:网络

 

缘起

以前有个贪便宜(一年 5 刀)而入手但目前在吃灰中的小鸡,当然是 OpenVZ,网络条件很差,用起来很鸡肋,后来看到 Google 的 BBR 也有能用在 OpenVZ 的案例,于是也想尝试下,看是否能将其起死回生。
LKL 大法

LKL(Linux Kernel Library) 是个有意思的东西,常见的应用场景是把整个 Linux kernel 编成一个动态库,然后用 LD_PRELOAD 环境变量将其注入到程序运行之前的环境里,强制让程序里的调用时用新编译的这个 kernel 包中的一些函数。

这样其实就已经解决了 OpenVZ 的系统不能升级 kernel 而不能使用 BBR 的问题:我可以把新的支持 BBR 的 kernel 库完全重新编一个,然后用 LD_PRELOAD 注入嘛,完美!

具体命令

现在开始贴命令,大段的命令,重要的地方我大概会写点注释

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# suppose you are in your home dir: /home/zhangsan
wget https://github.com/lkl/linux/archive/master.zip
unzip master.zip
cd linux-master
make -C tools/lkl

sudo su -
# act as root blow
mkdir haproxy
apt-get install haproxy
systemctl stop haproxy
systemctl disable haproxy
cd haproxy
cp \
/home/zhangsan/linux-master/tools/lkl/lib/hijack/liblkl-hijack.so \
.
strip liblkl-hijack.so

# lkl hijack configuration file below
(
cat <<'EOF'
{
"gateway":"10.0.0.1",
"debug":"1",
"singlecpu":"1",
"sysctl":"net.ipv4.tcp_wmem=4096 65536 67108864",
"sysctl":"net.ipv4.tcp_congestion_control=bbr",
"interfaces":[
{
"type":"tap",
"param":"tap0",
"ip":"10.0.0.2",
"masklen":"24",
"ifgateway":"10.0.0.1",
"offload":"0x8883",
"qdisc":"root|fq"
}
]
}
EOF

) > lkl-hijack.json

# haproxy configration file below
(
cat <<'EOF'
global
user haproxy
group haproxy

defaults
mode tcp
timeout connect 5s
timeout client 60s
timeout server 60s
listen shadowsocks
bind 10.0.0.2:443
server server1 10.0.0.1:11402

EOF
) > haproxy.cfg

# create start(restart) script file below
(
cat <<'EOF'
#!/bin/bash

killall -9 haproxy
sleep 5

ip tuntap del tap0 mode tap
ip tuntap add tap0 mode tap
ip addr add 10.0.0.1/24 dev tap0
ip link set tap0 up

sysctl -w net.ipv4.ip_forward=1

iptables -P FORWARD ACCEPT
iptables -t nat -D PREROUTING \
-i venet0 -p tcp --dport 443 \
-j DNAT --to-destination 10.0.0.2
iptables -t nat -A PREROUTING \
-i venet0 -p tcp --dport 443 \
-j DNAT --to-destination 10.0.0.2
iptables -t nat -D PREROUTING \
-i venet0 -p udp --dport 443 \
-j REDIRECT --to-port 11402
iptables -t nat -A PREROUTING \
-i venet0 -p udp --dport 443 \
-j REDIRECT --to-port 11402

export LD_PRELOAD=/root/haproxy/liblkl-hijack.so
haproxy -f /root/haproxy/haproxy.cfg
EOF
) > start_haproxy_lkl.sh

其他

本文只提到怎样在 OpenVZ 的虚拟机中启用 BBR,但实际上看上面的配置,应该知道系统里还有个服务,跑在 11402 端口的。这个服务的情况不在本文的内容范畴,所以没有细写。


路过

雷人

握手

鲜花

鸡蛋

评论 (0 个评论)

facelist doodle 涂鸦板

您需要登录后才可以评论 登录 | 注册

QQ|Archiver|手机版|小黑屋|软路由 ( 渝ICP备15001194号-1|渝公网安备 50011602500124号 )

GMT+8, 2025-2-5 22:51 , Processed in 0.051951 second(s), 17 queries , Gzip On, Redis On.

Powered by Discuz! X3.5 Licensed

© 2001-2025 Discuz! Team.

返回顶部