Welcome to Sysnet Board คู่มือ การใช้งานอุปกรณ์ Network. Please log in or sign up.
สมาชิกทั้งหมด
17,591
กระทู้ทั้งหมด
10,018
หัวข้อทั้งหมด
4,705

  • การ Set Load Balance บน RouterBoard แบบ NTH Load Balancing
    เริ่มโดย yod
    Read 29,278 times
0 สมาชิก และ 1 ผู้มาเยือน กำลังดูหัวข้อนี้
yod

 

 

การ Set Load Balance บน RouterBoard แบบ NTH Load Balancing



สวัสดีครับ หัวข้อนี้จะเป็นวิธีการทำ Load Balancing แบบ NTH ครับ

ข้อดีของ Load Balance แบบนี้คือจะแยกแต่ละ IP ของเครื่อง Client ที่ Connect เข้ามา ให้วิ่งออก Wan เส้นใดเส้นนึงโดยตรงเลยครับ เช่นเข้ามาคนแรกก็กำหนดไปเลยให้ออก Wan1 เข้ามาคนที่ 2 ก็ออก Wan 2 พอเข้ามาคนที่ 3 ก็ออก Wan1 ประมาณนี้อะครับ เพราะฉะนั้นจะไม่มีปัญหาเรื่องสลับเส้น Wan ไปมา ทำให้ฝั่ง Server ทำการ Disconnect เครื่องเราออก ซึ่งจะเกิดปัญหาบ่อยเมื่อเล่นเกมส์ Online หรือ MSN


ในตัวอย่างนี้ จะเป็นการทำ Load Balance 2 WAN ครับ ให้ลองทดสอบเล่นก่อนนะครับ โดย Backup ค่าเดิมที่ Set ไว้ก่อน




ผมได้จำลอง RouterBoard อีกตัวให้เป็น Mode PPPoE Server ซึ่งจะเปรียบเหมือนกับ ISP ส่วน RouterBoard ที่ใช้ทดสอบ จะได้ IP จาก PPPoE Server โดย IP ที่ pppoe-out1 เป็น 192.168.88.232 และ IP ที่ pppoe-out2 เป็น 192.168.88.230 ส่วน IP ขา Lan ที่ Router Board จะเป็น 192.168.10.1

จากนั้นก็ Connect ผ่าน Lan ได้ IP: 192.168.10.2 และ Connect ผ่าน Wireless ได้ IP: 192.168.10.3


Script ด้านล่างจะให้ Interface Ether1 เป็น pppoe-out1 และ Interface Ether2 เป็น pppoe-out2 ส่วน Ether3 เป็นขา Lan ของ RouterBoard ครับ

หลักการทำงาน เมื่อมีการ Connect จากเครื่อง Client เข้ามา มันจะ Mark Connection เป็น odd หรือ even ไว้ ส่วน IP Route ด้านล่างสุด ก็จะเลือกว่า Mark ที่เป็น odd ให้ออก ppoe-out1 และ Mark ที่เป็น even ออก pppoe-out2 ที่เหลือไว้ในกรณีเส้นใดเส้นนึงหลุดครับ

แก้ไข user/password ใน pppoe-out แต่ละเส้นให้ตรงกับทาง isp ด้วยนะครับ


/interface pppoe-client
add user=sysnet1@isp password=1234 interface=ether1 disabled=no
add user=sysnet2@isp password=1234 interface=ether2 disabled=no

/ ip firewall mangle
add chain=prerouting src-address-list=odd in-interface=ether3 action=mark-connection new-connection-mark=odd passthrough=yes
add chain=prerouting src-address-list=odd in-interface=ether3 action=mark-routing new-routing-mark=odd passthrough=no
add chain=prerouting src-address-list=even in-interface=ether3 action=mark-connection new-connection-mark=even passthrough=yes
add chain=prerouting src-address-list=even in-interface=ether3 action=mark-routing new-routing-mark=even passthrough=no

add chain=prerouting in-interface=ether3 connection-state=new nth=2,1 action=mark-connection new-connection-mark=odd passthrough=yes
add chain=prerouting in-interface=ether3 action=add-src-to-address-list address-list=odd address-list-timeout=1d connection-mark=odd passthrough=yes
add chain=prerouting in-interface=ether3 connection-mark=odd action=mark-routing new-routing-mark=odd passthrough=no

add chain=prerouting in-interface=ether3 connection-state=new nth=2,2 action=mark-connection new-connection-mark=even passthrough=yes
add chain=prerouting in-interface=ether3 action=add-src-to-address-list address-list=even address-list-timeout=1d connection-mark=even passthrough=yes
add chain=prerouting in-interface=ether3 connection-mark=even action=mark-routing new-routing-mark=even passthrough=no

/ ip firewall nat
add chain=srcnat out-interface=pppoe-out1 action=masquerade
add chain=srcnat out-interface=pppoe-out2 action=masquerade

/ ip route
add dst-address=0.0.0.0/0 gateway=pppoe-out1 scope=255 target-scope=10 routing-mark=odd
add dst-address=0.0.0.0/0 gateway=pppoe-out2 scope=255 target-scope=10 routing-mark=even
add dst-address=0.0.0.0/0 gateway=pppoe-out1 scope=255 target-scope=10
add dst-address=0.0.0.0/0 gateway=pppoe-out2 scope=255 target-scope=10


หลังจาก add script แล้ว จะอยู่ใน Firewall --> Mangle




IP ที่ Connect เข้ามา ทั้ง Card Wireless และ Card Lan จากเครื่อง Notebook ผม




IP ที่ได้ของ Card Lan จะเป็น 192.168.10.2




IP ที่ได้ของ Card Wireless จะเป็น 192.168.10.3




IP ที่เข้ามาจะโดน mark เอาไว้ครับ 192.168.10.3 เป็น even และ 192.168.10.2 เป็น odd


ผมลองถอดสาย Lan ออก จากนั้น Trace route ไปที่ www.pantip.com จะเห็นว่า Package มันออกทาง IP: 192.168.88.230 ซึ่งเป็นขา pppoe-out2 โดย connection ที่ mark ไว้เป็น even ซึ่งก็คือบังคับให้ออก pppoe-out2 ครับ (ดูจาก scrip ในส่วน /ip route)




ทีนี้ผมลอง Disable Wirless Card  จากนั้น Trace route ไปที่ www.pantip.com อีกทีจะเห็นว่าคราวนี้ Package มันวิ่งออกทาง IP: 192.168.88.232 แทน ซึ่งเป็นขา pppoe-out1 โดย connection ที่ mark ไว้เป็น odd ซึ่งก็คือบังคับให้ออก pppoe-out1 ครับ (ดูจาก scrip ในส่วน /ip route)




จากนั้นผมลองทดสอบเผื่อกรณีที่ ISP1 ล่ม โดยการถอดสาย ที่ Wan1 (ether1) ออก ลอง trace route อีกที Package มันจะวิ่งออกIP: 192.168.88.230 ซึ่งก็คือ pppoe-out2 อีกครั้ง




สำหรับ 3 Wan ผมยังไม่ได้ลองนะครับ  ::)





เรียบร้อยครับ ลองเล่นกันดูนะครับ ;D ;D

แล้วผมต้องแก้ยังไงครับคุณยอด  ถ้าเป็นแบบ ECMP ต้องการเปลี่ยนเป็น NTH Load Balancing  และมีเน็ต 3 เส้น

yod


Backup ค่า config ไว้ก่อนครับ จากนั้นเข้า new terminal พิมพ์ /system reset-configuration แล้วตอบ y ครับ หรือ disable ตามรายการ script ที่สร้างไว้ที่หัวข้อ การ Config Router Board ให้เป็น LoadBalance (ตัวอย่าง 3 Wan)


3 Wan ผมยังไม่ได้ลองครับ ต้อง modify code และ test เพิ่มเติมครับ




ถ้า 3 เส้น ต้องเพิ่มสีแดงมาใช่ไหมครับ ส่วนบรรทัดสีเขียวนี้ผมไม่รู้ว่าต้องแก้ยังไงครับเพราะไม่เข้าใจความหมาย

yod
#4
สำหรับ 3 Wan ครับ

Script ด้านล่างในกรณียังไม่ได้ตั้ง pppoe client หรือเพิ่ง reset ใหม่ๆเลย  :)

/interface pppoe-client
add ac-name="" add-default-route=no allow=pap,chap,mschap1,mschap2 comment="" \
   dial-on-demand=no disabled=no interface=ether1 max-mru=1480 \
   max-mtu=1480 mrru=disabled name=pppoe-out1 password=1234 profile=default \
   service-name="" use-peer-dns=yes user=sysnet1@isp
add ac-name="" add-default-route=no allow=pap,chap,mschap1,mschap2 comment="" \
   dial-on-demand=no disabled=no interface=ether2 max-mru=1480 \
   max-mtu=1480 mrru=disabled name=pppoe-out2 password=1234 profile=default \
   service-name="" use-peer-dns=no user=sysnet2@isp
add ac-name="" add-default-route=no allow=pap,chap,mschap1,mschap2 comment="" \
   dial-on-demand=no disabled=no interface=ether3 max-mru=1480 \
   max-mtu=1480 mrru=disabled name=pppoe-out3 password=1234 profile=default \
   service-name="" use-peer-dns=no user=sysnet3@isp

/ip address
add address=192.168.20.1/24 broadcast=192.168.20.255 comment="" disabled=no interface=ether4 network=192.168.20.0

/ip pool
add name=dhcp_pool2 ranges=192.168.20.2-192.168.20.254

/ip dhcp-server
add address-pool=dhcp_pool2 authoritative=after-2sec-delay bootp-support=static disabled=no interface=ether4 lease-time=3d name=dhcp1

/ip dhcp-server network
add address=192.168.20.0/24 comment="" dns-server=192.168.20.1 gateway=192.168.20.1



ในกรณีที่เป็นรุ่น rb450g ส่วนใหญ่จะทำ bridge กันไว้ ให้ไปลบ port ether2 และ ether3 ออกจาก bridge (เข้า menu bridge และไปที่ tab ports ให้ลบ ether2 และ 3 ออกได้เลยครับ)
แต่ถ้าเป็นรุ่น rb750 มักจะทำ ether2 เป็น master ส่วน ether3,4 และ 5 เป็น slave ของ 2 ให้เข้า menu interface และ double click ที่ ether3 เลือก master port เป็น none ส่วน ether4 และ ether5 ก็เหมือนกัน

ใส่ script ตามด้านล่างครับ



/ ip firewall mangle
add chain=prerouting src-address-list=mrk1 in-interface=ether4 action=mark-connection new-connection-mark=mrk1 passthrough=yes
add chain=prerouting src-address-list=mrk1 in-interface=ether4 action=mark-routing new-routing-mark=mrk1 passthrough=no

add chain=prerouting src-address-list=mrk2 in-interface=ether4 action=mark-connection new-connection-mark=mrk2 passthrough=yes
add chain=prerouting src-address-list=mrk2 in-interface=ether4 action=mark-routing new-routing-mark=mrk2 passthrough=no

add chain=prerouting src-address-list=mrk3 in-interface=ether4 action=mark-connection new-connection-mark=mrk3 passthrough=yes
add chain=prerouting src-address-list=mrk3 in-interface=ether4 action=mark-routing new-routing-mark=mrk3 passthrough=no

add chain=prerouting in-interface=ether4 connection-state=new nth=3,1 action=mark-connection new-connection-mark=mrk1 passthrough=yes
add chain=prerouting in-interface=ether4 action=add-src-to-address-list address-list=mrk1 address-list-timeout=1d connection-mark=mrk1 passthrough=yes
add chain=prerouting in-interface=ether4 connection-mark=mrk1 action=mark-routing new-routing-mark=mrk1 passthrough=no

add chain=prerouting in-interface=ether4 connection-state=new nth=3,2 action=mark-connection new-connection-mark=mrk2 passthrough=yes
add chain=prerouting in-interface=ether4 action=add-src-to-address-list address-list=mrk2 address-list-timeout=1d connection-mark=mrk2 passthrough=yes
add chain=prerouting in-interface=ether4 connection-mark=mrk2 action=mark-routing new-routing-mark=mrk2 passthrough=no

add chain=prerouting in-interface=ether4 connection-state=new nth=3,3 action=mark-connection new-connection-mark=mrk3 passthrough=yes
add chain=prerouting in-interface=ether4 action=add-src-to-address-list address-list=mrk3 address-list-timeout=1d connection-mark=mrk3 passthrough=yes
add chain=prerouting in-interface=ether4 connection-mark=mrk3 action=mark-routing new-routing-mark=mrk3 passthrough=no

/ ip firewall nat
add chain=srcnat out-interface=pppoe-out1 action=masquerade
add chain=srcnat out-interface=pppoe-out2 action=masquerade
add chain=srcnat out-interface=pppoe-out3 action=masquerade

/ ip route
add dst-address=0.0.0.0/0 gateway=pppoe-out1 scope=255 target-scope=10 routing-mark=mrk1
add dst-address=0.0.0.0/0 gateway=pppoe-out2 scope=255 target-scope=10 routing-mark=mrk2
add dst-address=0.0.0.0/0 gateway=pppoe-out3 scope=255 target-scope=10 routing-mark=mrk3

add dst-address=0.0.0.0/0 gateway=pppoe-out1 scope=255 target-scope=10
add dst-address=0.0.0.0/0 gateway=pppoe-out2 scope=255 target-scope=10
add dst-address=0.0.0.0/0 gateway=pppoe-out3 scope=255 target-scope=10



ผมลองทดสอบ 3wan

วิธี test เข้า Menu IP --> Firewall

รูปนี้ออก Wan 2 ครับ




ออก Wan 1




ออก Wan 3




ลองทดสอบเล่นกันดูครับ ยังไม่ต้องตั้ง hotspot server ก่อนก็ดีนะครับ เพื่อความชัวร์  ;D ;D




#5
ขอถามเพื่อความแน่ใจครับ คุณยอด
หลังจาก Reset แล้ว
ขั้นตอนที่ 1.
/interface pppoe-client add ac-name="" add-default-route=no allow=pap,chap,mschap1,mschap2 comment="" \
   dial-on-demand=no disabled=no interface=ether1 max-mru=1480 \
   max-mtu=1480 mrru=disabled name=pppoe-out1 password=1234 profile=default \
   service-name="" use-peer-dns=yes user=sysnet1@isp
add ac-name="" add-default-route=no allow=pap,chap,mschap1,mschap2 comment="" \
   dial-on-demand=no disabled=no interface=ether2 max-mru=1480 \
   max-mtu=1480 mrru=disabled name=pppoe-out2 password=1234 profile=default \
   service-name="" use-peer-dns=no user=sysnet2@isp
add ac-name="" add-default-route=no allow=pap,chap,mschap1,mschap2 comment="" \
   dial-on-demand=no disabled=no interface=ether3 max-mru=1480 \
   max-mtu=1480 mrru=disabled name=pppoe-out3 password=1234 profile=default \
   service-name="" use-peer-dns=no user=sysnet3@isp

/ip address
add address=192.168.20.1/24 broadcast=192.168.20.255 comment="" disabled=no interface=ether4 network=192.168.20.0

/ip pool
add name=dhcp_pool2 ranges=192.168.20.2-192.168.20.254

/ip dhcp-server
add address-pool=dhcp_pool2 authoritative=after-2sec-delay bootp-support=static disabled=no interface=ether4 lease-time=3d name=dhcp1

/ip dhcp-server network
add address=192.168.20.0/24 comment="" dns-server=192.168.20.1 gateway=192.168.20.1


ขั้นตอนที่ 2.

/ ip firewall mangle
add chain=prerouting src-address-list=mrk1 in-interface=ether4 action=mark-connection new-connection-mark=mrk1 passthrough=yes
add chain=prerouting src-address-list=mrk1 in-interface=ether4 action=mark-routing new-routing-mark=mrk1 passthrough=no

add chain=prerouting src-address-list=mrk2 in-interface=ether4 action=mark-connection new-connection-mark=mrk2 passthrough=yes
add chain=prerouting src-address-list=mrk2 in-interface=ether4 action=mark-routing new-routing-mark=mrk2 passthrough=no

add chain=prerouting src-address-list=mrk3 in-interface=ether4 action=mark-connection new-connection-mark=mrk3 passthrough=yes
add chain=prerouting src-address-list=mrk3 in-interface=ether4 action=mark-routing new-routing-mark=mrk3 passthrough=no

add chain=prerouting in-interface=ether4 connection-state=new nth=3,1 action=mark-connection new-connection-mark=mrk1 passthrough=yes
add chain=prerouting in-interface=ether4 action=add-src-to-address-list address-list=mrk1 address-list-timeout=1d connection-mark=mrk1 passthrough=yes
add chain=prerouting in-interface=ether4 connection-mark=mrk1 action=mark-routing new-routing-mark=mrk1 passthrough=no

add chain=prerouting in-interface=ether4 connection-state=new nth=3,2 action=mark-connection new-connection-mark=mrk2 passthrough=yes
add chain=prerouting in-interface=ether4 action=add-src-to-address-list address-list=mrk2 address-list-timeout=1d connection-mark=mrk2 passthrough=yes
add chain=prerouting in-interface=ether4 connection-mark=mrk2 action=mark-routing new-routing-mark=mrk2 passthrough=no

add chain=prerouting in-interface=ether4 connection-state=new nth=3,3 action=mark-connection new-connection-mark=mrk3 passthrough=yes
add chain=prerouting in-interface=ether4 action=add-src-to-address-list address-list=mrk3 address-list-timeout=1d connection-mark=mrk3 passthrough=yes
add chain=prerouting in-interface=ether4 connection-mark=mrk3 action=mark-routing new-routing-mark=mrk3 passthrough=no

/ ip firewall nat
add chain=srcnat out-interface=pppoe-out1 action=masquerade
add chain=srcnat out-interface=pppoe-out2 action=masquerade
add chain=srcnat out-interface=pppoe-out3 action=masquerade

/ ip route
add dst-address=0.0.0.0/0 gateway=pppoe-out1 scope=255 target-scope=10 routing-mark=mrk1
add dst-address=0.0.0.0/0 gateway=pppoe-out2 scope=255 target-scope=10 routing-mark=mrk2
add dst-address=0.0.0.0/0 gateway=pppoe-out3 scope=255 target-scope=10 routing-mark=mrk3

add dst-address=0.0.0.0/0 gateway=pppoe-out1 scope=255 target-scope=10
add dst-address=0.0.0.0/0 gateway=pppoe-out2 scope=255 target-scope=10
add dst-address=0.0.0.0/0 gateway=pppoe-out3 scope=255 target-scope=10


เลยใช่ไหมในส่วน Mangle แยกเน็ตแยกเกมส์ต้องเพิ่ม ต้องเพิ่มสคริปส์เข้ามาใน mangle เหมือนใน การทำ ECMP Load balance อยู่หรือปล่าวครับผม
หรือว่าการทำงานในแบบนี้  
pc1 -> Wan1 pc2 -> wan2 pc3 -> Wan3
pc4 -> Wan1 pc6 -> Wan2 pc5 -> Wan3

.....
.....
ตามแต่จะคอนเน็คเข้าตามลำดับใช่ไหมครับ



ขอคำชี้แนะด้วยครับผม
ขอบคุณครับ

yod


สวัสดีครับ

ถ้า backup ไว้แล้วอย่าไปกลัวเรื่อง reset ครับ ;D

เลยใช่ไหมในส่วน Mangle แยกเน็ตแยกเกมส์ต้องเพิ่ม ต้องเพิ่มสคริปส์เข้ามาใน mangle เหมือนใน การทำ ECMP Load balance อยู่หรือปล่าวครับผม
หรือว่าการทำงานในแบบนี้ 
pc1 -> Wan1 pc2 -> wan2 pc3 -> Wan3
pc4 -> Wan1 pc6 -> Wan2 pc5 -> Wan3


รูปแบบการทำงานจะไม่ไเหมือนกับแบบ ECMP ครับ อันนั้นมันจะสุ่มออกเอง บางทีออก wan1 เล่นๆไปมันก็ออก wan2 ได้ครับ

แต่รูปแบบในหัวข้อนี้จะ fix ไปเลยตั้งแต่มี connection เข้ามา ตามแบบ pc1 -> Wan1 pc2 -> wan2 pc3 -> Wan3 pc4 -> Wan1 pc6 -> Wan2 pc5 -> Wan3 ถูกต้อวแล้วครับ

ต้องเพิ่มในส่วน mangle และ route ตาม script ด้วยนะครับ

#7
มีวิธี จิ้ม ปุ่ม รีเซ็ต ไหมครับ ผมรีเชตด้วย /system reset-configuration  แล้วก็ลองทำตามสคริปด้านบน
แต่ไ้ด้ GW เป็น 192.168.88.1  เลยไปแก้ไขแล้วก็เข้าไม่ได้ครับ รบกวนด้วยครับ :'( :'( :'( :'(
หรือถ้าจะรบกวนให้คุณยอดรีโมตผ่าน teamview จะรบกวนไปไหมครับ

yod


ip default ของ router board จะเป็น 192.168.88.1 ปล่อยมันไว้ก่อนก็ได้ครับ จากนั้นเข้าไปที่ bridge ให้ลบ port ether2 และ ether3 ออก เสร็จแล้วก็ตรวจที่ dhcp ว่าชี้ interface ไปที่ bridge หรือมั้ย แค่นี้แหล่ะครับ ขั้นต้น จากนั้นก็ทำระบบ loadbalance

ถ้าแก้ไข ip แล้วเข้า winbox ไม่ได้ ลองเสียบสาย lan ที่ port อื่นดูครับ รอให้ lan status ที่เครื่องคอมมันหมุนๆจนหยุด แล้ว click ที่ mac address ใน list ของ winbox หรือไม่ก็ต้องใช้สาย serial แล้ว telnet เข้าไปแก้หมายเลข ip หรือ reset ใหม่เลย

#9
ผม รีเชตแล้ว(ผมใช้ RB450G จะทำ 3 wan)
-->new terminal
/interface pppoe-client
add ac-name="" add-default-route=no allow=pap,chap,mschap1,mschap2 comment="" \
   dial-on-demand=no disabled=no interface=ether1 max-mru=1480 \
   max-mtu=1480 mrru=disabled name=pppoe-out1 password=1234 profile=default \
   service-name="" use-peer-dns=yes user=sysnet1@isp
add ac-name="" add-default-route=no allow=pap,chap,mschap1,mschap2 comment="" \
   dial-on-demand=no disabled=no interface=ether2 max-mru=1480 \
   max-mtu=1480 mrru=disabled name=pppoe-out2 password=1234 profile=default \
   service-name="" use-peer-dns=no user=sysnet2@isp
add ac-name="" add-default-route=no allow=pap,chap,mschap1,mschap2 comment="" \
   dial-on-demand=no disabled=no interface=ether3 max-mru=1480 \
   max-mtu=1480 mrru=disabled name=pppoe-out3 password=1234 profile=default \
   service-name="" use-peer-dns=no user=sysnet3@isp

/ip address
add address=192.168.20.1/24 broadcast=192.168.20.255 comment="" disabled=no interface=ether4 network=192.168.20.0

/ip pool
add name=dhcp_pool2 ranges=192.168.20.2-192.168.20.254

/ip dhcp-server
add address-pool=dhcp_pool2 authoritative=after-2sec-delay bootp-support=static disabled=no interface=ether4 lease-time=3d name=dhcp1

/ip dhcp-server network
add address=192.168.20.0/24 comment="" dns-server=192.168.20.1 gateway=192.168.20.1


แล้วไปที่ Bride --> Port--> แล้วลบ ether2-local และ ether3-local  มัน Disconnect ทันทีเลยครับ
ผมต่อ Lan ที่ eth5 ครับ

ไฟล์ที่แนบมา  เข้าผ่าน winbox IP 192.168.88.1 ไม่ได้แล้ว
ผมลองเข้าผ่าน macaddress ครับเลยปริ้นสกรีนมาให้ดูครับ ว่าภาพมีส่วนใดผิดไหม