首页 运维杂谈HAProxy-安装及基础配置

HAProxy-安装及基础配置

运维派隶属马哥教育旗下专业运维社区,是国内成立最早的IT运维技术社区,欢迎关注公众号:yunweipai
领取学习更多免费Linux云计算、Python、Docker、K8s教程关注公众号:马哥linux运维

Ubuntu安装

HAProxy-安装及基础配置插图

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

HAProxy-安装及基础配置插图(1)

[root@ubuntu1804 ~]#apt-get install software-properties-common
[root@ubuntu1804 ~]#add-apt-repository ppa:vbernat/haproxy-2.0
[root@ubuntu1804 ~]#apt  update
[root@ubuntu1804 ~]#apt-cache madison haproxy
[root@ubuntu1804 ~]#apt install haproxy=2.0.4-1ppa1~bionic
#或安装最新版
[root@ubuntu1804 ~]#apt-get install haproxy=2.0.\*

#验证haproxy版本
[root@ubuntu1804 ~]#haproxy  -v 

范例:

[root@ubuntu1804 ~]#apt-get install 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 252 not upgraded.
Need to get 33.6 kB of archives.
After this operation, 13.3 kB of additional disk space will be used.
Do you want to continue? [Y/n] y
Get:1 http://mirrors.aliyun.com/ubuntu bionic-updates/main amd64 software-properties-common all 0.96.24.32.12 [10.0 kB]
Get:2 http://mirrors.aliyun.com/ubuntu bionic-updates/main amd64 python3-software-properties all 0.96.24.32.12 [23.6 kB]
Fetched 33.6 kB in 5s (6,528 B/s)                 
(Reading database ... 71030 files and directories currently installed.)
Preparing to unpack .../software-properties-common_0.96.24.32.12_all.deb ...
Unpacking software-properties-common (0.96.24.32.12) over (0.96.24.32.4) ...
Preparing to unpack .../python3-software-properties_0.96.24.32.12_all.deb ...
Unpacking python3-software-properties (0.96.24.32.12) over (0.96.24.32.4) ...
Processing triggers for man-db (2.8.3-2) ...
Setting up python3-software-properties (0.96.24.32.12) ...
Processing triggers for dbus (1.12.2-1ubuntu1) ...
Setting up software-properties-common (0.96.24.32.12) ...

[root@ubuntu1804 ~]#add-apt-repository ppa:vbernat/haproxy-2.0
 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.0.
 More info: https://launchpad.net/~vbernat/+archive/ubuntu/haproxy-2.0
Press [ENTER] to continue or Ctrl-c to cancel adding it.
Hit:1 http://mirrors.aliyun.com/ubuntu bionic InRelease
Hit:2 http://mirrors.aliyun.com/ubuntu bionic-security InRelease
Hit:3 http://mirrors.aliyun.com/ubuntu bionic-updates InRelease                           
Hit:4 http://mirrors.aliyun.com/ubuntu bionic-proposed InRelease                         
Hit:5 http://mirrors.aliyun.com/ubuntu bionic-backports InRelease                         
Get:6 http://ppa.launchpad.net/vbernat/haproxy-2.0/ubuntu bionic InRelease [20.7 kB]     
Get:7 http://ppa.launchpad.net/vbernat/haproxy-2.0/ubuntu bionic/main i386 Packages [984 B]
Get:8 http://ppa.launchpad.net/vbernat/haproxy-2.0/ubuntu bionic/main amd64 Packages [988 B]
Get:9 http://ppa.launchpad.net/vbernat/haproxy-2.0/ubuntu bionic/main Translation-en [704 B]
Fetched 23.4 kB in 6s (3,971 B/s)       
Reading package lists... Done

[root@ubuntu1804 ~]# apt-get update
Hit:1 http://mirrors.aliyun.com/ubuntu bionic InRelease
Hit:2 http://mirrors.aliyun.com/ubuntu bionic-security InRelease                         
Hit:3 http://mirrors.aliyun.com/ubuntu bionic-updates InRelease                           
Hit:4 http://mirrors.aliyun.com/ubuntu bionic-proposed InRelease                         
Hit:5 http://mirrors.aliyun.com/ubuntu bionic-backports InRelease                         
Hit:6 http://ppa.launchpad.net/vbernat/haproxy-2.0/ubuntu bionic InRelease               
Reading package lists... Done

[root@ubuntu1804 ~]#apt-get install haproxy=2.0.\*
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Selected version '2.0.13-1ppa1~bionic' (HAProxy 2.0: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 252 not upgraded.
Need to get 1,526 kB/1,819 kB of archives.
After this operation, 4,246 kB of additional disk space will be used.
Do you want to continue? [Y/n] y
Get:1 http://ppa.launchpad.net/vbernat/haproxy-2.0/ubuntu bionic/main amd64 haproxy amd64 2.0.13-1ppa1~bionic [1,526 kB]
Fetched 572 kB in 26s (22.1 kB/s)                                                         
Selecting previously unselected package liblua5.3-0:amd64.
(Reading database ... 71032 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.0.13-1ppa1~bionic_amd64.deb ...
Unpacking haproxy (2.0.13-1ppa1~bionic) ...
Processing triggers for ureadahead (0.100.0-20) ...
Processing triggers for libc-bin (2.27-3ubuntu1) ...
Processing triggers for systemd (237-3ubuntu10.3) ...
Processing triggers for man-db (2.8.3-2) ...
Setting up libpcre2-8-0:amd64 (10.31-2) ...
Setting up liblua5.3-0:amd64 (5.3.3-1ubuntu0.18.04.1) ...
Processing triggers for rsyslog (8.32.0-1ubuntu4) ...
Setting up haproxy (2.0.13-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) ...
Processing triggers for ureadahead (0.100.0-20) ...
Processing triggers for systemd (237-3ubuntu10.3) ...
Processing triggers for rsyslog (8.32.0-1ubuntu4) ...
[root@ubuntu1804 ~]#apt-cache madison haproxy
   haproxy | 2.0.13-1ppa1~bionic | http://ppa.launchpad.net/vbernat/haproxy-2.0/ubuntu bionic/main amd64 Packages
   haproxy | 1.8.8-1ubuntu0.9 | http://mirrors.aliyun.com/ubuntu bionic-security/main amd64 Packages
   haproxy | 1.8.8-1ubuntu0.9 | http://mirrors.aliyun.com/ubuntu bionic-updates/main amd64 Packages
   haproxy |    1.8.8-1 | http://mirrors.aliyun.com/ubuntu bionic/main amd64 Packages
   haproxy |    1.8.8-1 | http://mirrors.aliyun.com/ubuntu bionic/main Sources
   haproxy | 1.8.8-1ubuntu0.9 | http://mirrors.aliyun.com/ubuntu bionic-security/main Sources
   haproxy | 1.8.8-1ubuntu0.9 | http://mirrors.aliyun.com/ubuntu bionic-updates/main Sources

[root@ubuntu1804 ~]#haproxy  -v
HA-Proxy version 2.0.13-1ppa1~bionic 2020/02/15 - https://haproxy.org/

Centos 安装

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

默认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>

范例:CentOS 8 安装haproxy

[root@centos8 ~]#dnf -y install haproxy
[root@centos8 ~]#haproxy -v
HA-Proxy version 1.8.15 2018/12/13
Copyright 2000-2018 Willy Tarreau <willy@haproxy.org>
[root@centos8 ~]#haproxy -vv
HA-Proxy version 1.8.15 2018/12/13
Copyright 2000-2018 Willy Tarreau <willy@haproxy.org>

Build options :
  TARGET  = linux2628
  CPU     = generic
  CC      = gcc
  CFLAGS  = -O2 -g -fno-strict-aliasing -Wdeclaration-after-statement -fwrapv -Wno-format-truncation -Wno-null-dereference -Wno-unused-label
  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.1 FIPS  11 Sep 2018
Running on OpenSSL version : OpenSSL 1.1.1c FIPS  28 May 2019
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

第三方安装包

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

HAProxy-安装及基础配置插图(2)

HAProxy-安装及基础配置插图(3)

范例:基于互联网在线安装

#wget http://www.nosuchhost.net/~cheese/fedora/packages/epel-7/x86_64/cheese-release-7-1.noarch.rpm
# rpm -ivh cheese-release-7-1.noarch.rpm
# yum install haproxy

#验证haproxy版本
# haproxy  -v
HA-Proxy version 1.8.14-52e4d43 2018/09/20
Copyright 2000-2018 Willy Tarreau <willy@haproxy.org>

HAProxy-安装及基础配置插图(4)

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

[root@centos7 ~]#wget https://centos7.iuscommunity.org/ius-release.rpm
[root@centos7 ~]#rpm -Uvh ius-release*rpm
[root@centos7 ~]#yum -y install epel-release
[root@centos7 ~]#rpm -Uvh ius-release*rpm
[root@centos7 ~]#yum install haproxy18u
[root@centos7 ~]#haproxy  -v
HA-Proxy version 1.8.23 2019/11/25
Copyright 2000-2019 Willy Tarreau <willy@haproxy.org>

范例:下载rpm安装

#下载安装lua库对应的版本
[root@centos7 ~]#wget https://dl.iuscommunity.org/pub/ius/stable/CentOS/7/x86_64/lua53u-libs-5.3.4-1.ius.centos7.x86_64.rpm
#安装lua库
[root@centos7 ~]#yum -y install lua53u-libs-5.3.4-1.ius.centos7.x86_64.rpm

#下载haproxy
[root@centos7 ~]#wget https://dl.iuscommunity.org/pub/ius/stable/CentOS/7/x86_64/haproxy18u-1.8.20-1.el7.ius.x86_64.rpm

#安装haproxy
[root@centos7 ~]#yum -y install haproxy18u-1.8.20-1.el7.ius.x86_64.rpm
[root@centos7 ~]#haproxy  -v
HA-Proxy version 1.8.20 2019/04/25
Copyright 2000-2019 Willy Tarreau <willy@haproxy.org>

[root@centos7 ~]#systemctl start haproxy
[root@centos7 ~]#systemctl status haproxy.service 
● haproxy.service - HAProxy Load Balancer
   Loaded: loaded (/usr/lib/systemd/system/haproxy.service; disabled; vendor preset: disabled)
   Active: active (running) since Mon 2020-03-30 21:17:23 CST; 56s ago
  Process: 1257 ExecStartPre=/usr/sbin/haproxy -f $CONFIG -c -q (code=exited, status=0/SUCCESS)
 Main PID: 1258 (haproxy)
   CGroup: /system.slice/haproxy.service
           ├─1258 /usr/sbin/haproxy -Ws -f /etc/haproxy/haproxy.cfg -p /run/haproxy.pid
           └─1260 /usr/sbin/haproxy -Ws -f /etc/haproxy/haproxy.cfg -p /run/haproxy.pid

Mar 30 21:17:23 centos7.wangxiaochun.com systemd[1]: Starting HAProxy Load Balancer...
Mar 30 21:17:23 centos7.wangxiaochun.com systemd[1]: Started HAProxy Load Balancer.

本文链接:http://www.yunweipai.com/35245.html

网友评论comments

发表评论

邮箱地址不会被公开。

暂无评论

Copyright © 2012-2021 YUNWEIPAI.COM - 运维派 京ICP备16064699号-6
扫二维码
扫二维码
返回顶部