haproxy 负载均衡安装配置实例

本文详细介绍如何使用wget下载HAProxy源码包,通过tar命令解压并进入目录,利用make命令进行编译安装,设置运行参数,配置haproxy.cfg文件实现负载均衡功能,包括监听端口、模式选择、重试次数、超时设置等。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

wget https://fossies.org/linux/misc/haproxy-1.8.14.tar.gz
tar zxvf haproxy-1.8.14.tar.gz
cd haproxy-1.8.14
make TARGET=linux31
make install PREFIX=/data/haproxy
mkdir /data/haproxy/{conf,logs}

cp examples/option-http_proxy.cfg /data/haproxy/conf/haproxy.cfg

vi /data/haproxy/conf/haproxy.cfg
global
daemon
nbproc 1
pidfile /data/haproxy/conf/haproxy.pid
defaults
mode tcp
retries 2
option redispatch
option abortonclose
balance roundrobin
maxconn 102400
timeout connect 5000ms
timeout client 30000ms
timeout server 30000ms
#timeout check 2000
log 127.0.0.1 local0 info
listen test1
bind 0.0.0.0:9999
mode tcp
server s1 yourip:yourport check weight 1 inter 2000 rise 2 fall 3
#server s2
listen admin_stats
bind 0.0.0.0:1688
mode http
log 127.0.0.1 local0 err
stats refresh 30s
stats uri /haproxy-status
stats realm welcome login\ Haproxy
stats auth admin:admin
stats hide-version
stats admin if TRUE

保存退出,

./haproxy -f ../conf/haproxy.cfg

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值