How do I turn on traffic shaping in Virtuozzo?


The first thing to realize is that Virtuozzo ONLY shapes traffic that
is going outbound. This is important, because it defines which type of
traffic can be shaped, and also how classes work.


There are two traffic shaping settings that you can set. One of
them is a server-wide setting and one of them is per VE. So if you have
a 100Mbps ethernet port, you can set all of your VE’s to only be able
to use a certain portion of that.


To do this, you must have both traffic shaping and traffic
accounting turned on. You do this through /etc/sysconfig/vz and make
sure that the following lines are in there:



TRAFFIC_ACCOUNTING=”yes”

TRAFFIC_SHAPING=”yes”




If they aren’t, you can just cut and paste them in there. The next thing you will see is something like this:



BANDWIDTH=”eth0:102400 “




This tells Virtuozzo how much bandwidth you want to give in total to
all of your VE’s. If you only want to give them 10Mbps, then you would
change that to:




BANDWIDTH=”eth0:10240 “




Next up is going to be the TOTALRATE directive, in which you define the
total rate for each class. A class is a group of foreign IP’s that you
wish to control how much bandwidth can be sent out to them. The default
class is class 1, and that contains ALL IP addresses (0.0.0.0/0). You
can create other classes if you wish. So if you have a lot of people
from AOL flooding your server, you can create a class for AOL IP’s and
set it to a different rate. However, in general you’re only going to be
dealing with class 1.





The next line you should see would be:




TOTALRATE=”eth0:1:102400 “




This sets the very maximum that this rate class can push out. This is used in conjunction with the next line which is:




RATE=”eth0:1:102400 “



is sets the rate that this class of traffic is
guaranteed. So if you set this lower than the TOTALRATE, this class is
guaranteed the lower rate, but if there is space available, it can
burst up to the TOTALRATE. This will become more clear when we deal
with the VE’s and not the serverwide config. So in conclusion on part
1, here is what it may look like depending upon how much (or how
little) bandwidth the customer wants to give his customers:




## Network traffic parameters

TRAFFIC_ACCOUNTING=”yes”

TRAFFIC_SHAPING=”yes”

BANDWIDTH=”eth0:102400 “

TOTALRATE=”eth0:1:102400 “

RATE=”eth0:1:102400 “




If you change any settings in this file, be sure to restart the traffic shaping portion of Virtuozzo with:




service vz shaperrestart



Now that the server config is setup, the next
step would be to setup the shaping on each VE. This can be done through
the handy command of vzctl. Lets say that you wish to rate limit VE
101, how would you do that?



vzctl set 101 —save —rate eth0:1:10240 —ratebound yes




Lets head through this command:



—save writes the configuration change to the VE’s conf file, so that
if you need to restart it, it will come back up with these options we
are putting in


—rate eth0:1:10240 says that on eth0, class 1, this VE is
guaranteed 10240Kb/s. That is guaranteed bandwidth and will always be
there


—ratebound yes states that this VE is bound to the rate we just
set, and CANNOT burst up to the TOTALRATE we set for this class of
traffic in the system-wide configuration. If you didn’t wish to have
this, you could set “—ratebound no”.

Your rating: None