Haproxy之编译安装HAProxy2.1.3

1、安装lua

HAProxy 支持基于lua实现功能扩展,lua是一种小巧的脚本语言
#当前系统版本

[root@centos7 ~]#lua -v
Lua 5.1.4 Copyright (C) 1994-2008 Lua.org, PUC-Rio

#安装基础命令及编译依赖环境

[root@centos7 ~]# yum install gcc readline-devel
[root@centos7 ~]# wget http://www.lua.org/ftp/lua-5.3.5.tar.gz
[root@centos7 ~]# tar xvf lua-5.3.5.tar.gz -C /usr/local/src
[root@centos7 ~]# cd /usr/local/src/lua-5.3.5
[root@centos7 lua-5.3.5]# make linux test

#查看编译安装的版本

[root@centos7 lua-5.3.5]#src/lua -v
Lua 5.3.5 Copyright (C) 1994-2018 Lua.org, PUC-Rio

#查看安装方法

#HAProxy 2.0以上版本编译参数:
[root@centos37 ~]#yum -y install gcc openssl-devel pcre-devel systemd-devel
[root@centos37 ~]#tar xvf haproxy-2.1.3.tar.gz -C /usr/local/src
[root@centos37 ~]#cd /usr/local/src/haproxy-2.1.3/
[root@centos37 haproxy-2.1.3]#ll Makefile
-rw-rw-r-- 1 root root 40812 Feb 12 23:18 Makefile
[root@centos37 haproxy-2.1.3]#cat README
[root@centos37 haproxy-2.1.3]#cat INSTALL

#参考INSTALL文件进行编译安装

[root@centos37 haproxy-2.1.3]#make ARCH=x86_64 TARGET=linux-glibc USE_PCRE=1 USE_OPENSSL=1 USE_ZLIB=1 USE_SYSTEMD=1 USE_LUA=1 LUA_INC=/usr/local/src/lua-5.3.5/src/ LUA_LIB=/usr/local/src/lua-5.3.5/src/
[root@centos7 haproxy-2.1.3]# make install PREFIX=/apps/haproxy
[root@centos7 haproxy-2.1.3]#ln -s /apps/haproxy/sbin/haproxy /usr/sbin/

#查看生成的文件

[root@centos7 haproxy-2.1.3]#tree /apps/haproxy/

2.验证HAProxy版本
```cpp
[root@centos37 ~]#haproxy -v
HA-Proxy version 2.1.3 2020/02/12 - https://haproxy.org/
Status: stable branch - will stop receiving fixes around Q1 2021.
Known bugs: http://www.haproxy.org/bugs/bugs-2.1.3.html
[root@centos7 ~]#haproxy -vv
HA-Proxy version 2.1.3 2020/02/12 - https://haproxy.org/
Status: stable branch - will stop receiving fixes around Q1 2021

3.准备HAProxy启动文件

#默认缺少配置文件,无法启动

[root@centos37 ~]#systemctl daemon-reload
[root@centos37 ~]#systemctl start haproxy
Job for haproxy.service failed because the control process exited with error
code. See "systemctl status haproxy.service" and "journalctl -xe" for details
[root@centos37 ~]#systemctl stop haproxy  #此处无法启动,记得要停掉服务

#创建service文件

[root@centos37 ~]#vim /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
LimitNOFILE=100000

[Install]
WantedBy=multi-user.target

4、配置文件

#创建自定义的配置文件

[root@centos37 ~]# mkdir /etc/haproxy
[root@centos37 ~]# vim /etc/haproxy/haproxy.cfg
global
maxconn 100000
chroot /apps/haproxy
stats socket /var/lib/haproxy/haproxy.sock mode 600 level admin
#uid 99
#gid 99
user haproxy
group haproxy
daemon
#nbproc 4
#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 local2 info
defaults
option http-keep-alive
option forwardfor
maxconn 100000
mode http
timeout connect 300000ms
timeout client 300000ms
timeout server 300000ms
listen stats
mode http
bind 0.0.0.0:9999
stats enable
log global
stats uri /haproxy-status
stats auth haadmin:123456
listen web_port
bind 10.0.0.37:80
mode http
log global
server web1 127.0.0.1:8080 check inter 3000 fall 2 rise 5

5、启动 haproxy

#准备socket文件目录

[root@centos37 ~]# mkdir /var/lib/haproxy

#设置用户和目录权限

[root@centos37 ~]# useradd -r -s /sbin/nologin -d /var/lib/haproxy haproxy
[root@centos37 ~]# systemctl enable --now haproxy

6、验证 haproxy 状态

[root@centos37 ~]#systemctl status haproxy

在这里插入图片描述
http://10.0.0.8:9999/haproxy-status
在这里插入图片描述
http://10.0.0.7:9999/haproxy-status

在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值