Ubuntu1804上源码安装Haproxy2.0.12

    1:准备编译安装HAProxy的基础环境

1 apt install make gcc build-essential libssl-dev zlib1g-dev libpcre3 libpcre3-dev libsystemd-dev libreadline-dev -y
2:.编译安装lua,为HAProxy支持基于其实现功能扩展。
注:HAProxy要求的lua最低版本为5.3
2.1 下载并且安装lua

1 wget -P /usr/local/src/ http://www.lua.org/ftp/lua-5.3.5.tar.gz
2 cd /usr/local/src/
3 tar xf lua-5.3.5.tar.gz
4 cd lua-5.3.5/src/
5 make linux

 2.2 查看编译后的版本

root@template-ubuntu-20200606:/usr/local/src/lua-5.3.5/src# ./lua -v
Lua 5.3.5  Copyright (C) 1994-2018 Lua.org, PUC-Rio
3.编译安装haproxy
3.1安装基础环境
1 root@template-ubuntu-20200606:/usr/local/src# apt install iproute2 ntpdate tcpdump telnet traceroute nfs-kernel-server nfs-common lrzsz tree openssl libssl-dev libpcre3 libpcre3-dev zlib1g-dev  gcc openssh-server iotop unzip libreadline-dev libsystemd-dev
3.3 解压并安装
1 cd /usr/local/src/
2  tar xf haproxy-2.0.4.tar.gz
3  cd haproxy-2.0.4
4  make -j `lscpu |awk 'NR==4{print $2}'` 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=/apps/haproxy && make install PREFIX=/apps/haproxy

3.3 查看编译安装好的版本信息

1 root@template-ubuntu-20200606:/usr/local/src/haproxy-2.0.12# ./haproxy  -v
2 HA-Proxy version 2.0.12 2019/12/21 - https://haproxy.org/

4.编写haproxy启动脚本

 1 #创建文件
 2 vim /lib/systemd/system/haproxy.service
 3 
 4 [Unit]
 5 Description=HAProxy Load Balancer
 6 After=syslog.target network.target
 7 
 8 [Service]
 9 ExecStartPre=/apps/haproxy/sbin/haproxy -f /etc/haproxy/haproxy.cfg -c -q
10 ExecStart=/apps/haproxy/sbin/haproxy -Ws -f /etc/haproxy/haproxy.cfg -p /var/lib/haproxy/haproxy.pid
11 ExecReload=/bin/kill -USR2 $MAINPID
12 
13 [Install]
14 WantedBy=multi-user.target

5:编写配置文件 

 1 #创建haproxy的配置文件
 2 
 3 vim  /etc/haproxy/haproxy.cfg 
 4 
 5 global
 6     maxconn 100000
 7     chroot /apps/haproxy
 8     stats socket /var/lib/haproxy/haproxy.sock mode 600 level admin
 9     uid 99
10     gid 99
11     daemon
12     pidfile /var/lib/haproxy/haproxy.pid
13     log 127.0.0.1 local3 info
14 
15 
16 defaults
17     option http-keep-alive
18     option forwardfor
19     maxconn 100000
20     mode http
21     timeout connect 300000ms
22     timeout client 300000ms
23     timeout server 300000ms
24 
25 
26 listen stats
27     mode http
28     bind 0.0.0.0:9999
29     stats enable
30     log global
31     stats uri  /haproxy-status
32     stats auth admin:molson

6:启动haproxy

1 #创建文件并授权
2 mkdir  /var/lib/haproxy    #相关文件存放位置
3 chown  99.99 /var/lib/haproxy/ -R
4 
5 
6 #启动Haproxy并设置开机启动及检查Haproxy的状态
7 systemctl  start haproxy
8 systemctl  enable haproxy
9 systemctl  status  haproxy

7:打开网页验证状态

      看到如上图的信息,说明Haproxy安装成功

 

 

 

 

 

 

posted @ 2020-07-19 20:35  Molson  阅读(556)  评论(0编辑  收藏  举报