Recently Postgres data synchronization, need to simulate the remote room has bandwidth limitations of the synchronization effect, so want to limit the speed between the two machines.
TS command is very powerful, but also very difficult to understand and use, often wasted long time or uncertain.
Here's a simple and easy-to-use script, just set the target IP and the rate at which it needs to be throttled:
#!/bin/bash## TC uses the following units when passed as a parameter.# kbps:kilobytes per second # mbps:megabytes per se cond# kbit:kilobits per second# mbit:megabits per second# bps:bytes per second # amounts of data can be SPECIF IEDinch: # KB or k:kilobytes# MB or m:megabytes# mbit:megabits# kbit:kilobits# to get thebyteFigure from Bits, divide the number by8BIT#TC=/sbin/Tcif=eth0 # Interface DNLD=1mbit # DOWNLOAD LIMITUPLD=1mbit # UPLOAD Limit IP=216.3.128.12# Host IPU32="$TC Filter Add dev $IF protocol IP parent 1:0 prio 1 u32"start () {$TC qdisc add dev $IF root handle1: HTB Default -$TC class Add dev $IF parent1: ClassID1:1HTB Rate $DNLD $TC class add dev $IF parent1: ClassID1:2HTB rate $UPLD $U match IP DST $IP/ +Flowid1:1$U match ip src $IP/ +Flowid1:2}stop () {$TC qdisc del dev $IF root}restart () {StopSleep 1start}show () {$TC-S QdisclsDev $IF} Case " $" inchstart)Echo-N"Starting bandwidth shaping:"StartEcho " Done" ;; Stop)Echo-N"Stopping bandwidth shaping:"StopEcho " Done" ;; Restart)Echo-N"Restarting bandwidth shaping:"RestartEcho " Done" ;; Show)Echo "Bandwidth Shaping status for $IF: \ n"ShowEcho "" ;; *) pwd=$(pwd) Echo "Usage: $ (/usr/bin/dirname $pwd)/tc.bash {start|stop|restart|show}" ;;EsacExit0
Original address: http://www.iplocation.net/tools/traffic-control.php
Script Address: Http://www.iplocation.net/tc.bash.txt
In Linux, it is very easy to use TC to limit the speed between two servers.