การจัดการ Server > Haproxy
HAproxy on Centos7
(1/1)
ผู้ดูแลระบบ:
HAproxy on centos7
การทำ load balanced Layer4(Transport Layer) โดย haproxy
คุณต้องทำ web server ให้สามารถทำงานได้ก่อน 2 เครื่อง
และเครื่องสำหรับติดตั้ง haproxy 1 เครื่อง
1. ติดตั้ง haproxy
yum install haproxy
2.Config
vim /etc/haproxy/haproxy.cfg
ใน file จะมีค่าประมาณนี้
timeout client 30s
# timeout on server side
timeout server 30s
# การ monitor
stats enable
stats refresh 10s
stats uri /stats
stats realm Haproxy\ Statistics
stats auth haproxy:HAPROXY
# define frontend ( set any name for "http-in" section )
frontend http-in
# listen 80
bind *:80
# set default backend
default_backend backend_servers
# send X-Forwarded-For header
option forwardfor
# define backend
backend backend_servers
# balance with roundrobin
balance roundrobin
# define backend servers
server web1 192.168.30.134:80 check
server web2 192.168.30.135:80 check
บันทึก
3. start haproxy
systemctl start haproxy
สั่งให้ service start ทุกครั้งที่เปิดเครื่องใหม่
systemctl is-enabled haproxy
ถ้าแก้ไข config ทุกครั้งแล้วให้สั่ง
systemctl restart haproxy
ทดสอบด้วยการ เรียก ip ของเครื่อง haproxy
แล้ว refresh ดูว่าสลับทำงานหรือไม่(webserver 1,2 ให้ทำหน้าแรกแตกต่างกันไว้เพื่อดูว่าสลับกันทำงานจริงหรือไม่ )
นำร่อง
[0] ดัชนีข้อความ
Go to full version