Centos / Rocky / RedHat üzerinde haproxy src build hk.

Alparslan Ozturk
2 min readOct 4, 2021

Öncelikle Debian 10 ve 11 de bu tür işlemlerle uğraşmak zorunda kalmadan 2.x serisi haproxy servisini kullanabiliyorsunuz. Ancak Centos üzerinde src pakettten derlemeniz lazım.

0. öncelikle aşağdaki paketleri yükleyelim;

yum -y install gcc \
openssl-devel \
readline-devel \
systemd-devel \
make \
pcre-devel
  1. lua paketini derlemek ve install etmek;
wget https://www.lua.org/ftp/lua-5.4.3.tar.gz
tar zxvf lua-5.4.3.tar.gz
make
make install
echo "/usr/local/lib" > /etc/ld.so.conf.d/lua.conf
ldconfig -v
  1. haproxy paketini derlemek ; ben PREFIX vermeden yaptım, ama verilebilr.
make -j $(nproc) TARGET=linux-glibc \
USE_OPENSSL=1 \
USE_LUA=1 \
USE_PCRE=1 \
USE_SYSTEMD=1 \
USE_PROMEX=1
2.4.x den sonrası için USE_PRMEX=1 eklemeniz yeterlidir. /?metrics için…

Tabi burada ufak bir group/kullanıcı ikisini açmak lazım. sonrasında aşağdaki şekilde systemd servisini ekleyeyelim;

groupadd -g 188 haproxy
useradd -u 188 -g -m -d /var/lib/haproxy -s /sbin/nologin -c haproxy haproxy

Tabi burada gid / ve uid siz istediğinizi verebilirsiniz.

/root/haproxy/haproxy-2.4.4[root@ha1 haproxy-2.4.4]# cd admin/systemd/
[root@ha1 systemd]# make
cp haproxy.service cd admin/systemd/
systemctl daemon-reload

Buradan sonra haproxy.cfg dosyasını create etme işini size bırakıyorum. ornek aşağıdadır.

mkdir /etc/haproxy

global
daemon
maxconn 256
user haproxy
group haproxy
chroot /var/lib/haproxy

defaults
mode tcp
frontend istatistik
bind *:80
mode http
stats enable
#stats hide-version
stats uri /
stats refresh 10s
option http-use-htx
http-request use-service prometheus-exporter if {path /metrics}
.....

en son ayarları kontrol edip çalıştarabiliriz;

haproxy -c -f /etc/haproxy/haproxy.cfg


[NOTICE] (34779) : haproxy version is 2.4.4-acb1d0b
[NOTICE] (34779) : path to executable is /usr/local/sbin/haproxy
[ALERT] (34779) : parsing [/etc/haproxy/haproxy.cfg:21] : error detected in frontend ‘istatistik’ while parsing ‘http-request use-service’ rule : ‘prometheus-exporter’ unknown service name..
[ALERT] (34779) : Error(s) found in configuration file : /etc/haproxy/haproxy.cfg
tekrar düzgün make && make install yapınca düzeldi.

--

--