Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to install haproxy in centos or Ubuntu

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/03 Report--

This article is to share with you how to install haproxy in centos or Ubuntu. I believe most people don't know how to install it yet. In order to let you learn, I summarized the following contents. Without saying much, let's read on.

Ubuntu18.04 apt installation 2.0.4

Centos7.6 Yum installation 1.8.14

Centos7.6 compilation and installation of haproxy2.0.12

Ubuntu18.04 apt installation 2.0.4

Root@ubuntu:~# apt-get install software-properties-common

# install common software packages

Reading package lists... DoneBuilding dependency tree Reading state information... Donesoftware-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

# add the latest haproxy2.0 version to the local repository

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.0Press [ENTER] to continue or Ctrl-c to cancel adding it. # # manual ENTENR confirmation is required before the package 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 will be installed as needed .aliyun.com / ubuntu bionic-updates InRelease...

Root@ubuntu:~# apt update

# upgrade the local warehouse, which is required for all operations related to changing the package

Hit:1 http://mirrors.aliyun.com/ubuntu bionic InReleaseHit:2 http://mirrors.aliyun.com/ubuntu bionic-security InReleaseHit: 3 http://mirrors.aliyun.com/ubuntu bionic-updates InReleaseHit: 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

# see which versions of haproxy can be installed in the warehouse

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

# install the selected version

Root@ubuntu:~#haproxy-v

# verify the haproxy version

HA-Proxy version 1.8.14-52e4d43 2018/09/20Copyright 2000-2018 Willy Tarreau

Root@ubuntu:~# systemctl start haproxy

# start haproxy

Centos7.6 Yum installation 1.8.14

By default, the packages in centos7 are older. Haproxy is 1.5.18-9.el7, which does not meet the requirements. In this case, we can install it based on the third-party installation package yum.

Https://pkgs.org/download/haproxy the URL el7 updated the latest rpm package to 1.8.14

Generally, you need an installation package that relies on the repository 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 dependency package

Weget https://centos.pkgs.org/7/cheese-x86_64/cheese-release-7-1.noarch.rpm.html

Install the corresponding package

# rpm-ivh cheese-release-7-1.noarch.rpm#yum install haproxy-1.8.14-1.el7.x86_64.rpm-y

# verify the haproxy version

# haproxy-vHA-Proxy version 1.8.14-52e4d43 2018/09/20Copyright 2000-2018 Willy Tarreau

Centos7.6 compilation and installation of haproxy2.0.12

Compile and install HAProxy 2.0 LTS version. Download more source code packages on the official website: http://www.haproxy.org/download/

HAProxy supports functional extension based on lua and provides flexible extension and customization functions for applications. Since the lower version of lua that comes with centos does not meet the requirements of the minimum version of lua required by HAProxy, the package needs to be installed at compile time, and the official download address of lua

Https://www.lua.org/download.html

Yun installation and compilation 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.gz61% [= >] 187197 8.29KB/s eta 25s

Extract 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.car 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.agcc-std=gnu99-O2-Wall-Wextra-DLUA_COMPAT_5_2-DLUA_USE_LINUX-c-o lua.o lua.cgcc-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.cgcc-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'

Finally, two executable files are generated in src

System version

[root@localhost / usr/local/src/lua-5.3.5/src] # lua- vLua 5.1.4 Copyright (C) 1994-2008 Lua.org, PUC-Rio

Compiled version

[root@localhost / usr/local/src/lua-5.3.5/src] #. / lua- vLua 5.3.5 Copyright (C) 1994-2018 Lua.org, PUC-Rio

Compile and install HAProxy

Environmental dependencies that are ready to install 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 and 1.9 compilation 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 compilation 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# this configuration is installed in the / usr/local/haproxy directory by default. 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...

# install the configuration to the / usr/local/haproxy directory

[root@localhost / usr/local/src/haproxy-2.0.12] # make install PREFIX=/usr/local/haproxy

# move to / usr/sbin/ system environment

[root@localhost / usr/local/src/haproxy-2.0.12] # cp haproxy / usr/sbin/

# verify the 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 script

[root@localhost / usr/local/src] # cat / usr/lib/systemd/system/haproxy.service

The [Unit] Description=HAProxy Load BalancerAfter=syslog.target network.target# directory should correspond to the installation directory [Service] ExecStartPre=/usr/sbin/haproxy-f / etc/haproxy/haproxy.cfg-c-qExecStart=/usr/sbin/haproxy-Ws-f / etc/haproxy/haproxy.cfg-p / var/lib/haproxy/haproxy.pidExecReload=/bin/kill-USR2 $MAINPID [install] WantedBy=multi-user.target

# HA configuration file

# mkdir / etc/haproxy

# mkdir / var/lib/haproxy

# cat / etc/haproxy/haproxy.cfg

Globalmaxconn 100000chroot / usr/local/haproxystats socket / var/lib/haproxy/haproxy.sock mode 600level admin#stats socket / var/lib/haproxy/haproxy.sock1 mode 600level admin process 1#stats socket / var/lib/haproxy/haproxy.sock2 mode 600level admin process 2#stats socket / var/lib/haproxy/haproxy.sock3 mode 600level admin process 3#stats socket / var/lib/haproxy/haproxy.sock4 mode 600 level admin process 4uid 99gid 99daemon#nbproc 4 # default single process launch # nbthread 4 # can be set up Set to single-process multi-thread or multi-process single-thread And for the process process cpu binding # cpu-map 10 # cpu-map 2 1#cpu-map 3 2#cpu-map 4 3pidfile / var/lib/haproxy/haproxy.pidlog 127.0.0.1 local3 infodefaultsoption http-keep-aliveoption forwardformaxconn 100000mode httptimeout connect 300000mstimeout client 300000mstimeout server 300000ms# listen stats # start web monitoring # bind: 900 processes 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 the haproxy status:

[root@localhost / usr/local/src] # haproxy-v

HA-Proxy version 2.0.12 2019-12-21-https://haproxy.org/

Note: chroot, pidfile, user, group and other parameters are defined in the haproxy.cfg file. If the system does not have the corresponding resources, it will cause haproxy to fail to start.

For more information, please see log file / var/log/messages.

After reading the above, have you mastered the method of installing haproxy in centos or Ubuntu? If you want to learn more skills or want to know more about it, you are welcome to follow the industry information channel, thank you for reading!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report