3.1 Ubuntu安装

打开链接:https://haproxy.debian.net/,选择合适的版本,会自动出现下面安装提示

[root@ubuntu1804 ~]# apt-get install --no-install-recommends software-properties-common
[root@ubuntu1804 ~]# add-apt-repository ppa:vbernat/haproxy-2.4 # 过程中记得回车
[root@ubuntu1804 ~]# apt-get install haproxy=2.4.\*

# 验证haproxy版本
[root@ubuntu1804 ~]# haproxy -v
HAProxy version 2.4.3-1ppa1~bionic 2021/08/21 - https://haproxy.org/
Status: long-term supported branch - will stop receiving fixes around Q2 2026.
Known bugs: http://www.haproxy.org/bugs/bugs-2.4.3.html
Running on: Linux 4.15.0-112-generic #113-Ubuntu SMP Thu Jul 9 23:41:39 UTC 2020 x86_64

例:

[root@ubuntu1804 ~]# apt-get install --no-install-recommends software-properties-common
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following additional packages will be installed:
  python3-software-properties
The following packages will be upgraded:
  python3-software-properties software-properties-common
2 upgraded, 0 newly installed, 0 to remove and 155 not upgraded.
Need to get 33.9 kB of archives.
After this operation, 0 B of additional disk space will be used.
Do you want to continue? [Y/n] y
Get:1 http://us.archive.ubuntu.com/ubuntu bionic-updates/main amd64 software-properties-common all 0.96.24.32.14 [10.1 kB]
Get:2 http://us.archive.ubuntu.com/ubuntu bionic-updates/main amd64 python3-software-properties all 0.96.24.32.14 [23.9 kB]
Fetched 33.9 kB in 1s (34.7 kB/s)                      
(Reading database ... 67375 files and directories currently installed.)
Preparing to unpack .../software-properties-common_0.96.24.32.14_all.deb ...
Unpacking software-properties-common (0.96.24.32.14) over (0.96.24.32.13) ...
Preparing to unpack .../python3-software-properties_0.96.24.32.14_all.deb ...
Unpacking python3-software-properties (0.96.24.32.14) over (0.96.24.32.13) ...
Setting up python3-software-properties (0.96.24.32.14) ...
Setting up software-properties-common (0.96.24.32.14) ...
Processing triggers for dbus (1.12.2-1ubuntu1.2) ...
Processing triggers for man-db (2.8.3-2ubuntu0.1) ...
[root@ubuntu1804 ~]# add-apt-repository ppa:vbernat/haproxy-2.4
 HAProxy is a free, very fast and reliable solution offering high availability, load balancing, and proxying for TCP and HTTP-based applications. It is particularly suited for web sites crawling under very high loads while needing persistence or Layer7 processing. Supporting tens of thousands of connections is clearly realistic with todays hardware. Its mode of operation makes its integration into existing architectures very easy and riskless, while still offering the possibility not to expose fragile web servers to the Net.

This PPA contains packages for HAProxy 2.4.
 More info: https://launchpad.net/~vbernat/+archive/ubuntu/haproxy-2.4
Press [ENTER] to continue or Ctrl-c to cancel adding it.    # 这里记得需要回车

Get:1 http://ppa.launchpad.net/vbernat/haproxy-2.4/ubuntu bionic InRelease [20.8 kB]
Hit:2 http://security.ubuntu.com/ubuntu bionic-security InRelease               
Hit:3 http://us.archive.ubuntu.com/ubuntu bionic InRelease                              
Hit:4 http://us.archive.ubuntu.com/ubuntu bionic-updates InRelease                      
Get:5 http://ppa.launchpad.net/vbernat/haproxy-2.4/ubuntu bionic/main i386 Packages [976 B]
Hit:6 http://us.archive.ubuntu.com/ubuntu bionic-backports InRelease                    
Get:7 http://ppa.launchpad.net/vbernat/haproxy-2.4/ubuntu bionic/main amd64 Packages [972 B]
Get:8 http://ppa.launchpad.net/vbernat/haproxy-2.4/ubuntu bionic/main Translation-en [704 B]
Fetched 23.4 kB in 3s (7,903 B/s)       
Reading package lists... Done
[root@ubuntu1804 ~]# apt-get install haproxy=2.4.\*
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Selected version '2.4.3-1ppa1~bionic' (HAProxy 2.4:18.04/bionic [amd64]) for 'haproxy'
The following additional packages will be installed:
  liblua5.3-0 libpcre2-8-0
Suggested packages:
  vim-haproxy haproxy-doc
The following NEW packages will be installed:
  haproxy liblua5.3-0 libpcre2-8-0
0 upgraded, 3 newly installed, 0 to remove and 155 not upgraded.
Need to get 1,864 kB of archives.
After this operation, 4,684 kB of additional disk space will be used.
Do you want to continue? [Y/n] y
Get:1 http://us.archive.ubuntu.com/ubuntu bionic-updates/main amd64 liblua5.3-0 amd64 5.3.3-1ubuntu0.18.04.1 [115 kB]
Get:2 http://ppa.launchpad.net/vbernat/haproxy-2.4/ubuntu bionic/main amd64 haproxy amd64 2.4.3-1ppa1~bionic [1,570 kB]
Get:3 http://us.archive.ubuntu.com/ubuntu bionic/universe amd64 libpcre2-8-0 amd64 10.31-2 [179 kB]
Fetched 1,864 kB in 9s (212 kB/s)                                                        
Selecting previously unselected package liblua5.3-0:amd64.
(Reading database ... 67375 files and directories currently installed.)
Preparing to unpack .../liblua5.3-0_5.3.3-1ubuntu0.18.04.1_amd64.deb ...
Unpacking liblua5.3-0:amd64 (5.3.3-1ubuntu0.18.04.1) ...
Selecting previously unselected package libpcre2-8-0:amd64.
Preparing to unpack .../libpcre2-8-0_10.31-2_amd64.deb ...
Unpacking libpcre2-8-0:amd64 (10.31-2) ...
Selecting previously unselected package haproxy.
Preparing to unpack .../haproxy_2.4.3-1ppa1~bionic_amd64.deb ...
Unpacking haproxy (2.4.3-1ppa1~bionic) ...
Setting up libpcre2-8-0:amd64 (10.31-2) ...
Setting up liblua5.3-0:amd64 (5.3.3-1ubuntu0.18.04.1) ...
Setting up haproxy (2.4.3-1ppa1~bionic) ...
Created symlink /etc/systemd/system/multi-user.target.wants/haproxy.service → /lib/systemd/system/haproxy.service.
Processing triggers for libc-bin (2.27-3ubuntu1.2) ...
Processing triggers for systemd (237-3ubuntu10.42) ...
Processing triggers for man-db (2.8.3-2ubuntu0.1) ...
Processing triggers for rsyslog (8.32.0-1ubuntu4) ...
Processing triggers for ureadahead (0.100.0-21) ...
[root@ubuntu1804 ~]# haproxy -v
HAProxy version 2.4.3-1ppa1~bionic 2021/08/21 - https://haproxy.org/
Status: long-term supported branch - will stop receiving fixes around Q2 2026.
Known bugs: http://www.haproxy.org/bugs/bugs-2.4.3.html
Running on: Linux 4.15.0-112-generic #113-Ubuntu SMP Thu Jul 9 23:41:39 UTC 2020 x86_64

3.2 centos安装

在centos系统上通过yum、编译等多种安装方式

3.2.1 系统默认yum源

CentOS 7 默认的base仓库中包含haproxy的安装包文件,但是版本比较旧,是1.5.18的版本,距离当前版本已经有较长时间没有更新,由于版本比较旧所以有很多功能不支持,如果对功能和性能没有要求可以使用此版本,否则推荐使用新版本。

例:centos 7安装haproxy

[root@centos7 ~]# yum install haproxy -y

# 验证haproxy版本
[root@centos7 ~]# haproxy -v
HA-Proxy version 1.5.18 2016/05/10
Copyright 2000-2016 Willy Tarreau <willy@haproxy.org>

[root@centos7 ~]# 

例:centos8安装haproxy

[root@centos8 ~]# dnf install haproxy -y

[root@centos8 ~]# haproxy -v
HA-Proxy version 1.8.27-493ce0b 2020/11/06
Copyright 2000-2020 Willy Tarreau <willy@haproxy.org>

[root@centos8 ~]# haproxy -vv
HA-Proxy version 1.8.27-493ce0b 2020/11/06
Copyright 2000-2020 Willy Tarreau <willy@haproxy.org>

Build options :
  TARGET  = linux2628
  CPU     = generic
  CC      = gcc
  CFLAGS  = -O2 -g -fno-strict-aliasing -Wdeclaration-after-statement -fwrapv -Wno-null-dereference -Wno-unused-label -Wno-stringop-overflow
  OPTIONS = USE_LINUX_TPROXY=1 USE_CRYPT_H=1 USE_GETADDRINFO=1 USE_ZLIB=1 USE_REGPARM=1 USE_OPENSSL=1 USE_LUA=1 USE_SYSTEMD=1 USE_PCRE=1

Default settings :
  maxconn = 2000, bufsize = 16384, maxrewrite = 1024, maxpollevents = 200

Built with OpenSSL version : OpenSSL 1.1.1g FIPS  21 Apr 2020
Running on OpenSSL version : OpenSSL 1.1.1g FIPS  21 Apr 2020
OpenSSL library supports TLS extensions : yes
OpenSSL library supports SNI : yes
OpenSSL library supports : TLSv1.0 TLSv1.1 TLSv1.2 TLSv1.3
Built with Lua version : Lua 5.3.4
Built with transparent proxy support using: IP_TRANSPARENT IPV6_TRANSPARENT IP_FREEBIND
Encrypted password support via crypt(3): yes
Built with multi-threading support.
Built with PCRE version : 8.42 2018-03-20
Running on PCRE version : 8.42 2018-03-20
PCRE library supports JIT : no (USE_PCRE_JIT not set)
Built with zlib version : 1.2.11
Running on zlib version : 1.2.11
Compression algorithms supported : identity("identity"), deflate("deflate"), raw-deflate("deflate"), gzip("gzip")
Built with network namespace support.

Available polling systems :
      epoll : pref=300,  test result OK
       poll : pref=200,  test result OK
     select : pref=150,  test result OK
Total: 3 (3 usable), will use epoll.

Available filters :
        [SPOE] spoe
        [COMP] compression
        [TRACE] trace

[root@centos8 ~]# 

3.2.2 第三方安装包

官方没有提供rpm相关的包,可以通过第三方仓库的rpm包

从第三方网站下载rpm包:https://pkgs.org/download/haproxy

例:基于互联网第三方仓库在线安装

# wget https://repo.ius.io/7/x86_64/packages/h/haproxy22-2.2.10-1.el7.ius.x86_64.rpm
# rpm -Uvh haproxy22-2.2.10-1.el7.ius.x86_64.rpm
# yum install haroxy22

# 验证haproxy版本
# haproxy -v
HA-Proxy version 2.2.10-6a09215 2021/03/03 - https://haproxy.org/
Status: long-term supported branch - will stop receiving fixes around Q2 2025.
Known bugs: http://www.haproxy.org/bugs/bugs-2.2.10.html
Running on: Linux 3.10.0-1160.el7.x86_64 #1 SMP Mon Oct 19 16:18:59 UTC 2020 x86_64

例:利用第三方yum仓库安装

[root@centos7 ~]# wget https://repo.ius.io/ius-release-el7.rpm
[root@centos7 ~]# rpm -Uvh ius-release-el7.rpm
[root@centos7 ~]# yum install epel-release -y
[root@centos7 ~]# rpm -Uvh ius-release-el7.rpm
[root@centos7 ~]# yum install haproxy22 -y
[root@centos7 ~]# haproxy -v
HA-Proxy version 2.2.10-6a09215 2021/03/03 - https://haproxy.org/
Status: long-term supported branch - will stop receiving fixes around Q2 2025.
Known bugs: http://www.haproxy.org/bugs/bugs-2.2.10.html
Running on: Linux 3.10.0-1160.el7.x86_64 #1 SMP Mon Oct 19 16:18:59 UTC 2020 x86_64

例:下载rpm离线安装

# 下载安装lua库对应的版本,从该页面就可以看到
[root@centos7 ~]# wget https://repo.ius.io/7/x86_64/packages/l/lua53u-libs-5.3.4-1.ius.el7.x86_64.rpm

# 安装lua库
[root@centos7 ~]# yum install lua53u-libs-5.3.4-1.ius.el7.x86_64.rpm -y

# 下载haproxy
[root@centos7 ~]# wget https://repo.ius.io/7/x86_64/packages/h/haproxy22-2.2.10-1.el7.ius.x86_64.rpm

# 安装haproxy
[root@centos7 ~]# yum install haproxy22-2.2.10-1.el7.ius.x86_64.rpm -y

# 查看版本
[root@centos7 ~]# haproxy -v
HA-Proxy version 2.2.10-6a09215 2021/03/03 - https://haproxy.org/
Status: long-term supported branch - will stop receiving fixes around Q2 2025.
Known bugs: http://www.haproxy.org/bugs/bugs-2.2.10.html
Running on: Linux 3.10.0-1160.el7.x86_64 #1 SMP Mon Oct 19 16:18:59 UTC 2020 x86_64

[root@centos7 ~]# systemctl start haproxy
[root@centos7 ~]# systemctl status haproxy
● haproxy.service - HAProxy Load Balancer
   Loaded: loaded (/usr/lib/systemd/system/haproxy.service; disabled; vendor preset: disabled)
   Active: active (running) since Tue 2021-08-24 09:16:03 CST; 7s ago
  Process: 1420 ExecStartPre=/usr/sbin/haproxy -f $CONFIG -c -q $OPTIONS (code=exited, status=0/SUCCESS)
 Main PID: 1425 (haproxy)
   CGroup: /system.slice/haproxy.service
           ├─1425 /usr/sbin/haproxy -Ws -f /etc/haproxy/haproxy.cfg -p /run/haproxy....
           └─1427 /usr/sbin/haproxy -Ws -f /etc/haproxy/haproxy.cfg -p /run/haproxy....

Aug 24 09:16:03 centos7.waluna.top systemd[1]: Started HAProxy Load Balancer.
Aug 24 09:16:03 centos7.waluna.top haproxy[1425]: [WARNING] 235/091603 (1427) : Ser....
Aug 24 09:16:03 centos7.waluna.top haproxy[1425]: [NOTICE] 235/091603 (1427) : hapr...5
Aug 24 09:16:03 centos7.waluna.top haproxy[1425]: [NOTICE] 235/091603 (1427) : path...y
Aug 24 09:16:03 centos7.waluna.top haproxy[1425]: [ALERT] 235/091603 (1427) : backe...!
Aug 24 09:16:03 centos7.waluna.top haproxy[1425]: [WARNING] 235/091603 (1427) : Ser....
Aug 24 09:16:04 centos7.waluna.top haproxy[1425]: [WARNING] 235/091604 (1427) : Ser....
Aug 24 09:16:04 centos7.waluna.top haproxy[1425]: [WARNING] 235/091604 (1427) : Ser....
Aug 24 09:16:05 centos7.waluna.top haproxy[1425]: [WARNING] 235/091605 (1427) : Ser....
Aug 24 09:16:05 centos7.waluna.top haproxy[1425]: [ALERT] 235/091605 (1427) : backe...!
Hint: Some lines were ellipsized, use -l to show in full.