Linux集群技术 -- Web集群 负载均衡解决方案 - -CentOS7源码安装部署haproxy-2.1.10

本文档详细介绍了如何在CentOS7上通过源码方式安装部署HAProxy2.1.10,并结合Lua进行配置。首先下载haproxy和lua源码,然后分别编译安装。在编译haproxy时启用lua支持,设置相关参数。接着创建haproxy服务启动脚本和配置文件,最后启动并验证haproxy服务。
摘要由CSDN通过智能技术生成

CentOS7源码安装部署haproxy-2.1.10


下载haproxy-2.1.10、lua-5.3.5

[root@node03 ~]# wget -c https://www.haproxy.org/download/2.1/src/haproxy-2.1.10.tar.gz
[root@node03 ~]# wget -c https://www.lua.org/ftp/lua-5.3.5.tar.gz

编译安装lua-5.3.5

[root@node03 ~]# cd /usr/local/src/lua-5.3.5/
[root@node03 lua-5.3.5]# make linux
[root@node03 lua-5.3.5]# make install INSTALL_TOP=/usr/local/lua
[root@node03 lua-5.3.5]# /usr/local/lua/bin/lua -v
Lua 5.3.5  Copyright (C) 1994-2018 Lua.org, PUC-Rio

编译安装haproxy-2.1.10

[root@node03 ~]# tar xf haproxy-2.1.10.tar.gz -C /usr/local/src/
[root@node03 ~]# cd /usr/local/src/haproxy-2.1.10/
[root@node03 haproxy-2.1.10]# make USE_NS=1 USE_TFO=1 USE_OPENSSL=1 USE_ZLIB=1 USE_LUA=1 USE_PCRE=1 USE_SYSTEMD=1 USE_LIBCRYPT=1 USE_THREAD=1 TARGET=linux-glibc LUA_INC=/usr/local/lua/include LUA_LIB=/usr/local/lua/lib
[root@node03 haproxy-2.1.10]# make install PREFIX=/usr/local/haproxy

提供haproxy-2.1.10 系统启动服务脚本

[root@node03 haproxy-2.1.10]# vim /usr/lib/systemd/haproxy.service
[Unit]

Description=HAProxy Load Balancer

After=syslog.target network.target



[Service]

ExecStart=/usr/local/haproxy/sbin/haproxy -Ws -f /etc/haproxy/haproxy.cfg -p /run/haproxy.pid

ExecReload=/bin/kill -USR2 $MAINPID

KillMode=mixed



[Install]

WantedBy=multi-user.target

提供haproxy-2.1.10服务配置文件

[root@node03 ~]# vim /etc/haproxy/haproxy.cfg 
#---------------------------------------------------------------------

# Global settings

#---------------------------------------------------------------------

global

log         127.0.0.1 local2



chroot      /usr/local/haproxy

pidfile     /var/run/haproxy.pid

maxconn     4000

user        haproxy

group       haproxy

daemon



# turn on stats unix socket

stats socket /usr/local/haproxy/haproxy.sock



#---------------------------------------------------------------------

# common defaults that all the 'listen' and 'backend' sections will

# use if not designated in their block

#---------------------------------------------------------------------

defaults

mode                    http

log                     global

option                  httplog

option                  dontlognull

option http-server-close

option forwardfor       except 127.0.0.0/8

option                  redispatch

retries                 3

timeout http-request    10s

timeout queue           1m

timeout connect         10s

timeout client          1m

timeout server          1m

timeout http-keep-alive 10s

timeout check           10s

maxconn                 3000



#---------------------------------------------------------------------

# main frontend which proxys to the backends

#---------------------------------------------------------------------

frontend  main *:5000

acl url_static       path_beg       -i /static /images /javascript /stylesheets

acl url_static       path_end       -i .jpg .gif .png .css .js

 

use_backend static          if url_static

default_backend             app

#---------------------------------------------------------------------

# static backend for serving up images, stylesheets and such

#---------------------------------------------------------------------

backend static

balance     roundrobin

server      static 127.0.0.1:4331 check

#---------------------------------------------------------------------

# round robin balancing between the various backends

#---------------------------------------------------------------------

启动HAProxy

[root@node03 ~]# systemctl daemon-reload
[root@node03 ~]# systemctl enable --now haproxy
[root@node03 ~]# systemctl is-active haproxy
active
[root@node03 ~]# systemctl is-enabled haproxy
enabled

参考:CentOS7源码安装部署HAProxy-1.9.7

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值