Как известно у HAProxy нет своего репозитария для RedHat-подобных ОС, а в стандартных репозитариях Oracle Linux 7 есть только HAProxy 1.5 и 1.8
Как собрать свежую версию HAProxy 2.0 и первоначально настроить ее читайте ниже.
Исходные данные: Oracle Linux 7
Задача: Собрать и установить HAProxy 2.0 из исходников
1. Подготовка окружения для сборки:
yum install -y gcc pcre-static pcre-devel zlib-devel openssl-devel systemd-devel
2. Сборка HAProxy 2.0.x:
wget http://www.haproxy.org/download/2.0/src/haproxy-2.0.16.tar.gz tar -zxf haproxy-2.0.16.tar.gz cd haproxy-2.0.16 make TARGET=linux-glibc USE_PCRE=1 USE_OPENSSL=1 USE_ZLIB=1 USE_CRYPT_H=1 USE_LIBCRYPT=1 USE_SYSTEMD=1 USE_THREAD=1 USE_PTHREAD_PSHARED=1 cp haproxy /usr/sbin
3. Создание пользователя, вспомогательных каталогов и unit-файла для запуска HAProxy через systemd:
useradd -r -d /var/lib/haproxy -s /sbin/nologin haproxy mkdir -p /etc/haproxy mkdir -p /var/lib/haproxy touch /var/lib/haproxy/stats chown -R haproxy:haproxy /var/lib/haproxy wget https://gist.githubusercontent.com/CHERTS/3dadb93ef08166cdcb02fda76c48f3ba/raw/haproxy.service -O /usr/lib/systemd/system/haproxy.service wget https://gist.githubusercontent.com/CHERTS/43aca50aac0ef0e2a18c403d67f995ed/raw/haproxy.cfg -O /etc/haproxy/haproxy.cfg (cat <<-EOF # Add extra options to the haproxy daemon here. This can be useful for # specifying multiple configuration files with multiple -f options. # See haproxy(1) for a complete list of options. OPTIONS="" EOF ) > /etc/sysconfig/haproxy systemctl daemon-reload systemctl enable haproxy
4. Проверим корректность файла конфигурации:
haproxy -f /etc/haproxy/haproxy.cfg -c
5. Запустим HAProxy:
systemctl start haproxy
И проверим статус:
systemctl status haproxy
Результат:
● haproxy.service - HAProxy Load Balancer Loaded: loaded (/usr/lib/systemd/system/haproxy.service; enabled; vendor preset: disabled) Active: active (running) since Fri 2020-05-08 20:39:38 MSK; 10s ago Process: 8574 ExecStartPre=/usr/sbin/haproxy -f $CONFIG -c -q $EXTRAOPTS (code=exited, status=0/SUCCESS) Main PID: 8576 (haproxy) CGroup: /system.slice/haproxy.service ├─8576 /usr/sbin/haproxy -Ws -f /etc/haproxy/haproxy.cfg -p /run/haproxy.pid -S /run/haproxy-master.sock └─8578 /usr/sbin/haproxy -Ws -f /etc/haproxy/haproxy.cfg -p /run/haproxy.pid -S /run/haproxy-master.sock May 08 20:39:38 myserver systemd[1]: Starting HAProxy Load Balancer... May 08 20:39:38 myserver haproxy[8576]: [NOTICE] 128/203938 (8576) : New worker #1 (8578) forked May 08 20:39:38 myserver systemd[1]: Started HAProxy Load Balancer. May 08 20:39:38 myserver haproxy[8576]: [WARNING] 128/203938 (8578) : Server static/static is DOWN, reason: Layer4 connection prob...n queue. May 08 20:39:38 myserver haproxy[8576]: [ALERT] 128/203938 (8578) : backend 'static' has no server available! May 08 20:39:38 myserver haproxy[8576]: [WARNING] 128/203938 (8578) : Server app/app1 is DOWN, reason: Layer4 connection problem, ...n queue. May 08 20:39:39 myserver haproxy[8576]: [WARNING] 128/203939 (8578) : Server app/app2 is DOWN, reason: Layer4 connection problem, ...n queue. May 08 20:39:39 myserver haproxy[8576]: [WARNING] 128/203939 (8578) : Server app/app3 is DOWN, reason: Layer4 connection problem, ...n queue. May 08 20:39:39 myserver haproxy[8576]: [WARNING] 128/203939 (8578) : Server app/app4 is DOWN, reason: Layer4 connection problem, ...n queue. May 08 20:39:39 myserver haproxy[8576]: [ALERT] 128/203939 (8578) : backend 'app' has no server available!
6. Проверим статус HAProxy:
Проверим открытые порты:
netstat -ltupn | grep [h]aproxy
Результат:
tcp 0 0 0.0.0.0:5000 0.0.0.0:* LISTEN 8578/haproxy udp 0 0 0.0.0.0:11121 0.0.0.0:* 8576/haproxy udp 0 0 0.0.0.0:49219 0.0.0.0:* 8578/haproxy udp 0 0 0.0.0.0:21387 0.0.0.0:* 8578/haproxy
Выведем статистику:
echo "show stat" | nc -U /var/lib/haproxy/stats
Результат:
# pxname,svname,qcur,qmax,scur,smax,slim,stot,bin,bout,dreq,dresp,ereq,econ,eresp,wretr,wredis,status,weight,act,bck,chkfail,chkdown,lastchg,downtime,qlimit,pid,iid,sid,throttle,lbtot,tracked,type,rate,rate_lim,rate_max,check_status,check_code,check_duration,hrsp_1xx,hrsp_2xx,hrsp_3xx,hrsp_4xx,hrsp_5xx,hrsp_other,hanafail,req_rate,req_rate_max,req_tot,cli_abrt,srv_abrt,comp_in,comp_out,comp_byp,comp_rsp,lastsess,last_chk,last_agt,qtime,ctime,rtime,ttime,agent_status,agent_code,agent_duration,check_desc,agent_desc,check_rise,check_fall,check_health,agent_rise,agent_fall,agent_health,addr,cookie,mode,algo,conn_rate,conn_rate_max,conn_tot,intercepted,dcon,dses,wrew,connect,reuse,cache_lookups,cache_hits,srv_icur,src_ilim,qtime_max,ctime_max,rtime_max,ttime_max, main,FRONTEND,,,0,0,3000,0,0,0,0,0,0,,,,,OPEN,,,,,,,,,1,2,0,,,,0,0,0,0,,,,0,0,0,0,0,0,,0,0,0,,,0,0,0,0,,,,,,,,,,,,,,,,,,,,,http,,0,0,0,0,0,0,0,,,0,0,,,,,,, static,static,0,0,0,0,,0,0,0,,0,,0,0,0,0,DOWN,1,1,0,1,1,94,94,,1,3,1,,0,,2,0,,0,L4CON,,0,0,0,0,0,0,0,,,,,0,0,,,,,-1,Connection refused,,0,0,0,0,,,,Layer4 connection problem,,2,3,0,,,,127.0.0.1:4331,,http,,,,,,,,0,0,0,,,0,,0,0,0,0, static,BACKEND,0,0,0,0,300,0,0,0,0,0,,0,0,0,0,DOWN,0,0,0,,1,94,94,,1,3,0,,0,,1,0,,0,,,,0,0,0,0,0,0,,,,0,0,0,0,0,0,0,-1,,,0,0,0,0,,,,,,,,,,,,,,http,roundrobin,,,,,,,0,0,0,0,0,,,0,0,0,0, app,app1,0,0,0,0,,0,0,0,,0,,0,0,0,0,DOWN,1,1,0,1,1,94,94,,1,4,1,,0,,2,0,,0,L4CON,,0,0,0,0,0,0,0,,,,,0,0,,,,,-1,Connection refused,,0,0,0,0,,,,Layer4 connection problem,,2,3,0,,,,127.0.0.1:5001,,http,,,,,,,,0,0,0,,,0,,0,0,0,0, app,app2,0,0,0,0,,0,0,0,,0,,0,0,0,0,DOWN,1,1,0,1,1,93,93,,1,4,2,,0,,2,0,,0,L4CON,,0,0,0,0,0,0,0,,,,,0,0,,,,,-1,Connection refused,,0,0,0,0,,,,Layer4 connection problem,,2,3,0,,,,127.0.0.1:5002,,http,,,,,,,,0,0,0,,,0,,0,0,0,0, app,app3,0,0,0,0,,0,0,0,,0,,0,0,0,0,DOWN,1,1,0,1,1,93,93,,1,4,3,,0,,2,0,,0,L4CON,,0,0,0,0,0,0,0,,,,,0,0,,,,,-1,Connection refused,,0,0,0,0,,,,Layer4 connection problem,,2,3,0,,,,127.0.0.1:5003,,http,,,,,,,,0,0,0,,,0,,0,0,0,0, app,app4,0,0,0,0,,0,0,0,,0,,0,0,0,0,DOWN,1,1,0,1,1,93,93,,1,4,4,,0,,2,0,,0,L4CON,,0,0,0,0,0,0,0,,,,,0,0,,,,,-1,Connection refused,,0,0,0,0,,,,Layer4 connection problem,,2,3,0,,,,127.0.0.1:5004,,http,,,,,,,,0,0,0,,,0,,0,0,0,0, app,BACKEND,0,0,0,0,300,0,0,0,0,0,,0,0,0,0,DOWN,0,0,0,,1,93,93,,1,4,0,,0,,1,0,,0,,,,0,0,0,0,0,0,,,,0,0,0,0,0,0,0,-1,,,0,0,0,0,,,,,,,,,,,,,,http,roundrobin,,,,,,,0,0,0,0,0,,,0,0,0,0,
Как мы видим, HAProxy успешно запустился с типовым файлом конфигурации.
На этом все, до скорых встреч. Если у Вас возникли вопросы или Вы хотите чтобы я помог Вам, то Вы всегда можете связаться со мной разными доступными способами.
Профессионально занимаюсь системным администрированием Linux -серверов и баз данных (MySQL, PostgreSQL) на протяжении последних 24 лет.