Limitar ancho de banda con PrometheusQOS

Imagen de RazaMetaL

Tema: 

En mi búsqueda de una aplicación que me permita limitar anchos de banda por direcciones IP llegué hasta [url=http://www.arachne.cz/index.php?clanekid=231]PrometheusQoS[/url].

[quote]
Prometheus QoS (Quality of Service) is an ISP-oriented tool for easy manipulation of the IP traffic shaping and sharing features of the Linux kernel. It generates multiple nested HTB traffic control classes with fine-grained rate and ceiling values and implements optional daily (or simply periodical) data transfer quotas and data transfer statistics (as HTML). It is compatible with NAT (both asymmetric and symmetric), yet still provides good two-way shaping and prioritizing for both uploads and downloads.
[/quote]

Mis requerimientos son:
- Limitar anchos de banda por direcciones IP;
- Limitar anchos de banda por grupos de direcciones IP;
- Que sea fácil de administrar, esto porque quien va a administrar el servicio no voy a ser yo :)

Voy a describir como instalar y configurar PrometheusQoS para administrar los anchos de banda para los usuarios de mi red interna.

[b]Requisitos:[/b]
- Kernel 2.6 con soporte HTB y SFQ habilitados;

cat /boot/config-`uname -r` | grep CONFIG_NET_SCH_HTB && cat /boot/config-`uname -r` | grep CONFIG_NET_SCH_SFQ
CONFIG_NET_SCH_HTB=m
CONFIG_NET_SCH_SFQ=m

- Debian GNU/Linux, aunque se puede instalar prometheus en cualquier otra distro, si alguien lo hace que me avise para actualizar este manual ;)
- La instalación se hará como usuario root;

[b]Instalación:[/b]
Descargamos PrometheusQoS:

cd /usr/src/
wget http://www.arachne.cz/download/prometheus-0.7.8.tar.gz

Creamos un paquete deb y lo instalamos:

aptitude -y install debhelper build-essential debian-builder
cd /usr/src/
tar zvxf prometheus-0.7.8.tar.gz
cd prometheus-0.7.8
make deb
dpkg -i prometheus_0.7.8-1_i386.deb

[b]Configuración:[/b]
La configuración la podemos encontrar en /etc/prometheus y consta de dos archivos:

/etc/prometheus/prometheus.conf
/etc/prometheus/hosts

El primero va a contener los "planes" que vamos a ofrecer a los usuarios y el segundo especifica a que plan pertenece cada uno.

Supongamos que vamos a tener dos tipos de "planes":

- 1024kbps compartido entre 2 usuarios, con un mínimo de 512kbps y máximo de 1024kbps
- 512kbps compartido entre 8 usuarios, con un mínimo de 64kbps y máximo de 512kbps

Nuestros archivos de configuración ser verían así:
/etc/prometheus/prometheus.conf

#==========================================================================
#
# Prometheus QoS - steal fire from your ISP !
# "fair-per-IP" quality of service utility
# requires Linux kernel with HTB qdisc enabled
# GNUpyright(G)2007 Michael xChaos Polak, x@n.cz
# Credits: CZFree.Net / Freegate / Deu / d@n.cz
# ...and Martin Devera for his HTB, of course ;-)
#
#==========================================================================
#Path to external utilities required to run iGW Prometheus:
#--------------------------------------------------------------------------
tc /sbin/tc
iptables /sbin/iptables
iptables-restore /sbin/iptables-restore
#==========================================================================
#Filename of iptables mangle table for iptables-restore
#--------------------------------------------------------------------------
iptables-file /var/spool/prometheus.iptables
#==========================================================================
#Filename of /etc/hosts - style IP address configuration file
#--------------------------------------------------------------------------
hosts /etc/prometheus/hosts
#==========================================================================
#Keywords found in /etc/host comments - syntax KEYWORD-MIN-MAX
#Eg.: 192.168.1.2 mypc #internet-256-512
#sets HTB rate for 192.168.1.2 to 256 kbps and HTB ceil to 512 kbps
#--------------------------------------------------------------------------
keyword internet512-8a1
keyword internet1024-2a1

#==========================================================================
#LAN (local, downstream) and WN (isp, internet, upstream) interface names
#didn't work well with only one interface - two interfaces are required now
#--------------------------------------------------------------------------
lan-interface eth1 #Linux network interface name
wan-interface eth0 #Linux network interface name
#==========================================================================
#LAN and WAN medium definition (100Mbit, 10Mbit - use 2Mbit for Wi-Fi)
#--------------------------------------------------------------------------
lan-medium 100Mbit #Mbit|kbit
wan-medium 100Mbit #Mbit|kbit
#==========================================================================
#guranted upload and download bandwidth FROM your ISP (in kbps, please!)
#asymetry settings will be automaticaly calculated from these values
#--------------------------------------------------------------------------
wan-download 2048 #kbps
wan-upload 2048 #kbps
#==========================================================================
#special QoS free zone (eg. free CZFree tranzit, etc.)
#Apply QoS on HTTP proxy IP addres/port
#Set HTB rate and HTB ceil for address undefined in hosts file
#--------------------------------------------------------------------------
qos-free-zone 0 #0=disable|subnet eg. 192.168.0.0/16
qos-free-delay 14400 #seconds to wait before applying QoS
qos-proxy-enable 1 #1=yes|0=no
qos-proxy-ip 192.168.0.1/32 #eg. IP of our LAN interface
qos-proxy-port 3128 #squid port
free-rate 64 #kbps - by Vitex kuli testovani dashboardu
free-ceil 128 #kbps
digital-divide-weirdness-ratio 1 #can be 1, 2, 3, maybe even more...
#==========================================================================
#Asymetric line settings - this allows setup of ADSL-style ISP service
#asymetry-rate 2 means upload is limited to 50% of the rate of download
#asymetry-treshold 64 means upload will be 64 kbps slower then download
#--------------------------------------------------------------------------
#These settings are keyword-derived ! (see "keyword" section)
#--------------------------------------------------------------------------
internet512-8a1-asymetry-ratio 1 #2,4,etc. for relative upload shaping
internet512-8a1-asymetry-treshold 0 #kbps
internet1024-8a1-asymetry-ratio 2
internet1024-8a1-asymetry-treshold 0
#==========================================================================
#HTB fine tuning part I - common settings
#--------------------------------------------------------------------------
htb-nesting-limit 3 #0..4: HTB seems to have built-in limit
htb-burst 8 #kbit (ip level classes)
htb-burst-group 32 #kbit (group level classes)
htb-burst-main 64 #kbit (medium&line level classes - 1:1, 1:2)
htb-leaf-discipline sfq perturb 5 #maybe "none"
htb-r2q 1
#type filtering traffic: mark&filter or classify (without tc filter)
filter-type classify #or mark
#==========================================================================
#magic-include-upload - is data counter sum of upload and download ?
#magic-treshold - heaviest downloader: htb-rate, 2nd: htb-rate+magic-treshold
#==========================================================================
magic-include-upload 1 #1=yes|0=no
magic-treshold 2 #kbps
#--------------------------------------------------------------------------
#Magic data limit based od guaranted bandwidth in kbps fine tunes HTB ceil:
#(magic-relative-limit)*(min bandwidth kbps) = limit for given time period
#eg. value 8 gives 512 MB limit to 64 kbps HTB rates, 1024 MB to 128'ers...
#magic-fixed-limit is fixed data limit in MB (megabytes), 0=no limit
#HTB ceil will be reduced to (HTB rate) for the most unfair-users
#other offenders get (HTB rate)+(magic-treshold)
#magic-relative-prio and magic-fixed-prio work exactly the same way as
#limit, except that they reduce HTB priority instead of HTB ceil
#--------------------------------------------------------------------------
#These settings are keyword-derived ! (see "keyword" section)
#--------------------------------------------------------------------------
internet512-8a1-magic-relative-limit 8 #*kb/sec->MB/day
internet512-8a1-magic-relative-prio 6 #*kb/sec->MB/day
internet512-8a1-magic-fixed-limit 0 #MB, less then
internet512-8a1-magic-fixed-prio 0 #MB, less then
internet1024-2a1-magic-relative-limit 12
internet1024-2a1-magic-relative-prio 8
internet1024-2a1-magic-fixed-limit 0
internet1024-2a1-magic-fixed-prio 0
#==========================================================================
#HTB fine tuning part II - keyword dependent settings
#--------------------------------------------------------------------------
#These settings are keyword-derived ! (see "keyword" section)
#--------------------------------------------------------------------------
internet512-8a1-htb-default-prio 1 #can be 1...7
internet512-8a1-htb-rate-bonus 0 #kbps
internet512-8a1-htb-ceil-malus 0 #kbps
internet1024-2a1-htb-default-prio 1
internet1024-2a1-htb-rate-bonus 16
internet1024-2a1-htb-ceil-malus 0
#==========================================================================
#HTB fine tuning part III - keyword dependent settings
#--------------------------------------------------------------------------
#These settings are keyword-derived ! (see "keyword" section)
# optionally! if not defined, using global leaf-discipline
# value "none" skip qdisc creation for this keyword
#--------------------------------------------------------------------------
#internet512-8a1-leaf-leaf-discipline esfq
#internet1024-2a1-leaf-discipline none
#==========================================================================
#Credit file settings - stores unused credit from previous runs
#--------------------------------------------------------------------------
credit-filename /var/lib/misc/prometheus.credit
credit-enable 1 #1=yes|0=no
#==========================================================================
#Log file names and directories
#--------------------------------------------------------------------------
log-filename /var/log/prometheuslog
log-traffic-directory /var/www/logs/
log-traffic-html-directory /var/www/logs/html/
log-traffic-url-path logs/
#==========================================================================
#Hall of Fame - Greatest Suckers settings
#--------------------------------------------------------------------------
hall-of-fame-enable 1 #1=yes|0=no
hall-of-fame-filename /var/www/yesterday.html
hall-of-fame-preview /var/www/today.html
hall-of-fame-title Hall of Fame - Greatest Suckers
#==========================================================================
#Hall of Fame - Color settings (for FUP data limit display)
#--------------------------------------------------------------------------
#These settings are keyword-derived ! (see "keyword" section)
#--------------------------------------------------------------------------
internet512-8a1-html-color 008000
internet1024-2a1-html-color 000080
#==========================================================================
#That's all, folks. Now just run /usr/sbin/prometheus every day...

Como podrán apreciar, en el archivo de configuración hemos definido los nombres de los planes que vamos a ofrecer:

internet512-8a1
internet1024-2a1

Entre otras cosas también se ha especificado:

wan-download Ancho de banda de bajada que tenemos disponible para distribuir
wan-upload Ancho de banda de subida que tenemos disponible para distribuir
lan-interface Interfaz LAN, generalmente eth1
wan-interface Interfaz WAN, generalmetne eth0
lan-medium Velocidad de la tarjeta de red LAN (10Mbit, 100Mbit, etc)
wan-medium Velocidad de la tarjeta de red WAN (10Mbit, 100Mbit, etc)

Ahora debemos definir cuales son los usuarios que van a estar en cada plan:
/etc/prometheus/hosts

# use TABs to separate IP address, hostname, and speed definition!
# this file is just dummy example not related to prometheus.conf.SAMPLE
# see sample-configuration/hosts to learn more about what Prometheus QoS can handle

# syntax: "via-prometheus-MIN-MAX", where MIN and MAX are values in kbps
# "sharing-HOSTNAME" is useful to aggregate more IPs in single traffic class

# note, that keywords parsed by Prometheus QoS look like ordinary comments to tools
# used to process bsd-style /etc/hosts file...

192.168.0.0 redclientes #(solo informacion - nombre de la red)
192.168.0.1 linux #(solo informacion - interfaz interna del linux)
192.168.0.2 pcmonitoreo #sharing-linux
192.168.0.3 pcrazametal #sharing-linux

# Clientes plan 512kbps
# En ancho de banda mínimo cuando todos esten conectados será de 64kbps
# y el máximo de 512kbps
192.168.0.101 cliente1 #internet512-8a1-64-512
192.168.0.102 cliente2 #sharing-cliente1
192.168.0.103 cliente3 #sharing-cliente1
192.168.0.104 cliente4 #sharing-cliente1
192.168.0.105 cliente5 #sharing-cliente1
192.168.0.106 cliente6 #sharing-cliente1
192.168.0.107 cliente7 #sharing-cliente1
192.168.0.108 cliente8 #sharing-cliente1

# Clientes plan 1024kbps
# En ancho de banda mínimo cuando todos esten conectados será de 512kbps
# y el máximo de 1024kbps
192.168.0.201 cliente9 #internet1024-2a1-512-1024
192.168.0.202 cliente10 #sharing-cliente9

Habilitamos el arranque de PromethusQoS y nuestras configuración cuando reiniciemos el servidor:
vi /etc/default/prometheus

# Run prometheus on startup
PROMETHEUS_ENABLE=yes

Iniciamos prometheus:

/etc/init.d/prometheus start

Prometheus nos mostrará los clientes y a que plan estan asociados:

Prometheus QoS - "fair-per-IP" Quality of Service setup utility.
Version 0.7.8 - Copyright (C)2005-2008 Michael Polak (xChaos)
iptables-restore & burst tunning & classify modification 0.7d by Ludva
Credit: CZFree.Net, Martin Devera, Netdave, Aquarius, Gandalf

Parsing configuration file /etc/prometheus/prometheus.conf ...
Configured keywords: via-prometheus internet512-8a1 internet1024-2a1
Parsing iptables verbose output ...
Parsing class defintion file /etc/prometheus/hosts ...
Resolving shared connections ...
Unresolved shared connection: 192.168.0.3 pcrazametal sharing-linux
Unresolved shared connection: 192.168.0.2 pcmonitoreo sharing-linux
Parsing credit file /var/lib/misc/prometheus.credit ...
Initializing iptables and tc classes ...
Running /sbin/iptables-restore

[b]Para tener en cuenta:[/b]
La unidad utilizada en /etc/prometheus/prometheus.conf es el kilobit y no el kilobyte (1 byte = 8 bits).
El archivo /etc/prometheus/hosts utiliza espacios de tabulador entre la dirección IP, nombre de cliente y plan.
Podemos utlizar prometheus -p para obtener una top10 de consumo de cada cliente.

Comentarios

Prometheus solo limita el

Imagen de RazaMetaL

Prometheus solo limita el ancho de banda que consumirá el cliente. La navegación se la tienes que dar con squid ó iptables.

-----

Visita este [url=http://www.sindominio.net/ayuda/preguntas-inteligentes.html]link[/url] :evil:

[img]http://www.bbspot.com/Images/News_Features/2003/01/os_quiz/debian.jpg[/img]

(adsbygoogle = window.adsbygoogle || []).push({});

Primero gracias x compartir

Imagen de falcom

Primero gracias x compartir Raza, lo instale en un centos 5.3 y funciona perfectamente... ahora una consulta segun vi q podemos sacar el top de consumo de los users en reportes con estas lineas..

#==========================================================================
#Log file names and directories
#--------------------------------------------------------------------------
log-filename /var/log/prometheuslog
log-traffic-directory /var/www/logs/
log-traffic-html-directory /var/www/logs/html/
log-traffic-url-path logs/
#==========================================================================
#Hall of Fame - Greatest Suckers settings
#--------------------------------------------------------------------------
hall-of-fame-enable 1 #1=yes|0=no
hall-of-fame-filename /var/www/yesterday.html
hall-of-fame-preview /var/www/today.html
hall-of-fame-title Hall of Fame - Greatest Suckers
#==========================================================================

el cual muestra correctamente los mayores consumidores.. la pregunta es si hay una forma de testear si en verdad esta marcando los paquetes de un usuario "x" y mostrarlo no se si me explico x ejemplo con htb-gen se hace:

iptables -L -t mangle -vxn | grep 192.168.0.15

o hay un comando para probarlo si funciona en una interfaz ???
Otra inquietud hice planes asi:

internet2048-151a1

es decir comparti 2 Mb entre 151 users con un rate de 12 Kbps

free-rate 12

se puede hacer esto ??
Thnx

Cita: el cual muestra

Imagen de RazaMetaL

[quote]
el cual muestra correctamente los mayores consumidores.. la pregunta es si hay una forma de testear si en verdad esta marcando los paquetes de un usuario "x" y mostrarlo no se si me explico x ejemplo con htb-gen se hace:
iptables -L -t mangle -vxn | grep 192.168.0.15[/quote]

Ese comando debe funcionar. Para saber el ancho de banda que consume cada usuario yo utilizo jnetto/iftop :

aptitude install jnettop iftop

Luego:

jnettop -b -i eth1 -x "host 192.168.0.15"

[quote]
Otra inquietud hice planes asi:
internet2048-151a1

es decir comparti 2 Mb entre 151 users con un rate de 12 Kbps
free-rate 12
[/quote]

Lée el archivo de configuración prometheus.conf. El free-rate es utilizado para otra cosa.

Si quieres compartir 2Mbps entre 151 usuarios debes sacar cuanto va a ser el ancho de banda mínimo que vas a destinar a cada usuario, esto lo haces dividiendo 2048kbps/151=14kbps. La línea en el archivo host debería quedar:


192.168.0.15 usuario #keyword-14-2048
192.168.0.16 usuario2 #sharing-usuario
192.168.0.151 usuario151 #sharing-usuario

El keyword lo defines en /etc/prometheus/prometheus.conf . Cuando todos los 151 usuarios esten conectados, cada uno va a tener 14kbps, si solo uno esta conectado va a tener 2048kbps.

-----

Visita este [url=http://www.sindominio.net/ayuda/preguntas-inteligentes.html]link[/url] :evil:

[img]http://www.bbspot.com/Images/News_Features/2003/01/os_quiz/debian.jpg[/img]

(adsbygoogle = window.adsbygoogle || []).push({});

¿Con que herramienta hacen el

Imagen de Freestate

¿Con que herramienta hacen el test de velocidad?

Raza.. tampoco entiendo como en el archivo host defines que ips pertenecen a que plan.


# Clientes plan 512kbps
# En ancho de banda mínimo cuando todos esten conectados será de 64kbps
# y el máximo de 512kbps
192.168.0.101 cliente1 #internet512-8a1-64-512
192.168.0.102 cliente2 #sharing-cliente1
192.168.0.103 cliente3 #sharing-cliente1
192.168.0.104 cliente4 #sharing-cliente1
192.168.0.105 cliente5 #sharing-cliente1
192.168.0.106 cliente6 #sharing-cliente1
192.168.0.107 cliente7 #sharing-cliente1
192.168.0.108 cliente8 #sharing-cliente1

# Clientes plan 1024kbps
# En ancho de banda mínimo cuando todos esten conectados será de 512kbps
# y el máximo de 1024kbps
192.168.0.201 cliente9 #internet1024-2a1-512-1024
192.168.0.202 cliente10 #sharing-cliente9

No me vayas a decir que son con los comentarios que tienen # ...

Saludos!!!

Si te fijas en el archivo

Imagen de RazaMetaL

Si te fijas en el archivo /etc/prometheus/prometheus.conf creas un keyword que va a definir las politicas de limitación, prioridades y demás.

En el archivo /etc/prometheus/hosts das a cada dirección IP un ancho de banda de la siguiente manera:


192.168.0.10 usuario #keywork-min-max

Donde 192.168.0.10 es la ip del dispositivo a limitar ancho de banda, usuario es un nombre con el cual describes a ese dispositivo y keyword-min-max es el ancho de banda que va a tener,, si en prometheus.conf definistes un keywork como internet y quieres por ejemplo asignarle la la ip 192.168.0.10 512 de ancho de banda máximo y un mínimo de 128 debería quedar la línea así:


192.168.0.10 milaptop #internet-128-512

Ahora, supongamos que quieres que otro dispositivo comparta ese canal de 128-512 de la laptop:

192.168.0.10 milaptop #internet-128-512
192.168.0.11 otralaptop #sharing-milaptop
192.168.0.12 pchermano #sharing-milaptop

Según el ejemplo, 192.168.0.11 y 192.168.0.12 compartirán el canal máximo de 512kbps que configuré en un inicio para milaptop.

Si al contrario, quires que las laptops tengan un ancho de banda compartido entre ellas, y pchermano tenga otro ancho de banda, quedaría algo así:


192.168.0.10 milaptop #internet-128-512
192.168.0.11 otralaptop #sharing-milaptop
192.168.0.12 pchermano #internet-64-64

De acuerdo a lo descrito en el ejemplo anterior, pchermano va a tener un ancho de banda mínimo de 64kbps y máximo de 64kbps.

-----

Visita este [url=http://www.sindominio.net/ayuda/preguntas-inteligentes.html]link[/url] :evil:

[img]http://www.bbspot.com/Images/News_Features/2003/01/os_quiz/debian.jpg[/img]

(adsbygoogle = window.adsbygoogle || []).push({});

Excelente, ya me quedó claro

Imagen de Freestate

Excelente, ya me quedó claro eso. Yo pensaba que en


192.168.0.10 milaptop #internet-128-512

"#internet-128-512" era un mero comentario y no afectaba en nada al script...pero ya vi que no. Gracias raza. Otra consulta yo manejo varias ips en mi proxy... puedo declararlas en en el prometheus.conf asi?:

qos-proxy-ip 192.168.0.1/32 #eg. IP of our LAN interface
qos-proxy-ip 192.168.1.1/32 #eg. IP of our LAN interface
qos-proxy-ip 192.168.2.1/32 #eg. IP of our LAN interface

Todas escuchando en el 8080.

Por otro lado alguna herramienta para medir el ancho de banda? yo hago pruebas en speedtest, speakeasy, entre otros. Pero no son de fiar... al menos desde mi ISP.

Saludos!

Cita: Otra consulta yo manejo

Imagen de RazaMetaL

[quote]Otra consulta yo manejo varias ips en mi proxy... puedo declararlas en en el prometheus.conf asi?:

qos-proxy-ip 192.168.0.1/32 #eg. IP of our LAN interface
qos-proxy-ip 192.168.1.1/32 #eg. IP of our LAN interface
qos-proxy-ip 192.168.2.1/32 #eg. IP of our LAN interface

Todas escuchando en el 8080.[/quote]

No utlizo esa opción, pruebala y nos avisas si funciona o no. Pienso que bastaría con declarar solo 1 dirección de la interfaz interna, aunque yo esa parte de la configuración la tengo con la opción free zone en disable.

Si usas un proxy transparente vas a necesitar habilitar la opción qos-proxy-enable 1 para poder limitar el puerto del proxy.


#==========================================================================
#special QoS free zone (eg. free CZFree tranzit, etc.)
#Apply QoS on HTTP proxy IP addres/port
#Set HTB rate and HTB ceil for address undefined in hosts file
#--------------------------------------------------------------------------
qos-free-zone 10.0.0.0/8 #0=disable|subnet eg. 192.168.0.0/16
qos-free-delay 14400 #seconds to wait before applying QoS
qos-proxy-enable 0 #1=yes|0=no
qos-proxy-ip 10.11.10.1/32 #eg. IP of our LAN interface
qos-proxy-port 3128 #squid port
free-rate 64 #kbps - by Vitex kuli testovani dashboardu
free-ceil 128 #kbps
digital-divide-weirdness-ratio 1 #can be 1, 2, 3, maybe even more...

-----

Visita este [url=http://www.sindominio.net/ayuda/preguntas-inteligentes.html]link[/url] :evil:

[img]http://www.bbspot.com/Images/News_Features/2003/01/os_quiz/debian.jpg[/img]

(adsbygoogle = window.adsbygoogle || []).push({});

Estimado Raza Como hago para

Imagen de nino1511

Estimado Raza

Como hago para dar prioridad a un plan o keyword, he intentado en las opciones de prioridad pero no me funciona. Ej:

Si tengo 2 planes
1) 1mega 2:1 512-1024
2) 512k 10:1 64-512

Teniendo como total de ancho de banda 1024kbit
quiero que el primero tenga mas prioridad que el otro plan

htb-default-prio
magic-relative-prio
leaf-leaf-discipline esfq (debe habilitarse o no?)

Saludos

Vamos Ecuador, si se puede

hola saludos estoy trabajando

Imagen de maxstoro

hola saludos estoy trabajando actualmente con el cbq pero estoy tratando de instalar el prometheus en centos 5 y me da un error al momento de comenzar la instalacion

hasta aqui todo bien

cd /usr/src/
tar zvxf prometheus-0.7.8.tar.gz
cd prometheus-0.7.8


mi problema es aqui al ejecutar este comando me sale


make deb
cc -std=c99 -Wall prometheus.c -o prometheus
make: cc: No se encontró el programa
make: *** [prometheus] Error 127


quisiera que me ayudaran de antemano les quedo agradecido

Páginas