How can I do traffic shaping in Linux by IP?
The traffic shaping layer of the kernel is, basically, a packet scheduler attached to your network card. So one traffic shaping policy applies to one network card.
What you can do, in your case, is to create a list of IP and bandwidth attached, and then, for each IP, you create:
- One traffic shaping rule identified by a classid
- One netfilter rule that will mark packets to a specific mark value
- One Filter that will bind that packets marks to the classid, thus applying the traffic control rule to the specified packets.
The example given by @Zoredache works, but I personnally prefer to use Netfilter capability instead of TC to filter packets, and HTB instead of CBQ for the shapping algorithm. So you can try something like this (requires Bash 4 for associative arrays):
#! /bin/bash
NETCARD=eth0
MAXBANDWIDTH=100000
# reinit
tc qdisc del dev $NETCARD root handle 1
tc qdisc add dev $NETCARD root handle 1: htb default 9999
# create the default class
tc class add dev $NETCARD parent 1:0 classid 1:9999 htb rate $(( $MAXBANDWIDTH ))kbit ceil $(( $MAXBANDWIDTH ))kbit burst 5k prio 9999
# control bandwidth per IP
declare -A ipctrl
# define list of IP and bandwidth (in kilo bits per seconds) below
ipctrl[192.168.1.1]="256"
ipctrl[192.168.1.2]="128"
ipctrl[192.168.1.3]="512"
ipctrl[192.168.1.4]="32"
mark=0
for ip in "${!ipctrl[@]}"
do
mark=$(( mark + 1 ))
bandwidth=${ipctrl[$ip]}
# traffic shaping rule
tc class add dev $NETCARD parent 1:0 classid 1:$mark htb rate $(( $bandwidth ))kbit ceil $(( $bandwidth ))kbit burst 5k prio $mark
# netfilter packet marking rule
iptables -t mangle -A INPUT -i $NETCARD -s $ip -j CONNMARK --set-mark $mark
# filter that bind the two
tc filter add dev $NETCARD parent 1:0 protocol ip prio $mark handle $mark fw flowid 1:$mark
echo "IP $ip is attached to mark $mark and limited to $bandwidth kbps"
done
#propagate netfilter marks on connections
iptables -t mangle -A POSTROUTING -j CONNMARK --restore-mark
#!/bin/bash set -x DEV=eth0 export DEV tc qdisc del dev $DEV root tc qdisc del dev $DEV root tc qdisc add dev $DEV root handle 1: cbq avpkt 1000 bandwidth 100mbit # setup a class to limit to 1500 kilobits/s tc class add dev $DEV parent 1: classid 1:1 cbq rate 1500kbit \ allot 1500 prio 5 bounded isolated # add traffic from 10.2.1.37 to that class tc filter add dev $DEV parent 1: protocol ip prio 16 u32 \ match ip src 10.2.1.37 flowid 1:1
Very nice cheatsheet, helped me a lot recently when I had to replace a faulty drive.
MegaCli -AdpEventLog -GetEvents -f events.log -aALL && cat events.log
how about just using
MegaCli -AdpEventLog -GetEvents -f /dev/stdout -aALL
/opt/MegaRAID/MegaCli
[root@DBS1 MegaCli]# rpm -qa |grep Mega
MegaCli-8.07.10-1.noarch
[root@DBS1 MegaCli]# cat /etc/redhat-release
Red Hat Enterprise Linux Server release 6.1 (Santiago)
[root@DBS1 MegaCli]# uname -a
Linux DBS1 2.6.32-100.34.1.el6uek.x86_64 #1 SMP Wed May 25 17:46:45 EDT 2011 x86_64 x86_64 x86_64 GNU/Linux
[root@DBS1 MegaCli]# lspci |grep RAID
50:00.0 RAID bus controller: LSI Logic / Symbios Logic MegaRAID SAS 2108 [Liberator] (rev 05)
what is the command for make the leds on the physical drives to light again , ,cant tell which drive is failing on visual check.
MegaCli –PDLocate –PhysDrv[E0:S0,E1:S1....]
-aN|-a0,1,2|-aALL
tricky part is, YOU HAVE TO ESCAPE THE BRACKETS IN THE SHELL. fml.
MegaCli pdlocate physdrv \[252:0\] a0
MegaCli pdlocate stop physdrv \[252:0\] a0
MegaCli -PdLocate {[-start] | -stop} -physdrv[E0:S0,E1:S1,...] -aN|-a0,1,2|-aALL
Example: MegaCli -PdLocate -stop -physdrv[237:2] -a0
this monster: