Panduan Instalasi HAproxy pada CentOS 7

Panduan Instalasi HAproxy pada CentOS 7

Artikel ini berisikan panduan instalasi HAproxy di CentOS 7, berikut langkah-langkahnya.

  • Install dahulu Development Tools

yum groupinstall "Development Tools"

  • Install beberapa paket yang dibutuhkan untuk compile

yum -y install readline-devel pcre2-devel openssl-devel systemd-devel zlib-devel

  • Download source code Lua


  • ekstrak source code Lua

tar xzvf lua-5.4.6.tar.gz

  • compile Lua dari source code

cd lua-5.4.6
make INSTALL_TOP=/opt/lua-5.4.6 linux install
cd ~

  • Download source code HAproxy


  • ekstrak source code HAproxy

tar xzvf haproxy-2.8.5.tar.gz

  • compile HAproxy

cd haproxy-2.8.5
make -j $(nproc) TARGET=linux-glibc CPU=native USE_PCRE2=1 USE_PCRE2_JIT=1 USE_OPENSSL=1 USE_ZLIB=1 USE_SYSTEMD=1 USE_LUA=1 LUA_INC=/opt/lua-5.4.6/include LUA_LIB=/opt/lua-5.4.6/lib
make install

  • lakukan pembuatan beberapa file dan directory

cp /usr/local/sbin/haproxy /usr/sbin/
mkdir -p /etc/haproxy
mkdir -p /run/haproxy
mkdir -p /var/lib/haproxy
touch /var/lib/haproxy/stats

  • membuat user untuk service HAproxy

useradd -r haproxy

  • cek status HAproxy

haproxy -v

buat file systemd untuk service HAproxy

vim /etc/systemd/system/haproxy.service

Description=HAProxy Load Balancer

Environment="CONFIG=/etc/haproxy/haproxy.cfg" "PIDFILE=/run/" "EXTRAOPTS=-S /run/haproxy-master.sock"
ExecStartPre=/usr/sbin/haproxy -f $CONFIG -c -q $EXTRAOPTS
ExecStart=/usr/sbin/haproxy -Ws -f $CONFIG -p $PIDFILE $EXTRAOPTS
ExecReload=/usr/sbin/haproxy -f $CONFIG -c -q $EXTRAOPTS
ExecReload=/bin/kill -USR2 $MAINPID

  • reload systemd untuk apply perubahan pada systemd

systemctl daemon-reload

  • buat file config HAproxy

vim /etc/haproxy/haproxy.cfg

    log local2
    maxconn     50000
    chroot      /var/lib/haproxy

    mode http
    log global
    option httplog
    option dontlognull
    timeout connect 5000ms
    timeout client 50000ms
    timeout server 50000ms

frontend http
    bind *:80
    mode http

    acl rcn-website hdr(host) -i
    acl rcn-website hdr(host) -i
    use_backend backend-rcn if rcn-website
backend backend-rcn
    mode http
    option httpclose
    option forwardfor
    server server-1 check

listen  stats
    bind        *:1122
    mode        http
    log         global
    maxconn     16

    stats enable
    stats hide-version
    stats refresh 3s
    stats show-node
    stats admin if TRUE
    stats auth rcn:rcnpass
    stats uri  /stats
    stats realm Haproxy\ Statistics
  • start service HAproxy

systemctl start haproxy.service

About the author

Routecloud Networks

Information about Server, Linux and Computer Network.

Great! You’ve successfully signed up.

Welcome back! You've successfully signed in.

You've successfully subscribed to Routecloud Networks.

Success! Check your email for magic link to sign-in.

Success! Your billing info has been updated.

Your billing was not updated.