Hero Image

Install HAProxy on NetBSD 10

Install HAProxy on NetBSD 10

HAProxy is a high-performance TCP/HTTP load balancer.

Step 1 – Install HAProxy

pkgin install haproxy
echo 'haproxy=YES' >> /etc/rc.conf
service haproxy start

Step 2 – Basic configuration (/usr/pkg/etc/haproxy/haproxy.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
    user        haproxy
    group       haproxy
    daemon

defaults
    log         global
    mode        http
    option      httplog
    option      dontlognull
    timeout connect 5s
    timeout client  50s
    timeout server  50s
    errorfile 400 /etc/haproxy/errors/400.http
    errorfile 503 /etc/haproxy/errors/503.http

frontend http-in
    bind *:80
    default_backend webservers

backend webservers
    balance     roundrobin
    option      httpchk GET /health
    server web1 192.168.1.10:80 check
    server web2 192.168.1.11:80 check
    server web3 192.168.1.12:80 check

Step 3 – Validate and reload

haproxy -c -f /usr/pkg/etc/haproxy/haproxy.cfg
systemctl reload haproxy 2>/dev/null || rc-service haproxy reload 2>/dev/null || rcctl reload haproxy

Step 4 – Stats page

listen stats
    bind *:8404
    stats enable
    stats uri /
    stats refresh 10s
    stats auth admin:haproxypass

Access at http://your-server:8404/.