sudo apt install haproxy
chỉnh sửa file sudo nano /etc/haproxy/haproxy.cfg
global
log /dev/log local0 info # Ghi log chi tiết hơn (info)
log /dev/log local1 notice
chroot /var/lib/haproxy
user haproxy
group haproxy
daemon
maxconn 2000
# Đảm bảo rằng logging đã được bật
defaults
log global
mode tcp
option tcplog # Đảm bảo rằng tcplog được bật để ghi log TCP
option dontlognull
timeout connect 5000ms
timeout client 50000ms
timeout server 50000ms
retries 3
tạo file all_rtmp.cfg
sudo nano all_rtmp.cfg
global
log /dev/log local0
log /dev/log local1 notice
chroot /var/lib/haproxy
# stats socket /run/haproxy/admin.sock mode 660 level admin # Uncomment if needed
stats timeout 30s
user haproxy
group haproxy
daemon
# Tuning performance
maxconn 2000
tune.ssl.default-dh-param 2048
defaults
log global
mode tcp
option tcplog
option dontlognull
timeout connect 5000ms
timeout client 50000ms
timeout server 50000ms
retries 3
frontend rtmp_frontend
mode tcp
bind *:4334 # Change to 1935 if you prefer default RTMP port
timeout client 50000
default_backend rtmp_backend
backend rtmp_backend
mode tcp
balance roundrobin # Load balancing method
timeout connect 60s
timeout server 50000ms
option tcp-check # Perform a health check for the backend servers
server server1 192.168.1.164:1935 check
server server2 192.168.1.222:1940 check
server server3 192.168.1.222:1970 check
server server4 192.168.1.164:1960 check
listen stats
bind *:8404 # Port for HAProxy statistics
mode http
stats enable
stats uri /haproxy?stats
stats refresh 10s
stats auth admin:adminpass # Basic authentication for accessing stats page
sudo haproxy -f all_rtmp.cfg
sudo systemctl start haproxy
sudo systemctl enable haproxy
sudo systemctl status haproxy
sudo systemctl restart haproxy
http://192.168.1.222:8404/haproxy?stats