How to Install HAProxy 2.0+ in Amazon Linux 2/CentOS/RHEL

https://www.bantrain.com/how-to-install-haproxy-2-0-in-amazon-linux-2-centos-rhel/

First, Install dependencies needed to build HAProxy

Download Lua source code and then Install Lua

curl -R -O http://www.lua.org/ftp/lua-5.3.5.tar.gz
tar zxf lua-5.3.5.tar.gz
cd lua-5.3.5
make linux test
make linux install
cd ..

Download OpenSSL source code and then Install OpenSSL

curl -R -O https://www.openssl.org/source/openssl-1.1.1d.tar.gz
tar xvzf openssl-1.1.1d.tar.gz
cd openssl-1.1.1d
./config --prefix=/usr/local/openssl-1.1.1d shared
make
make install

Download HAProxy source code and then Install HAProxy

Add Service for HAProxy

nano /etc/systemd/system/haproxy.service

Then paste in the following

[Unit]
Description=HAProxy Load Balancer
After=network.target
[Service]
Environment=LD_LIBRARY_PATH=/usr/local/openssl-1.1.1d/lib/
Environment="CONFIG=/etc/haproxy/haproxy.cfg" "PIDFILE=/run/haproxy.pid" "EXTRAOPTS=-S /run/haproxy-master.sock"
ExecStartPre=/usr/local/sbin/haproxy -f $CONFIG -c -q $EXTRAOPTS
ExecStart=/usr/local/sbin/haproxy -Ws -f $CONFIG -p $PIDFILE $EXTRAOPTS
ExecReload=/usr/local/sbin/haproxy -f $CONFIG -c -q $EXTRAOPTS
ExecReload=/bin/kill -USR2 $MAINPID
KillMode=mixed
Restart=always
SuccessExitStatus=143
Type=notify
[Install]
WantedBy=multi-user.target

Then finish HAProxy Installation Process by running

systemctl daemon-reload
mkdir -p /etc/haproxy
touch /etc/haproxy/haproxy.cfg
systemctl enable haproxy
systemctl start haproxy
cd ..

Optional remove build dependencies for haproxy

yum remove readline-devel pcre-devel openssl-devel

如果haproxy -V报错:openssl: error while loading shared libraries: libssl.so.1.1: cannot open shared object file: No such file or directory

ln -s /usr/local/openssl-1.1.1d/lib/libssl.so.1.1 /usr/lib64/libssl.so.1.1
ln -s /usr/local/openssl-1.1.1d/lib/libcrypto.so.1.1 /usr/lib64/libcrypto.so.1.1

 

发表评论

邮箱地址不会被公开。 必填项已用*标注