haproxy代理数据库

安装部署

复制代码
cp haproxy-systemd-wrapper  /usr/sbin/
cp haproxy /usr/sbin

chmod +x /usr/sbin/haproxy
chmod +x /usr/sbin/haproxy-systemd-wrapper
mkdir -p /etc/haproxy

vi /etc/haproxy/haproxy.cfg

useradd haproxy
chown -R haproxy:haproxy /etc/haproxy

mkdir /var/lib/haproxy
chown -R haproxy:haproxy /var/lib/haproxy




vi /etc/sysconfig/haproxy

# Add extra options to the haproxy daemon here. This can be useful for
# specifying multiple configuration files with multiple -f options.
# See haproxy(1) for a complete list of options.
OPTIONS=""




vi /usr/lib/systemd/system/haproxy.service

[Unit]
Description=HAProxy Load Balancer
After=syslog.target network.target

[Service]
EnvironmentFile=/etc/sysconfig/haproxy
ExecStart=/usr/sbin/haproxy-systemd-wrapper -f /etc/haproxy/haproxy.cfg -p /run/haproxy.pid $OPTIONS
ExecReload=/bin/kill -USR2 $MAINPID
KillMode=mixed

[Install]
WantedBy=multi-user.target




systemctl daemon-reload
systemctl restart haproxy
安装步骤
复制代码

 

配置文件说明

复制代码
#---------------------------------------------------------------------
# 全局设定部分
#---------------------------------------------------------------------
global

defaults
        log     global
        mode    tcp
        option  dontlognull
        timeout connect 5000
        timeout client  50000
        timeout server  50000

#---------------------------------------------------------------------
# HAPROXY状态页面
#---------------------------------------------------------------------
listen admin_stats
   stats       enable
   # 监听端口
   bind        *:12345
   mode        http
   option      httplog
   log         global
   maxconn     10
   # 刷新间隔
   stats       refresh          30s
   # 页面路径
   stats       uri              /
   stats       realm            haproxy
   # 访问认证
   stats       auth             admin:password
   stats       hide-version

#---------------------------------------------------------------------
# TCP转发及负载均衡及简单TCP可用性校验
# weight权重;check inter检测频率;rise 1一次可用恢复;fall 2两次失败降级
#---------------------------------------------------------------------
frontend tidb-in
    bind     *:10000
    maxconn  80000
    default_backend tidb

backend tidb
    #使用HTTP对URI路径可用性进行检测
    #option httpchk
    #http-check send meth GET uri /check.html
    #http-check expect status 200

    server tidb-1    10.30.92.70:4000    maxconn 40480  weight 10  check inter 10s  rise 1 fall 2
    server tidb-2    10.30.92.71:4000    maxconn 40480  weight 10  check inter 10s  rise 1 fall 2
    server tidb-3    10.30.92.73:4000    maxconn 44440  weight 10  check inter 10s  rise 1 fall 2
haproxy.cfg
复制代码

     

      

       负载均衡配置

       

     haproxy可以不需要虚拟vip,可以在多台主机上同时部署haproxy并且进行同样的配置,这样客户端无论连接哪台haproxy主机都能把请求转发到后台的服务主机上进行处理

posted @   不懂123  阅读(51)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 周边上新:园子的第一款马克杯温暖上架
· 分享 3 个 .NET 开源的文件压缩处理库,助力快速实现文件压缩解压功能!
· Ollama——大语言模型本地部署的极速利器
· DeepSeek如何颠覆传统软件测试?测试工程师会被淘汰吗?
· 使用C#创建一个MCP客户端
历史上的今天:
2022-07-19 ckman安装步骤
2021-07-19 docker服务程序网络排查
2021-07-19 网络分层协议集合分析
点击右上角即可分享
微信分享提示