Ubuntu18.04 apt installation 2.0.4
Centos7.6 Yum install 1.8.14
Centos7.6 compile and install haproxy2.0.12
<H6 id = 1> Ubuntu18.04 apt installation 2.0.4 </ h6>
Ubuntu @ root: ~ # apt-get install software-properties-common
# install common software packages
Reading package lists... Done
Building dependency tree
Reading state information... Done
software-properties-common is already the newest version (0.96.24.32.12).
0 upgraded, 0 newly installed, 0 to remove and 1 not upgraded.
Ubuntu @ root: ~ # add-apt-repository ppa:vbernat/haproxy-2.0
# add the latest version of haproxy2.0 to a local warehouse
root@ubuntu:~# 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.
##这里需要手动ENTENR确认后才会据需安装包
Get:1 http://ppa.launchpad.net/vbernat/haproxy-2.0/ubuntu bionic InRelease [20.7 kB]
Hit:2 http://mirrors.aliyun.com/ubuntu bionic InRelease
Hit:3 http://mirrors.aliyun.com/ubuntu bionic-security InRelease
Hit:4 http://mirrors.aliyun.com/ubuntu bionic-updates InRelease
...
Ubuntu @ root: ~ # apt update
# upgrade the local repository, all operations related to change the package, you need to do this
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 [9
...
Ubuntu @ root: ~ # apt-cache madison haproxy
# look at the warehouse haproxy · What version can be installed
root@ubuntu:~# apt-cache madison haproxy
haproxy | 2.0.12-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
Ubuntu @ root: ~ # apt install haproxy=2.0.4-1ppa1\~bionic
# install the selected version
Ubuntu @ root: ~ # haproxy -v
# version verification haproxy
HA-Proxy version 1.8.14-52e4d43 2018/09/20
Copyright 2000-2018 Willy Tarreau <[email protected]>
Ubuntu @ root: ~ # systemctl start haproxy
# start haproxy
<H6 id = 2> Centos7.6 Yum mounted 1.8.14 </ h6>
By default centos7 package are older haproxy is 1.5.18-9.el7, less meet the demand, then we can install a third-party installation package based on yum
https://pkgs.org/download/haproxy the URL el7 latest rpm package update to 1.8.14
Generally it requires a dependency warehouse pack installation package and haproxy.rpm
Download the installation package
wget https://centos.pkgs.org/7/cheese-x86_64/haproxy-1.8.14-1.el7.x86_64.rpm.html
Download dependencies
weget https://centos.pkgs.org/7/cheese-x86_64/cheese-release-7-1.noarch.rpm.html
Mounting the corresponding packet
#rpm -ivh cheese-release-7-1.noarch.rpm
#yum install haproxy-1.8.14-1.el7.x86_64.rpm -y
# Verify haproxy version
# haproxy -v
HA-Proxy version 1.8.14-52e4d43 2018/09/20
Copyright 2000-2018 Willy Tarreau <[email protected]>
<H6 id = 3> Centos7.6 compiler installation haproxy2.0.12 </ h6>
Compile and install HAProxy 2.0 LTS version, more source packages Download the official website: http://www.haproxy.org/download/
HAProxy supports lua expand the functions provide flexible expansion and customization capabilities for applications, due to the centos version comes with lua relatively low does not meet the minimum version required HAProxy lua (5.3) requirements, so you need to install the packages are built , lua official Download
https://www.lua.org/download.html
yun install the compiler environment
yum install libtermcap-devel ncurses-devel libevent-devel readline-devel wget make gcc-y
Download lua5.3.5
wget http://www.lua.org/ftp/lua-5.3.5.tar.gz
61% [===================================================> ] 187,197 8.29KB/s eta 25s
Unpack and compile Lua
[root @ localhost / usr / local / src] # tar xf lua-5.3.5.tar.gz -C .
[root @ localhost / usr / local / src] # cd lua-5.3.5
[root @ localhost /usr/local/src/lua-5.3.5]#cd src && make linux
...
gcc -std=gnu99 -O2 -Wall -Wextra -DLUA_COMPAT_5_2 -DLUA_USE_LINUX -c -o linit.o linit.c
ar rcu liblua.a lapi.o lcode.o lctype.o ldebug.o ldo.o ldump.o lfunc.o lgc.o llex.o lmem.o lobject.o lopcodes.o lparser.o lstate.o lstring.o ltable.o ltm.o lundump.o lvm.o lzio.o lauxlib.o lbaselib.o lbitlib.o lcorolib.o ldblib.o liolib.o lmathlib.o loslib.o lstrlib.o ltablib.o lutf8lib.o loadlib.o linit.o
ranlib liblua.a
gcc -std=gnu99 -O2 -Wall -Wextra -DLUA_COMPAT_5_2 -DLUA_USE_LINUX -c -o lua.o lua.c
gcc -std=gnu99 -o lua lua.o liblua.a -lm -Wl,-E -ldl -lreadline
gcc -std=gnu99 -O2 -Wall -Wextra -DLUA_COMPAT_5_2 -DLUA_USE_LINUX -c -o luac.o luac.c
gcc -std=gnu99 -o luac luac.o liblua.a -lm -Wl,-E -ldl -lreadline
make[1]: Leaving directory `/usr/local/src/lua-5.3.5/src'
Ultimately generate two executable files in the src
system version
[root@localhost /usr/local/src/lua-5.3.5/src]#lua -v
Lua 5.1.4 Copyright (C) 1994-2008 Lua.org, PUC-Rio
Compiled version
[root@localhost /usr/local/src/lua-5.3.5/src]#./lua -v
Lua 5.3.5 Copyright (C) 1994-2018 Lua.org, PUC-Rio
Compile and install HAProxy
Ready to install haproxy environment dependent
yum install gcc gcc-c++ glibc glibc-devel pcre pcre-devel openssl openssl-devel systemd-devel net-tools vim iotop bc zip unzip zlib-devel lrzsz tree screen lsof tcpdump wget ntpdate -y
#HAProxy 1.8 and 1.9 versions of the compiler parameters:
make ARCH=x86_64 TARGET=linux2628 USE_PCRE=1 USE_OPENSSL=1 USE_ZLIB=1 USE_SYSTEMD=1 USE_CPU_AFFINITY=1 PREFIX=/usr/local/haproxy
#HAProxy 2.0 compiler parameters:
[root@localhost /usr/local/src/haproxy-2.0.12]#make ARCH=x86_64 TARGET=linux-glibc USE_PCRE=1 USE_OPENSSL=1 USE_ZLIB=1 USE_SYSTEMD=1 USE_CPU_AFFINITY=1 USE_LUA=1 LUA_INC=/usr/local/src/lua-5.3.5/src/ LUA_LIB=/usr/local/src/lua-5.3.5/src/ PREFIX=/usr/local/haproxy
#该配置默认安装在/usr/local/haproxy目录下
...
CC src/dict.o
CC src/xprt_handshake.o
CC ebtree/ebtree.o
CC ebtree/eb32sctree.o
CC ebtree/eb32tree.o
CC ebtree/eb64tree.o
CC ebtree/ebmbtree.o
CC ebtree/ebsttree.o
CC ebtree/ebimtree.o
CC ebtree/ebistree.o
LD haproxy
...
This configuration is mounted to the # / usr / local / haproxy directory
[root@localhost /usr/local/src/haproxy-2.0.12]#make install PREFIX=/usr/local/haproxy
# Moved to the / usr / sbin / System Environment
[root @ localhost /usr/local/src/haproxy-2.0.12]#cp haproxy /usr/sbin/
# Verify haproxy version
[root @ localhost /usr/local/src/haproxy-2.0.12]#haproxy -v
HA-Proxy version 2.0.12 2019/12/21 - https://haproxy.org/
# Prepare HAProxy startup scripts
[root @ localhost / usr / local / src] #cat /usr/lib/systemd/system/haproxy.service
[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
# Associate with HA configuration file
# mkdir /etc/haproxy
# mkdir /var/lib/haproxy
#cat /etc/haproxy/haproxy.cfg
global
maxconn 100000
chroot /usr/local/haproxy
stats socket /var/lib/haproxy/haproxy.sock mode 600 level admin
#stats socket /var/lib/haproxy/haproxy.sock1 mode 600 level admin process 1
#stats socket /var/lib/haproxy/haproxy.sock2 mode 600 level admin process 2
#stats socket /var/lib/haproxy/haproxy.sock3 mode 600 level admin process 3
#stats socket /var/lib/haproxy/haproxy.sock4 mode 600 level admin process 4
uid 99
gid 99
daemon
#nbproc 4 #默认单进程启动
#nbthread 4 #可设置为单进程多线程或者多进程单线程,以及针对进程进程cpu绑定
#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 local3 info
defaults
option http-keep-alive
option forwardfor
maxconn 100000
mode http
timeout connect 300000ms
timeout client 300000ms
timeout server 300000ms
# listen stats #启动web监控
# bind :9009
# stats enable
# stats hide-version
# stats uri /haproxy-status
# stats realm HAPorxy\Stats\Page
# stats auth admin:123456
# #stats refresh 3s
# stats admin if TRUE
Start haproxy:systemctl start harpoxy
Verify haproxy Status:
[@ localhost the root / usr / local / the src] #haproxy -v
HA-Proxy version 2.0.12 2019/12/21 - https://haproxy.org/
NOTE: haproxy.cfg file defines the chroot, pidfile, user, group parameters, if the system resources are not haproxy cause can not start
moving, with particular reference to the log file / var / log / messages