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

wget https://www.lua.org/ftp/lua-5.4.6.tar.gz

  • 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

wget https://www.haproxy.org/download/2.8/src/haproxy-2.8.5.tar.gz

  • 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

[Unit]
Description=HAProxy Load Balancer
After=network.target

[Service]
Environment="CONFIG=/etc/haproxy/haproxy.cfg" "PIDFILE=/run/haproxy.pid" "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
KillMode=mixed
Restart=always
SuccessExitStatus=143
Type=notify

[Install]
WantedBy=multi-user.target
  • reload systemd untuk apply perubahan pada systemd

systemctl daemon-reload

  • buat file config HAproxy

vim /etc/haproxy/haproxy.cfg

global
    log         127.0.0.1 local2
    daemon
    maxconn     50000
    chroot      /var/lib/haproxy

defaults
    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 routecloud.net
    acl rcn-website hdr(host) -i www.routecloud.net
    use_backend backend-rcn if rcn-website
    
backend backend-rcn
    mode http
    option httpclose
    option forwardfor
    server server-1 10.10.10.10:80 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
arisyi

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.