|
|
Re: How to limit traffic per vps? [message #31453 is a reply to message #31363] |
Tue, 01 July 2008 00:23 |
swindmill
Messages: 57 Registered: April 2007
|
Member |
|
|
Try something like this:
#!/bin/bash
IFSPEED="100mbit"
SPEEDLIMIT="512kbit"
SHAPEIPS=`echo 192.168.1.{10..20}`
STARTSHAPECLASS=10
addtc()
{
tc qdisc del dev $DEV root
tc qdisc add dev $DEV root handle 1: htb
tc class add dev $DEV parent 1: classid 1:1 htb rate "$IFSPEED" burst 15k quantum 60000
SHAPECLASS=$STARTSHAPECLASS
for IP in `echo "$SHAPEIPS"`
do
tc class add dev $DEV parent 1:1 classid 1:"$SHAPECLASS" htb rate "$SPEEDLIMIT" quantum 3000
SHAPECLASS=$(($SHAPECLASS+1))
done
SHAPECLASS=$STARTSHAPECLASS
for IP in `echo "$SHAPEIPS"`
do
tc filter add dev $DEV protocol ip parent 1:1 prio 1 u32 match ip $1 "$IP" flowid 1:"$SHAPECLASS"
SHAPECLASS=$(($SHAPECLASS+1))
done
}
DEV="eth0"
addtc src
DEV="venet0"
addtc dst
This will limit each VE IP address in the range of 192.168.1.10 through 192.168.1.20 to 512kbit/sec in and out. I didn't actually test this but it does seem to produce valid commands and should serve your needs.
The commands this example executes are:
tc qdisc del dev eth0 root
tc qdisc add dev eth0 root handle 1: htb
tc class add dev eth0 parent 1: classid 1:1 htb rate 100mbit burst 15k quantum 60000
tc class add dev eth0 parent 1:1 classid 1:10 htb rate 512kbit quantum 3000
tc class add dev eth0 parent 1:1 classid 1:11 htb rate 512kbit quantum 3000
tc class add dev eth0 parent 1:1 classid 1:12 htb rate 512kbit quantum 3000
tc class add dev eth0 parent 1:1 classid 1:13 htb rate 512kbit quantum 3000
tc class add dev eth0 parent 1:1 classid 1:14 htb rate 512kbit quantum 3000
tc class add dev eth0 parent 1:1 classid 1:15 htb rate 512kbit quantum 3000
tc class add dev eth0 parent 1:1 classid 1:16 htb rate 512kbit quantum 3000
tc class add dev eth0 parent 1:1 classid 1:17 htb rate 512kbit quantum 3000
tc class add dev eth0 parent 1:1 classid 1:18 htb rate 512kbit quantum 3000
tc class add dev eth0 parent 1:1 classid 1:19 htb rate 512kbit quantum 3000
tc class add dev eth0 parent 1:1 classid 1:20 htb rate 512kbit quantum 3000
tc filter add dev eth0 protocol ip parent 1:1 prio 1 u32 match ip src 192.168.1.10 flowid 1:10
tc filter add dev eth0 protocol ip parent 1:1 prio 1 u32 match ip src 192.168.1.11 flowid 1:11
tc filter add dev eth0 protocol ip parent 1:1 prio 1 u32 match ip src 192.168.1.12 flowid 1:12
tc filter add dev eth0 protocol ip parent 1:1 prio 1 u32 match ip src 192.168.1.13 flowid 1:13
tc filter add dev eth0 protocol ip parent 1:1 prio 1 u32 match ip src 192.168.1.14 flowid 1:14
tc filter add dev eth0 protocol ip parent 1:1 prio 1 u32 match ip src 192.168.1.15 flowid 1:15
tc filter add dev eth0 protocol ip parent 1:1 prio 1 u32 match ip src 192.168.1.16 flowid 1:16
tc filter add dev eth0 protocol ip parent 1:1 prio 1 u32 match ip src 192.168.1.17 flowid 1:17
tc filter add dev eth0 protocol ip parent 1:1 prio 1 u32 match ip src 192.168.1.18 flowid 1:18
tc filter add dev eth0 protocol ip parent 1:1 prio 1 u32 match ip src 192.168.1.19 flowid 1:19
tc filter add dev eth0 protocol ip parent 1:1 prio 1 u32 match ip src 192.168.1.20 flowid 1:20
tc qdisc del dev venet0 root
tc qdisc add dev venet0 root handle 1: htb
tc class add dev venet0 parent 1: classid 1:1 htb rate 100mbit burst 15k quantum 60000
tc class add dev venet0 parent 1:1 classid 1:10 htb rate 512kbit quantum 3000
tc class add dev venet0 parent 1:1 classid 1:11 htb rate 512kbit quantum 3000
tc class add dev venet0 parent 1:1 classid 1:12 htb rate 512kbit quantum 3000
tc class add dev venet0 parent 1:1 classid 1:13 htb rate 512kbit quantum 3000
tc class add dev venet0 parent 1:1 classid 1:14 htb rate 512kbit quantum 3000
tc class add dev venet0 parent 1:1 classid 1:15 htb rate 512kbit quantum 3000
tc class add dev venet0 parent 1:1 classid 1:16 htb rate 512kbit quantum 3000
tc class add dev venet0 parent 1:1 classid 1:17 htb rate 512kbit quantum 3000
tc class add dev venet0 parent 1:1 classid 1:18 htb rate 512kbit quantum 3000
tc class add dev venet0 parent 1:1 classid 1:19 htb rate 512kbit quantum 3000
tc class add dev venet0 parent 1:1 classid 1:20 htb rate 512kbit quantum 3000
tc filter add dev venet0 protocol ip parent 1:1 prio 1 u32 match ip dst 192.168.1.10 flowid 1:10
tc filter add dev venet0 protocol ip parent 1:1 prio 1 u32 match ip dst 192.168.1.11 flowid 1:11
tc filter add dev venet0 protocol ip parent 1:1 prio 1 u32 match ip dst 192.168.1.12 flowid 1:12
tc filter add dev venet0 protocol ip parent 1:1 prio 1 u32 match ip dst 192.168.1.13 flowid 1:13
tc filter add dev venet0 protocol ip parent 1:1 prio 1 u32 match ip dst 192.168.1.14 flowid 1:14
tc filter add dev venet0 protocol ip parent 1:1 prio 1 u32 match ip dst 192.168.1.15 flowid 1:15
tc filter add dev venet0 protocol ip parent 1:1 prio 1 u32 match ip dst 192.168.1.16 flowid 1:16
tc filter add dev venet0 protocol ip parent 1:1 prio 1 u32 match ip dst 192.168.1.17 flowid 1:17
tc filter add dev venet0 protocol ip parent 1:1 prio 1 u32 match ip dst 192.168.1.18 flowid 1:18
tc filter add dev venet0 protocol ip parent 1:1 prio 1 u32 match ip dst 192.168.1.19 flowid 1:19
tc filter add dev venet0 protocol ip parent 1:1 prio 1 u32 match ip dst 192.168.1.20 flowid 1:20
[Updated on: Tue, 01 July 2008 02:56] Report message to a moderator
|
|
|
|
|
|
|
Re: How to limit traffic per vps? [message #31651 is a reply to message #31580] |
Fri, 04 July 2008 14:01 |
|
silentninja
Messages: 37 Registered: September 2007
|
Member |
|
|
This is my script.
- Modification: I've added an if so if the vps has 768 ram, It gets a 256kbit limit and if the vps has a higher limit 512kbit limit.
- Modification: The SHAPEIPS gets filled with the IP's on the vz conf files automatically.
- Modification: I've changed the total ammount of the webserver to 4mbit since I cannot afford 100mbit like your example and even if all 8 vps has 512kbit limit, it should never go further the 4mbits.
This is my script:
#!/bin/bash
IFSPEED="4mbit"
SHAPEIPS=`grep IP_ADDRESS /etc/vz/conf/* | cut -d\" -f2 | sed 's/ /\n/'`
STARTSHAPECLASS=10
addtc()
{
tc qdisc del dev $DEV root
tc qdisc add dev $DEV root handle 1: htb
tc class add dev $DEV parent 1: classid 1:1 htb rate "$IFSPEED" burst 15k quantum 60000
SHAPECLASS=$STARTSHAPECLASS
for IP in `echo "$SHAPEIPS"`
do
if [ `grep "IP_ADDR" /etc/vz/conf/* | grep "$IP" | cut -d: -f1 | xargs -iFILE grep VMGUAR FILE | grep -c 768` -eq 1 ]; then SPEEDLIMIT="256kbit"; else SPEEDLIMIT="512kbit"; fi;
tc class add dev $DEV parent 1:1 classid 1:"$SHAPECLASS" htb rate "$SPEEDLIMIT" quantum 3000
SHAPECLASS=$(($SHAPECLASS+1))
done
SHAPECLASS=$STARTSHAPECLASS
for IP in `echo "$SHAPEIPS"`
do
tc filter add dev $DEV protocol ip parent 1:1 prio 1 u32 match ip $1 "$IP" flowid 1:"$SHAPECLASS"
SHAPECLASS=$(($SHAPECLASS+1))
done
}
# Trafico saliente
DEV="eth0"
addtc src
# Trafico entrante
DEV="venet0"
addtc dst
[Updated on: Fri, 04 July 2008 14:02] Report message to a moderator
|
|
|
|
|