La traducción del artículo se preparó la víspera del inicio del curso “Administrador de Linux. Virtualización y agrupación en clústeres "
— - . HAProxy , .
HAProxy , , . Linux, CentOS 8, , Debian 8 Ubuntu 16.
HAProxy - - . HAProxy CentOS 8, -.
- . - -, nginx httpd, .
HAProxy CentOS 8
, HAProxy — , , CentOS, . , :
sudo yum info haproxy
HAProxy : , , . , HAProxy, , .
2.0, . . , .
sudo yum install gcc pcre-devel tar make -y
. , , HAProxy.
wget http://www.haproxy.org/download/2.0/src/haproxy-2.0.7.tar.gz -O ~/haproxy.tar.gz
:
tar xzvf ~/haproxy.tar.gz -C ~/
:
cd ~/haproxy-2.0.7
:
make TARGET=linux-glibc
, , HAProxy:
sudo make install
HAProxy , . .
HAProxy
HAProxy:
sudo mkdir -p /etc/haproxy
sudo mkdir -p /var/lib/haproxy
sudo touch /var/lib/haproxy/stats
, HAProxy :
sudo ln -s /usr/local/sbin/haproxy /usr/sbin/haproxy
- , haproxy.init examples /etc/init.d. , , systemd:
sudo cp ~/haproxy-2.0.7/examples/haproxy.init /etc/init.d/haproxy
sudo chmod 755 /etc/init.d/haproxy
sudo systemctl daemon-reload
:
sudo chkconfig haproxy on
HAProxy:
sudo useradd -r haproxy
:
haproxy -v
HA-Proxy version 2.0.7 2019/09/27 - https://haproxy.org/
2.0.7, .
, CentOS 8 . , :
sudo firewall-cmd --permanent --zone=public --add-service=http
sudo firewall-cmd --permanent --zone=public --add-port=8181/tcp
sudo firewall-cmd --reload
HAProxy — . , , , HAProxy, .
/etc/haproxy/haproxy.cfg . HAProxy , .
(layer 4)
. , , vi :
sudo vi /etc/haproxy/haproxy.cfg
. server_name , , private_ip — IP- , -. IP- UpCloud Private network Network.
global
log /dev/log local0
log /dev/log local1 notice
chroot /var/lib/haproxy
stats timeout 30s
user haproxy
group haproxy
daemon
defaults
log global
mode http
option httplog
option dontlognull
timeout connect 5000
timeout client 50000
timeout server 50000
frontend http_front
bind *:80
stats uri /haproxy?stats
default_backend http_back
backend http_back
balance roundrobin
server server_name1 private_ip1:80 check
server server_name2 private_ip2:80 check
(layer 4) http_front, 80, http_back. /haproxy?stats .
.
HAProxy , .
, . :
- Roundrobin: . , . , .
- Leastconn: . . , LDAP, SQL, TSE . ., , HTTP.
- First: . , . maxconn, .
- Source: IP- , , . , IP- , .
(layer 7)
— (layer 7), , - . , , URL.
HAProxy :
sudo vi /etc/haproxy/haproxy.cfg
:
frontend http_front
bind *:80
stats uri /haproxy?stats
acl url_blog path_beg /blog
use_backend blog_back if url_blog
default_backend http_back
backend http_back
balance roundrobin
server server_name1 private_ip1:80 check
server server_name2 private_ip2:80 check
backend blog_back
server server_name3 private_ip3:80 check
ACL url_blog, , /blog. Use_backend , , url_blog, blog_back, .
: http_back, , , blog_back, example.com/blog.
HAProxy :
sudo systemctl restart haproxy
- , , , .
HAProxy , IP- , . stats uri .
http://load_balancer_public_ip/haproxy?stats
, , !
-, / . , , .
, , HTTP- . , HAProxy :
sudo systemctl status haproxy
, , , . , haproxy.cfg. username password - :
listen stats
bind *:8181
stats enable
stats uri /
stats realm Haproxy\ Statistics
stats auth username:password
stats uri . , HAProxy.
sudo systemctl restart haproxy
, .
http://load_balancer_public_ip:8181
, - , IP - .
http://load_balancer_public_ip/
: HAProxy
HAProxy! -. HAProxy, , , . , HAProxy, .
- , . , IP . IP- UpCloud.
« Linux. »***