您好,登錄后才能下訂單哦!
Ubuntu18.04 apt 安裝2.0.4
Centos7.6 Yum安裝1.8.14
Centos7.6編譯安裝haproxy2.0.12
<h7 id=1>Ubuntu18.04 apt 安裝2.0.4</h7>
root@ubuntu:~# apt-get install software-properties-common
#安裝常用軟件包
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.
root@ubuntu:~# add-apt-repository ppa:vbernat/haproxy-2.0
#添加最新的haproxy2.0版本到本地倉庫
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
...
root@ubuntu:~# apt 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
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
...
root@ubuntu:~# apt-cache madison haproxy
#看倉庫中haproxy·有哪些版本可以安裝
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
root@ubuntu:~# apt install haproxy=2.0.4-1ppa1\~bionic
#安裝選擇的版本
root@ubuntu:~#haproxy -v
#驗證haproxy版本
HA-Proxy version 1.8.14-52e4d43 2018/09/20
Copyright 2000-2018 Willy Tarreau <willy@haproxy.org>
root@ubuntu:~# systemctl start haproxy
#啟動haproxy
<h7 id=2>Centos7.6 Yum安裝1.8.14</h7>
默認情況centos7中的包都是較老的haproxy是1.5.18-9.el7的,不太滿足需求,此時我們可以基于第三方安裝包yum安裝
https://pkgs.org/download/haproxy 該網址el7最新rpm包更新至1.8.14
一般需要一個依賴倉庫包和haproxy.rpm的安裝包
下載安裝包
wget https://centos.pkgs.org/7/cheese-x86_64/haproxy-1.8.14-1.el7.x86_64.rpm.html
下載依賴包
weget https://centos.pkgs.org/7/cheese-x86_64/cheese-release-7-1.noarch.rpm.html
安裝對應的包
#rpm -ivh cheese-release-7-1.noarch.rpm
#yum install haproxy-1.8.14-1.el7.x86_64.rpm -y
#驗證haproxy版本
# haproxy -v
HA-Proxy version 1.8.14-52e4d43 2018/09/20
Copyright 2000-2018 Willy Tarreau <willy@haproxy.org>
<h7 id=3>Centos7.6編譯安裝haproxy2.0.12</h7>
編譯安裝HAProxy 2.0 LTS版本,更多源碼包官網下載地址:http://www.haproxy.org/download/
HAProxy 支持基于lua實現功能擴展,為應用程序提供靈活的擴展和定制功能,由于centos自帶的lua版本比較低并不符合HAProxy要求的lua最低版本(5.3)的要求,因此編譯時需要安裝該包,lua官方下載地址
https://www.lua.org/download.html
yun安裝編譯環境
yum install libtermcap-devel ncurses-devel libevent-devel readline-devel wget make gcc-y
下載lua5.3.5
wget http://www.lua.org/ftp/lua-5.3.5.tar.gz
61% [===================================================> ] 187,197 8.29KB/s eta 25s
解壓并編譯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'
最終在src生成兩個可執行文件
系統版本
[root@localhost /usr/local/src/lua-5.3.5/src]#lua -v
Lua 5.1.4 Copyright (C) 1994-2008 Lua.org, PUC-Rio
編譯的版本
[root@localhost /usr/local/src/lua-5.3.5/src]#./lua -v
Lua 5.3.5 Copyright (C) 1994-2018 Lua.org, PUC-Rio
編譯安裝HAProxy
準備安裝haproxy的環境依賴
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及1.9版本編譯參數:
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編譯參數:
[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
...
#安裝該配置到/usr/local/haproxy目錄下
[root@localhost /usr/local/src/haproxy-2.0.12]#make install PREFIX=/usr/local/haproxy
#移動到/usr/sbin/系統環境下
[root@localhost /usr/local/src/haproxy-2.0.12]#cp haproxy /usr/sbin/
#驗證haproxy版本
[root@localhost /usr/local/src/haproxy-2.0.12]#haproxy -v
HA-Proxy version 2.0.12 2019/12/21 - https://haproxy.org/
#準備HAProxy啟動腳本
[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
#準配HA配置文件
#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
啟動haproxy:systemctl start harpoxy
驗證haproxy狀態:
[root@localhost /usr/local/src]#haproxy -v
HA-Proxy version 2.0.12 2019/12/21 - https://haproxy.org/
注: haproxy.cfg文件中定義了chroot、pidfile、user、group等參數,如果系統沒有相應的資源會導致haproxy無法啟
動,具體參考日志文件/var/log/messages
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。