haproxy.jpg
编译环境:centos7.9
依赖安装:

yum install curl gcc gcc-c++ openssl openssl-devel pcre-devel bzip2-devel systemd-devel

离线安装:

yum localinstall *.rpm -y

创建无home也无法登录的用户:

useradd -s /sbin/nologin -M haproxy

下载解压:

curl —progress https://codeload.github.com/haproxy/haproxy/tar.gz/refs/tags/v2.5.0 | tar xz
cd haproxy-2.5.0
uname -a
make TARGET=linux310 ARCH=x86_64 USE_SYSTEMD=1 USE_CPU_AFFINITY=1 USE_PCRE=1 USE_OPENSSL=1 USE_ZLIB=1
make install
cp haproxy /usr/sbin/
mkdir -p /usr/local/haproxy/log
touch /usr/local/haproxy/log/haproxy.log

# USE_PCRE=1 开启正则 USE_OPENSSL=1 开启openssl USE_ZLIB=1
# # USE_CPU_AFFINITY=1 为开启haproxy进程与CPU核心绑定,USE_SYSTEMD=1为支持使用 -Ws参数(systemd-aware master-worker 模式)启动Haproxy,从而实现单主进程多子进程运行模式。
可以使用PREFIX=/usr/local/haproxy指定安装位置
默认安装位置:/usr/local/sbin/haproxy
卸载:make uninstall
准备系统启动脚本

cp examples/haproxy.init /etc/init.d/haproxy
chmod 755 /etc/init.d/haproxy
chkconfig —add haproxy
make -C admin/systemd/
cp admin/systemd/haproxy.service /lib/systemd/system/haproxy.service

系统配置文件:

vi /etc/sysconfig/haproxy
# 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=””

配置各个负载的内核参数:

vim /etc/sysctl.conf
net.ipv4.ip_nonlocal_bind=1
#开启允许绑定非本机的IP,haporxy启动忽视VIP存在
net.ipv4.ip_forward=1
#内核是否转发数据包

配置内核参数生效:sysctl -p
配置文件:

mkdir /etc/haproxy
mkdir /var/lib/haproxy
mkdir /etc/haproxy/conf

复制配置文件:

cp examples/basic-config-edge.cfg /etc/haproxy/haproxy.cfg

配置文件:
离线安装打包编译haproxy-2.5.0 - 图2
离线安装打包编译haproxy-2.5.0 - 图3
统计页面查看:IP:8181
离线安装打包编译haproxy-2.5.0 - 图4
参考文献:
https://blog.csdn.net/sinat_37719426/article/details/119710983
https://www.cnblogs.com/wangxu01/articles/11196522.html#top