首页 > 其他 > 详细

OpenWrt > ADSL单线多播,负载均衡

时间:2016-03-22 22:02:19      阅读:692      评论:0      收藏:0      [点我收藏+]

前题:


 

  • OpenWrt路由器
  • 一些背景知识

步骤


  1. 使用SSH 登陆路由器。I.e. ssh root@192.168.2.1
  2. 运行/usr/bin/duobo。日志类似:
  3. 技术分享
    sh: 2: unknown operand
    Killed
    Warning: Unable to locate ipset utility, disabling ipset support
     * Flushing IPv4 filter table
     * Flushing IPv4 nat table
     * Flushing IPv4 mangle table
     * Flushing IPv4 raw table
     * Flushing conntrack table ...
     * Populating IPv4 filter table
       * Zone lan
       * Zone wan
       * Rule Allow-DHCP-Renew
       * Rule Allow-Ping
       * Rule 51413
       * Rule 9091
       * Rule 9000
       * Rule 6800
       * Forward lan -> wan
     * Populating IPv4 nat table
       * Zone lan
       * Zone wan
     * Populating IPv4 mangle table
       * Zone lan
       * Zone wan
     * Populating IPv4 raw table
       * Zone lan
       * Zone wan
     * Set tcp_ecn to off
     * Set tcp_syncookies to on
     * Set tcp_window_scaling to on
     * Running script /etc/firewall.user
     * Running script /usr/share/miniupnpd/firewall.include
     * Running script /usr/share/qos_gargoyle/firewall.include
       ! Failed with exit code 1
    
    ___________________________________________________
    开始第1次拔号...........
    正在并发拔号中.............
    等待3秒.............
    [3]拔[0]拔成功, 小于设定的[2]拔,将重新拔号...
    
    _________________________
    View Code
  4. 如果没有成功并发多播,重新运行。根据提示信息调整duobo的内部参数设置,分享一些技巧
  5. 由于‘遗留问题’,我需要多一个步骤,跑到N-WAN的选项卡,点一下‘保存&应用’。
  6. number=10
    n=3
    ok=2
    wait=5
    • 原则:失败多次以后,建议冷重启路由器,多个运行中的脚本会互相冲突,把问题复杂化
    • 把n调到6,这样会虚拟出很多接口。重启后调回来3.
    • 将ok调低一点,比如2。我觉得别太贪心,如果能稳定多播2个ADSL的IP,那其实概率上更折中了稳定性和高负载下的带宽均衡。
    • wait的时间其实不需要20s,我感觉5s差不多,这个要看运行日志,做相应调整

遗留问题


 

技术分享
 1 开始第3次拔号...........
 2 正在并发拔号中.............
 3 等待10秒.............
 4 pppoe-wan Link encap:Point-to-Point Protocol  
 5 pppoe-wan3 Link encap:Point-to-Point Protocol  
 6 [3]拔[2]拔成功, 大于或等于设定的[2]拨,退出拔号...
 7 Error: an inet address is expected rather than "dev".
 8 iptables v1.4.10: Couldnt load target `zone_wan_notrack:File not found
 9 
10 Try `iptables -h or iptables --help for more information.
11 iptables v1.4.10: Couldnt load target `zone_wan_nat:File not found
12 
13 Try `iptables -h or iptables --help for more information.
14 iptables: No chain/target/match by that name.
15 iptables v1.4.10: Couldnt load target `zone_wan:File not found
16 
17 Try `iptables -h or iptables --help for more information.
18 iptables: No chain/target/match by that name.
19 iptables: No chain/target/match by that name.
20 iptables: No chain/target/match by that name.
21 iptables: No chain/target/match by that name.
22 iptables: No chain/target/match by that name.
23 iptables: No chain/target/match by that name.
24 iptables: No chain/target/match by that name.
25 Error: an inet address is expected rather than "dev".
26 iptables v1.4.10: Couldnt load target `zone_wan_notrack:File not found
27 
28 Try `iptables -h or iptables --help for more information.
29 iptables v1.4.10: Couldnt load target `zone_wan_nat:File not found
30 
31 Try `iptables -h or iptables --help for more information.
32 iptables: No chain/target/match by that name.
33 iptables v1.4.10: Couldnt load target `zone_wan:File not found
34 
35 Try `iptables -h or iptables --help for more information.
36 iptables: No chain/target/match by that name.
37 iptables: No chain/target/match by that name.
38 iptables: No chain/target/match by that name.
39 iptables: No chain/target/match by that name.
40 iptables: No chain/target/match by that name.
41 iptables: No chain/target/match by that name.
42 iptables: No chain/target/match by that name.
43 Error: an IP address is expected rather than "dev"
44 192.168.2.0/24 dev br-lan  proto kernel  scope link  src 192.168.2.1 
45 221.218.232.1 dev pppoe-wan3  proto kernel  scope link  src 123.112.248.148 
46 221.218.232.1 dev pppoe-wan  proto kernel  scope link  src 221.218.236.51 
47 Kernel IP routing table
48 Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
49 192.168.2.0     0.0.0.0         255.255.255.0   U     0      0        0 br-lan
50 221.218.232.1   0.0.0.0         255.255.255.255 UH    0      0        0 pppoe-wan3
51 221.218.232.1   0.0.0.0         255.255.255.255 UH    0      0        0 pppoe-wan
View Error Code

显然这个0.3版本的脚本不完全适用于我的路由器,有时间我需要查查原因。

估计都是关于iptables

有没有大侠指点一下?

 

多播代码(V0.3)


 

技术分享
  1 #!/bin/sh
  2 #modified by muziling v0.3
  3 #并发多拨脚本
  4 
  5 #number是重拔次数
  6 #n是几拔
  7 #ok是拔上几次后退出拔号
  8 #wait time
  9 
 10 number=10
 11 n=3
 12 ok=2
 13 wait=5
 14 # avoid same with feixiangs N-WAN naming and must start with "wan"
 15 prefix=wan
 16 vthprefix=vth
 17 
 18 j=$(ifconfig | grep pppoe-wan | wc -l)
 19 if [ "$j" >= "$ok" ] ;
 20 then
 21     echo 已经是[$j]拔了,退出拔号...
 22     exit 0
 23 fi
 24 
 25 if [ -f /etc/config/nwannumset ] ;
 26 then
 27     uci set nwannumset.@macvlan_numset[0].macvlan_num=1
 28     uci commit nwannumset
 29 fi
 30 for i in $( seq 1 $(($n-1)))
 31 do
 32     ifname=$prefix$i
 33     ifvth=$vthprefix$i
 34     #ifwan=$(uci get network.wan.ifname)
 35     pppoe_name=$(uci get network.wan.username) 
 36     pppoe_pw=$(uci get network.wan.password) 
 37 
 38     if [ $(ip link | grep " ${ifvth}@eth0.2:" | wc -l) == "0" ] ;
 39     then
 40         macfac=$(ifconfig | grep eth0.2 | tr -s " " | cut -d " " -f5 | cut -b 1-8)
 41         mac="$macfac:"$(md5sum /proc/sys/kernel/random/uuid | sed s/\(..\)/&:/g | cut -b 1-8 | tr [a-f] [A-F])
 42         ip link add link eth0.2 $ifvth type macvlan
 43         ifconfig $ifvth hw ether $mac
 44     fi
 45 
 46     # add /etc/config/network
 47     uci delete network.$ifname
 48     uci set network.$ifname=interface
 49     uci set network.$ifname.ifname=$ifvth
 50     #uci set network.$ifname._orig_ifname=eth0.2
 51     #uci set network.$ifname._orig_bridge=false
 52     uci set network.$ifname.proto=pppoe
 53     uci set network.$ifname.username=$pppoe_name
 54     uci set network.$ifname.password=$pppoe_pw
 55     uci set network.$ifname.auto=0
 56     uci set network.$ifname.defaultroute=0
 57     uci set network.$ifname.peerdns=1
 58     uci set network.$ifname.pppd_options="plugin rp-pppoe.so syncppp $n"
 59 
 60     # add /etc/config/dhcp
 61     uci delete dhcp.$ifvth
 62     uci set dhcp.$ifvth=dhcp 
 63     uci set dhcp.$ifvth.interface=$ifname
 64     uci set dhcp.$ifvth.ignore=1 
 65 
 66     if [ -f /etc/config/nwan ] ;
 67     then
 68         uci delete nwan.$ifname
 69         uci set nwan.$ifname=interface 
 70         uci set nwan.$ifname.name=telecom 
 71         uci set nwan.$ifname.route=balance 
 72         uci set nwan.$ifname.weight=1 
 73         uci set nwan.$ifname.uptime=0day,0hour,0min
 74         uci commit nwan
 75     fi
 76 done
 77 uci set network.wan.defaultroute=0
 78 uci set network.wan.peerdns=1
 79 uci set network.wan.pppd_options="plugin rp-pppoe.so syncppp $n"
 80 uci commit network
 81 uci commit dhcp
 82 
 83 fw_wan_list=$(uci show network |grep =interface |grep -v lan|grep -v loopback |cut -d"." -f2 | awk -F "=" {printf $1" "})
 84 uci set firewall.@zone[1].network="$fw_wan_list"
 85 uci commit firewall
 86 /etc/init.d/firewall restart
 87 
 88 for q in $( seq 1 $number )
 89 do
 90     echo
 91     echo ___________________________________________________
 92     echo 开始第$q次拔号...........
 93     killall -q -SIG pppd
 94     if [ "$q" == "1" ] ;
 95     then
 96         for i in $( seq 1 $(($n-1)))
 97         do
 98             ifup $prefix$i
 99         done
100     fi
101 
102     echo 正在并发拔号中.............
103     echo 等待$wait秒.............
104     sleep $wait
105 
106     j=$(ps | grep pppd | wc -l)
107     ! [ "$j" -ge "$n" ]  && ifup ${prefix}1
108 
109     ifconfig|grep pppoe
110     j=$(ifconfig | grep pppoe-wan | wc -l)
111 
112     ! [ "$j" -ge "$ok" ] && echo [$n]拔[$j]拔成功, 小于设定的[$ok]拔,将重新拔号...
113     [ "$j" -ge "$ok" ] && echo [$n]拔[$j]拔成功, 大于或等于设定的[$ok]拨,退出拔号...
114 
115     if [ "$j" -ge "$ok" ] ;
116     then
117         for i in $( seq 0 $(($n-1)))
118         do
119             if [ "$i" == "0" ] ;
120             then
121                 interface=wan
122             else
123                 interface=$prefix$i
124             fi
125             if [ $(ifconfig | grep "pppoe-$interface " | wc -l) == "0" ] ;
126             then
127                 ifdown $interface
128             fi
129         done
130         break
131     fi
132 done
133 # kill ddns sleep and re-check wan ip change
134 killall sleep
135 
136 j=$(ifconfig | grep pppoe-wan | wc -l)
137 ! [ "$j" -ge 0 ] && reboot
138 
139 #ppoename=$(ifconfig |grep ppoe- |awk {print substr($1,7)}|tr \n  )
140 ppoename=$(ifconfig |grep ppoe- |awk {print $1}|tr \n  )
141 i=0
142 vias=""
143 for wan_ifname in $ppoename
144 do
145     vias="$vias nexthop via $wan_ip dev $wan_ifname weight 1 "
146     let "rt=100+$i"
147     i=$(($i+1))
148     ip route flush table $rt
149     ip route add default via $wan_ip dev $wan_ifname table $rt
150     ip route add table $rt to $(ip route | grep br-lan)
151 
152     if [ $(iptables -t nat -vxnL POSTROUTING | grep -c " $wan_ifname ") == "0" ] ;
153     then
154         iptables -t raw -A PREROUTING -i $wan_ifname -j zone_wan_notrack
155         iptables -t nat -A PREROUTING -i $wan_ifname -j zone_wan_prerouting
156         iptables -t nat -A POSTROUTING -o $wan_ifname -j zone_wan_nat
157         iptables -t filter -A forward -i $wan_ifname -j zone_wan_forward
158         iptables -t filter -A input -i $wan_ifname -j zone_wan
159         iptables -t filter -A zone_wan_ACCEPT -o $wan_ifname -j ACCEPT
160         iptables -t filter -A zone_wan_ACCEPT -i $wan_ifname -j ACCEPT
161         iptables -t filter -A zone_wan_DROP -o $wan_ifname -j DROP
162         iptables -t filter -A zone_wan_DROP -i $wan_ifname -j DROP
163         iptables -t filter -A zone_wan_REJECT -o $wan_ifname -j reject
164         iptables -t filter -A zone_wan_REJECT -i $wan_ifname -j reject
165     fi
166     iptables -A PREROUTING -t mangle -i $wan_ifname -j MARK --set-mark $rt
167     iptables -t mangle -A zone_wan_MSSFIX -o $wan_ifname -p tcp -m tcp --tcp-flags SYN,RST SYN -j TCPMSS --clamp-mss-to-pmtu
168     ip rule add fwmark $rt table $rt prio $rt
169 done
170 ip route del default
171 ip route add default scope global $vias
172 ip route flush cache
173 ip route list
174 route -n
175 root@OpenWrt:~# 
View Code (duobo)

 

参考文献


 

OpenWrt For AR71xx系列 ar2 Tr 脱机 N-WAN r48549

自己动手 4530R 脱机 Samba U-BOOT 多拨(11-04更新部分问题说明,请看2楼)

[0916更新]WR703N WR720N 及其他各类 OpenWRT类路由实现一号多拨带宽叠加教程

OpenWrt > ADSL单线多播,负载均衡

原文:http://www.cnblogs.com/backuper/p/5308584.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!