Load Balancer คือ ระบบเซิร์ฟเวอร์ที่มีประสิทธิภาพสูง รองรับการทำงานทีมีปริมาณงาน (Workload) เป็นจำนวนมากได้เป็นอย่างดี เกิดจากการนำเซิร์ฟเวอร์หลายๆ เครื่องที่มีหน้าที่การทำงานเดียวกันมาทำงานร่วมกันเพื่อกระจายปริมาณงานไปยังแต่ละเครื่อง ทำให้ระบบสามารถรองรับการทำงานหนักๆ ได้เป็นอย่างดี มีความยืดหยุ่นในการออกแบบระบบให้เหมาะกับทุกๆ สถานการณ์ เพื่อตอบสนองความต้องการของคุณอย่างแท้จริง ทำไมต้องใช้ Load Balancer ? เพราะความต้องการใช้งานที่เพิ่มขึ้น ทำให้ต้องหาวิธีการรองรับ เพื่อไม่ให้เกิดปัญหา Over Load จนเครื่อง Web Server, Application Server หรือ Database Server ไม่สามารถให้บริการได้ การทำ Server Load Balance เป็นอีกวิธีการหนึ่งที่จะสามารถช่วยแก้ปัญหาได้ โดยที่ไม่จำเป็นต้องซื้อเครื่องที่ Spec สูงมากๆ ซึ่งมีราคาแพงมาเปลี่ยนแทนเครื่องเดิม แต่สามารถใช้เครื่องที่ Spec เท่าๆกันหลายเครื่อง มาทำงานร่วมกันแทน โดยการทำ Load Balance ในบางกรณีจะทำให้ได้ ระบบมีประสิทธิภาพสูงและความเสถียรมากกว่าการใช้เครื่องใหญ่ๆ เครื่องเดียวอีกด้วย โดยหลักนิยมใช้งานกันส่วนมากจะเป็นทั้ง 3 วีธีดังนี้ 1.Round Robin เป็นการส่ง Traffic ไปยัง Server ภายในกลุ่มวนไปเรื่อย เช่น 1,2,3,… 2.Sticky เป็นการส่ง Traffic โดยยึดติดกับ Session ที่ User เคยเข้าไปใช้งาน 3.Work Load เป็นการส่ง Traffic โดยดูที่ Performance ของ Server ภายในกลุ่มเป็นสำคัญ Load Balancer Software ที่นำมาใช้หลักๆจะเป็น 1.CentOS 7 เป็นระบบปฏิบัติการ 2.Software ที่เป็น Opensource คือ Haproxy มาทำเป็นตัวกระจายโหลด (Load Balancer) 3.Apache 2.4 ทำการ Run เป็นเว็บเซิร์ฟเวอร์ 4.ฐานข้อมูลนั้นนำ Mysql 5.7 มาใช้งาน 5.ในการ Sync ข้อมูลระหว่างเครื่องที่เป็นเว็บเซิร์ฟนั้นจะมี Open Source ที่ชื่อว่า Unsion มาทำการ Replicate 6.Redis เป็นตัวเก็บ Session โดยการทำงานเป็นแบบ Nosql ซึ่งนำมาเก็บ Session การเรียกใช้งานของเว็บเซิร์ฟเวอร์ รูปที่ 1 การทำงานหลักที่เรียกว่า Load Balancer จะเห็นได้ว่าจะรูปที่ 1 จะเป็นการทำงานของ User ที่มีการเรียกใช้งานจาก Web browser ต่างๆ อทิเช่น google chorme firefox IE เป็นต้น เรียกการทำงานมายังเครื่องเซิร์ฟเวอร์ที่เป็น Loadbalancer ซึ่งตัว Loadbalancer จะกระจายโหลดไปยังเว็บเซิร์ฟเวอร์แต่ละเครื่องซึ่งมาจากการ Config ไม่ว่าจะเป็น แบบ Round Robin แบบ Sticky ก็ดี อยู่ที่ลักษณะการทำงานของแต่ระบบที่จะใช้งาน ซึ่งรูปนี้จะมีการ Sync Data กันโดยนำ Unsion มาทำการ Sync ข้อมูลกับเครื่องที่เป็นเว็บเซิร์ฟเวอร์ และมีการแยกดาต้าเบสเซิร์ฟเวอร์ออกจากเครื่องที่เป็นเว็บเซิร์ฟเวอร์เพื่อให้มีการทำงานได้อย่างมีประสิทธิภาพ นอกจากนั้นนำ Redis มาติดตั้งบนเครื่องที่เป็นดาต้าเบสเซิร์ฟเวอร์เพื่อให้มีหน้าที่เก็บ Session ของการทำงาน รูปที่ 2 เป็นการ Statistics Report Statistics Report เป็นการแสดงให้เห็นถึง Status การทำงานว่ามีการใช้งานตอนนี้ไปเท่าไหร่ มีการส่ง Traffic ไปแล้วเท่าไหร่ รวมถึงบอก Status เครื่องเซิร์ฟเวอร์ว่ามีการทำงานเป็นอย่างไร Report อันนี้สามารถวิเคราะห์การเจริญเติบโตว่าควรจะเพิ่มเว็บเซิร์ฟให้เพียงพอต่อการทำงานอีกหรือไม่ Load Balancer ป้องกัน DDOS ตัวอย่างเช่น 1.สามารถป้องกันการใช้งาน Traffic Bandwidth ขนาดใหญ่ที่อาจจะมีผู้ไม่หวังดีทำงานส่งเข้ามายังเครื่องเซิร์ฟเวอร์ของเรา 2.กำหนดค่าป้องกัน IP ที่มีการติด Blacklist เช่น Barracudacentral Spamcop Spamhaus เป็นต้น 3.สามารถเขียน Acl ระบุการโจมตีจาก Bots เนื่องจากตัว Haproxy นั้นสามารถเขียน Acl ป้องกันการโจมตีเพิ่มเติมเข้าไปกับ Config ได้ 4.ป้องกันการโจมตี Syn Flood ซึ่งเป็นการโจมตีเมื่อเครื่อง Server ได้รับแพ็คเกต SYN จะจองพื้นที่ในหน่วยความจำไว้เป็นคิวเพื่อใช้สร้างการเชื่อมต่อ ซึ่งถ้าหากมีเครื่อง Client ส่งแพ็คเกต SYN เข้ามาเป็นจำนวนมากหรือส่งแพ็คเกต SYN เข้ามาจากหลายๆ เครื่องพร้อมกันจนจำนวนคิวที่มีอยู่ไม่เพียงพอ ก็จะทำให้เครื่อง Server ไม่สามารถให้บริการต่อได้ ระบบบที่นำ Monitoring สามารถใช้งานได้ดังนี้ 1.Zabbix นำมาใช้งานเพื่อรองรับการทำงานแจ้งเตือนตัวระบบบอกถึงสถานะการทำงานของ Service ต่างๆ โดยสามารถมอนิเตอร์ได้ถึงในส่วนของ Appication Layer 2.Managed Server Service จะเป็นตัวแสดงให้เห็นถึงปัญหาต่างๆที่เกิดขึ้นไม่ว่าจะเป็น Incident Problem ซึ่งได้เกิดขึ้นกับเครื่องเซิร์ฟเวอร์จะออกมาเป็นในมุมมองของ Report Who’s using it ใครที่มีการใช้งานบ้าง หลักๆที่ใช้งานตอนนี้จะมี Instagram Twitter ที่เป็นที่รู้จักกันดี เป็นต้น ที่มา https://www.haproxy.org/they-use-it.html หากต้องการข้อมูลเพิ่มเติมเกี่ยวกับ Load Balancer หรือผลิตภัณฑ์กลุ่ม Cloud ตัวอื่นๆ สามารถติดต่อ 02-055-1095 Netway.co.th ได้ตลอด 24 ชม
ให้ทำการแก้ไขที่ path # nano -w /etc/rsyslog.conf การแก้ไขโดยการนำเครื่องหมาย # ออก $ModLoad imudp และ $UDPServerRun 514 # Provides UDP syslog reception$ModLoad imudp$UDPServerRun 514 เมื่อแก้ไขเสร็จให้ทำการ Save การเพิ่มค่าไปใน path # nano -w /etc/rsyslog.d/haproxy.conf เพิ่มค่า local2.* /var/log/haproxy.log และทำการ Save และทำการ restart service ตามด้านล่าง # systemctl restart haproxy# systemctl restart rsyslog.service __________________________________________________________________________________________________ Netway Communication ให้บริการด้าน Load Balancer พื้นฐานสำหรับธุรกิจ เป็นตัวแทนแบรนด์ไอทีชั้นนำมากมาย Office 365, Google Workspace, Zendesk, SSL ฯลฯ เรามีเจ้าหน้าที่พร้อมดูแลคุณ 24 ชม. ติดต่อเราเพื่อสอบถามผลิตภัณฑ์ ขอราคา หรือปรึกษาเรื่องไอที ได้เลยค่ะ Line : @netway (มี @ ด้านหน้า) หรือ https://bit.ly/line-netway Facebook : m.me/netway.offcial Tel : 02-055-1095 Email : support@netway.co.th Web Chat : https://netway.co.th/ #ให้เราช่วยคุณเรื่องไอที #การสื่อสาร Netway #มีครบจบที่เดียว #Netway Communication #NetwayTraining #NetwayConnect #Load Balancer
เราสามารถ Config Report การทำงาน Loadbalancer เพื่อตรวจสอบสถานะการทำงานได้ โดยนำ Code ข้างล่างไปใส่ไว้ใน Path /etc/haproxy/haproxy.cfg stats enable stats hide-version stats uri /stats #จะเป็นการตั้งค่า URL ที่เรียกใช้งาน stats realm Haproxy\ Statistics stats auth haproxy:redhat # เป็นการตั้งค่าในส่วน User และ Password ในการ Login เข้าใช้งาน __________________________________________________________________________________________________ Netway Communication ให้บริการด้าน Load Balancer พื้นฐานสำหรับธุรกิจ เป็นตัวแทนแบรนด์ไอทีชั้นนำมากมาย Office 365, Google Workspace, Zendesk, SSL ฯลฯ เรามีเจ้าหน้าที่พร้อมดูแลคุณ 24 ชม. ติดต่อเราเพื่อสอบถามผลิตภัณฑ์ ขอราคา หรือปรึกษาเรื่องไอที ได้เลยค่ะ Line : @netway (มี @ ด้านหน้า) หรือ https://bit.ly/line-netway Facebook : m.me/netway.offcial Tel : 02-055-1095 Email : support@netway.co.th Web Chat : https://netway.co.th/ #ให้เราช่วยคุณเรื่องไอที #การสื่อสาร Netway #มีครบจบที่เดียว #Netway Communication #NetwayTraining #NetwayConnect #Load Balancer
การเพิ่ม Server ที่เป็น Webserver เข้าไปในเครื่อง Loadbalancer โดยการเข้าไปที่ path # nano -w /etc/haproxy/haproxy.cfg จากนั้นเลื่อนลงไปยัง config ด้านล่างจะแสดงให้เห็นถึงเครื่อง Webserver ที่ได้มีการใช้งานอยู่ Config การเชื่อมต่อ Webserver #---------------------------------------------------------------------# static backend for serving up images, stylesheets and such#---------------------------------------------------------------------#backend static# balance roundrobin# server static 127.0.0.1:4331 check##---------------------------------------------------------------------# round robin balancing between the various backends#---------------------------------------------------------------------backend LBbalance roundrobin server webserver1 172.168.10.10:80 cookie webserver1 check # backend server. server webserver2 172.168.10.11:80 cookie webserver2 check # backend server. จะเห็นได้ว่ามีการ Config ไว้ที่ 2 เครื่อง Webserver เมื่อเรามีเครื่อง Webserver เพิ่มเข้ามาอีกเราสามารถเพิ่มต่อจากเดิมได้เลย ตัวอย่างเช่น server webserver3 172.168.10.12:80 cookie webserver3 check เมื่อมีการเพิ่มค่าลงไปแล้วให้ทำการ Restart haproxy จากนั้นสามารถตรวจสอบ Status การทำงานได้ที่ URL ที่ เป็น stats ให้ทำการเพิ่มในส่วนของ /etc/hosts โดยการเพิ่มดังนี้ 172.168.10.10 webserver1.systemnetway.com webserver1 172.168.10.11 webserver2.systemnetway.com webserver2 172.168.10.12 webserver3.systemnetway.com webserver3 เป็นต้น __________________________________________________________________________________________________ Netway Communication ให้บริการด้าน Load Balancer พื้นฐานสำหรับธุรกิจ เป็นตัวแทนแบรนด์ไอทีชั้นนำมากมาย Office 365, Google Workspace, Zendesk, SSL ฯลฯ เรามีเจ้าหน้าที่พร้อมดูแลคุณ 24 ชม. ติดต่อเราเพื่อสอบถามผลิตภัณฑ์ ขอราคา หรือปรึกษาเรื่องไอที ได้เลยค่ะ Line : @netway (มี @ ด้านหน้า) หรือ https://bit.ly/line-netway Facebook : m.me/netway.offcial Tel : 02-055-1095 Email : support@netway.co.th Web Chat : https://netway.co.th/ #ให้เราช่วยคุณเรื่องไอที #การสื่อสาร Netway #มีครบจบที่เดียว #Netway Communication #NetwayTraining #NetwayConnect #Load Balancer
Code When / reason 200 access to stats page, and when replying to monitoring requests 301 when performing a redirection, depending on the configured code 302 when performing a redirection, depending on the configured code 303 when performing a redirection, depending on the configured code 307 when performing a redirection, depending on the configured code 308 when performing a redirection, depending on the configured code 400 for an invalid or too large request 401 when an authentication is required to perform the action (when accessing the stats page) 403 when a request is forbidden by a "block" ACL or "reqdeny" filter 408 when the request timeout strikes before the request is complete 500 when haproxy encounters an unrecoverable internal error, such as a memory allocation failure, which should never happen 502 when the server returns an empty, invalid or incomplete response, or when an "rspdeny" filter blocks the response. 503 when no server was available to handle the request, or in response to monitoring requests which match the "monitor fail" condition 504 when the response timeout strikes before the server responds __________________________________________________________________________________________________ Netway Communication ให้บริการด้าน Load Balancer พื้นฐานสำหรับธุรกิจ เป็นตัวแทนแบรนด์ไอทีชั้นนำมากมาย Office 365, Google Workspace, Zendesk, SSL ฯลฯ เรามีเจ้าหน้าที่พร้อมดูแลคุณ 24 ชม. ติดต่อเราเพื่อสอบถามผลิตภัณฑ์ ขอราคา หรือปรึกษาเรื่องไอที ได้เลยค่ะ Line : @netway (มี @ ด้านหน้า) หรือ https://bit.ly/line-netway Facebook : m.me/netway.offcial Tel : 02-055-1095 Email : support@netway.co.th Web Chat : https://netway.co.th/ #ให้เราช่วยคุณเรื่องไอที #การสื่อสาร Netway #มีครบจบที่เดียว #Netway Communication #NetwayTraining #NetwayConnect #Load Balancer