CentOS7源码安装部署haproxy-2.1.10


下载haproxy-2.1.10、lua-5.3.5

[root@node03 ~]# wget -c https://www.haproxy.org/download/2.1/src/haproxy-2.1.10.tar.gz
[root@node03 ~]# wget -c https://www.lua.org/ftp/lua-5.3.5.tar.gz

编译安装lua-5.3.5

[root@node03 ~]# cd /usr/local/src/lua-5.3.5/
[root@node03 lua-5.3.5]# make linux
[root@node03 lua-5.3.5]# make install INSTALL_TOP=/usr/local/lua
[root@node03 lua-5.3.5]# /usr/local/lua/bin/lua -v
Lua 5.3.5 Copyright (C) 1994-2018 Lua.org, PUC-Rio

编译安装haproxy-2.1.10

[root@node03 ~]# tar xf haproxy-2.1.10.tar.gz -C /usr/local/src/
[root@node03 ~]# cd /usr/local/src/haproxy-2.1.10/
[root@node03 haproxy-2.1.10]# make USE_NS=1 USE_TFO=1 USE_OPENSSL=1 USE_ZLIB=1 USE_LUA=1 USE_PCRE=1 USE_SYSTEMD=1 USE_LIBCRYPT=1 USE_THREAD=1 TARGET=linux-glibc LUA_INC=/usr/local/lua/include LUA_LIB=/usr/local/lua/lib
[root@node03 haproxy-2.1.10]# make install PREFIX=/usr/local/haproxy

提供haproxy-2.1.10 系统启动服务脚本

[root@node03 haproxy-2.1.10]# vim /usr/lib/systemd/haproxy.service
[Unit]

Description=HAProxy Load Balancer

After=syslog.target network.target



[Service]

ExecStart=/usr/local/haproxy/sbin/haproxy -Ws -f /etc/haproxy/haproxy.cfg -p /run/haproxy.pid

ExecReload=/bin/kill -USR2 $MAINPID

KillMode=mixed



[Install]

WantedBy=multi-user.target

提供haproxy-2.1.10服务配置文件

[root@node03 ~]# vim /etc/haproxy/haproxy.cfg 
#---------------------------------------------------------------------

# Global settings

#---------------------------------------------------------------------

global

log 127.0.0.1 local2



chroot /usr/local/haproxy

pidfile /var/run/haproxy.pid

maxconn 4000

user haproxy

group haproxy

daemon



# turn on stats unix socket

stats socket /usr/local/haproxy/haproxy.sock



#---------------------------------------------------------------------

# common defaults that all the 'listen' and 'backend' sections will

# use if not designated in their block

#---------------------------------------------------------------------

defaults

mode http

log global

option httplog

option dontlognull

option http-server-close

option forwardfor except 127.0.0.0/8

option redispatch

retries 3

timeout http-request 10s

timeout queue 1m

timeout connect 10s

timeout client 1m

timeout server 1m

timeout http-keep-alive 10s

timeout check 10s

maxconn 3000



#---------------------------------------------------------------------

# main frontend which proxys to the backends

#---------------------------------------------------------------------

frontend main *:5000

acl url_static path_beg -i /static /images /javascript /stylesheets

acl url_static path_end -i .jpg .gif .png .css .js



use_backend static if url_static

default_backend app

#---------------------------------------------------------------------

# static backend for serving up images, stylesheets and such

#---------------------------------------------------------------------

backend static

balance roundrobin

server static 127.0.0.1:4331 check

#---------------------------------------------------------------------

# round robin balancing between the various backends

#---------------------------------------------------------------------

启动HAProxy

[root@node03 ~]# systemctl daemon-reload
[root@node03 ~]# systemctl enable --now haproxy
[root@node03 ~]# systemctl is-active haproxy
active
[root@node03 ~]# systemctl is-enabled haproxy
enabled

参考:​​CentOS7源码安装部署HAProxy-1.9.7​​