harproxy
安装依赖包
apt update && apt -y install gcc make libssl-dev libpcre3
libpcre3-dev zlib1g-dev libreadline-dev libsystemd-dev liblua5.3-dev
下载
[root@ubuntu2204 ~]#wget http://www.haproxy.org/download/2.8/src/haproxy-
2.8.0.tar.gz
编译安装
[root@ubuntu2204 ~]#tar xf haproxy-2.8.0.tar.gz;cd haproxy-2.8.0/
make ARCH=x86_64 TARGET=linux-glibc USE_PCRE=1 USE_OPENSSL=1 USE_ZLIB=1 USE_SYSTEMD=1 USE_PROMEX=1 USE_LUA=1 LUA_LIB_NAME=lua5.3
make install PREFIX=/apps/haproxy
haproxy配置文件
mkdir /etc/haproxy -p
root@ubuntu20:/etc/haproxy# vi haproxy.cfg
global
maxconn 100000
chroot /apps/haproxy
stats socket /var/lib/haproxy/haproxy.sock mode 600 level admin
#uid 99
#gid 99
user haproxy
group haproxy
daemon
#nbproc 4
#cpu-map 1 0
#cpu-map 2 1
#cpu-map 3 2
#cpu-map 4 3
#pidfile /var/lib/haproxy/haproxy.pid
log 127.0.0.1 local2 info
defaults
option http-keep-alive
option forwardfor
maxconn 100000
mode http
timeout connect 300000ms
timeout client 300000ms
timeout server 300000ms
listen stats
mode http
bind 0.0.0.0:9999
stats enable
log global
stats uri /haproxy-status
stats auth admin:123456
检测配置文件
root@ubuntu20:/etc/haproxy# /apps/haproxy/sbin/haproxy -c -f /etc/haproxy/haproxy.cfg
Configuration file is valid
创建用户
useradd -m -r -s /sbin/nologin -d /var/lib/haproxy haproxy
service文件配置
cat > /lib/systemd/system/haproxy.service <<-EOF
[Unit]
Description=HAProxy Load Balancer
After=syslog.target network.target
[Service]
ExecStartPre=/usr/sbin/haproxy -f /etc/haproxy/haproxy.cfg -c -q
ExecStart=/usr/sbin/haproxy -Ws -f /etc/haproxy/haproxy.cfg -p /var/lib/haproxy/haproxy.pid
ExecReload=/bin/kill -USR2 \$MAINPID
[Install]
WantedBy=multi-user.target
EOF
启动haproxy
systemctl start haproxy
访问页面
http://192.168.1.120:9999/haproxy-status