编译安装haproxy 2.6.15
#创建HAProxy运行账户和组
groupadd haproxy useradd -g haproxy haproxy -s /bin/false
#首先安装必要的组件依赖
yum install -y gcc gcc-c++ glibc make autoconf openssl openssl-devel pcre pcre-devel readline-devel systemd-devel
#如果是ubuntu用一下命令
sudo apt install -y build-essential autoconf libssl-dev libpcre3-dev libreadline-dev libsystemd-dev
#下载haproxy
wget https://www.haproxy.org/download/2.6/src/haproxy-2.6.15.tar.gz
#首先要安装lua-5.4.8
下载lua
wget https://www.lua.org/ftp/lua-5.4.8.tar.gz
tar zxvf lua-5.4.8.tar.gz cd lua-5.4.8 make linux make install INSTALL_TOP=/usr/local/lua
#lua安装完毕,接下来安装haproxy tar zxvf ./haproxy-2.6.15.tar.gz cd haproxy-2.6.15 make TARGET=linux-glibc USE_OPENSSL=1 USE_LUA=1 USE_PCRE=1 USE_SYSTEMD=1 LUA_INC=/usr/local/lua/include LUA_LIB=/usr/local/lua/lib make install PREFIX=/usr/local/haproxy #安装以后将service文件放到相应目录 mv haproxy.service /usr/lib/systemd/system/ #创建haproxy所需要的文件夹,并将配置文件放到对应的目录中 mkdir -p /etc/haproxy mkdir -p /var/lib/haproxy mv haproxy.cfg /etc/haproxy/
#测试运行状态命令
/usr/local/haproxy/sbin/haproxy -Ws -f /etc/haproxy/haproxy.cfg -p /run/haproxy.pid -S /run/haproxy-master.sock