-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathvzopenvztc.sh
executable file
·120 lines (103 loc) · 3.5 KB
/
vzopenvztc.sh
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#!/bin/sh
if [ -e /tools/disabletc ]; then
exit;
fi
if [ ! -e /etc/vz/conf ]; then
exit;
fi
cat <<EOF
#!/bin/sh
export PATH=/usr/local/bin:/usr/local/sbin:$PATH:/sbin
modprobe ipt_mark
modprobe ipt_MARK
modprobe ipt_MASQUERADE
modprobe ipt_helper
modprobe ipt_REDIRECT
modprobe ipt_state
modprobe ipt_TCPMSS
modprobe ipt_LOG
#modprobe ipt_SAME
modprobe ipt_TOS
modprobe iptable_nat
modprobe ipt_length
modprobe ipt_tcpmss
modprobe iptable_mangle
modprobe ipt_limit
modprobe ipt_tos
modprobe iptable_filter
modprobe ipt_helper
modprobe ipt_tos
modprobe ipt_ttl
modprobe ipt_REJECT
#modprobe sch_sfq
##modprobe em_u32
#modprobe cls_u32
#modprobe sch_cbq
##modprobe sch_prio
#eth
/sbin/tc qdisc del dev eth0 root
/sbin/tc qdisc add dev eth0 root handle 1: cbq avpkt 1000 bandwidth 200mbit
#venet
/sbin/tc qdisc del dev venet0 root
/sbin/tc qdisc add dev venet0 root handle 1: cbq avpkt 1000 bandwidth 200mbit
# vps's / changes here
EOF
nid=1;
if [ -e /etc/vz/conf ]; then
cd /etc/vz/conf
# ignore ve-vps.basic.conf
for i in `ls *.conf | grep -v ve-vps.basic.conf`; do
id=`echo $i | cut -d. -f1`;
IPs=`cat $i | grep ^IP_A | cut -d\" -f2`
BW='10mbit'
# ignore files with no ips
if [ ! "$IPs" = "" ]; then
# look for BW upgrade
if [ -e /tools/bandwidth/$id/80 ]; then
BW='80mbit'
elif [ -e /tools/bandwidth/$id/30 ]; then
BW='30mbit'
elif [ -e /tools/bandwidth/$id/40 ]; then
BW='40mbit'
elif [ -e /tools/bandwidth/$id/50 ]; then
BW='50mbit'
elif [ -e /tools/bandwidth/$id/60 ]; then
BW='60mbit'
elif [ -e /tools/bandwidth/$id/70 ]; then
BW='70mbit'
elif [ -e /tools/bandwidth/$id/20 ]; then
BW='20mbit'
elif [ -e /tools/bandwidth/$id/5 ]; then
BW='5mbit'
elif [ -e /tools/bandwidth/$id/10 ]; then
BW='10mbit'
elif [ -e /tools/bandwidth/$id/15 ]; then
BW='15mbit'
elif [ -e /tools/bandwidth/$id/25 ]; then
BW='25mbit'
# just in case nothing passed
else
BW='25mbit'
fi
for ip in $IPs; do
if [ ! -e /tools/bandwidth/$id/skip ]; then
echo "#VZID $id";
echo '#eth0 up';
echo "/sbin/tc class add dev eth0 parent 1: classid 1:$nid cbq rate $BW allot 1500 prio 5 bounded isolated";
echo "/sbin/tc filter add dev eth0 parent 1: protocol ip prio 16 u32 match ip src $ip flowid 1:$nid";
echo "/sbin/tc qdisc add dev eth0 parent 1:$nid sfq perturb 1";
nid=`expr $nid + 1`;
echo '#eth0 down';
echo "/sbin/tc class add dev venet0 parent 1: classid 1:$nid cbq rate $BW allot 1500 prio 5 bounded isolated"
#echo "/sbin/tc filter add dev venet0 parent 1: protocol ip prio 16 u32 match ip src $ip flowid 1:$nid";
echo "/sbin/tc filter add dev venet0 parent 1: protocol ip prio 16 u32 match ip dst $ip flowid 1:$nid";
echo "/sbin/tc qdisc add dev venet0 parent 1:$nid sfq perturb 10";
nid=`expr $nid + 1`;
fi
done
echo
fi
done
else
echo 'Error: /etc/vz/conf not found';
fi