• 首页 首页 icon
  • 工具库 工具库 icon
    • IP查询 IP查询 icon
  • 内容库 内容库 icon
    • 快讯库 快讯库 icon
    • 精品库 精品库 icon
    • 问答库 问答库 icon
  • 更多 更多 icon
    • 服务条款 服务条款 icon

haproxy代理数据库

武飞扬头像
langy1990
帮助1

安装部署

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主机都能把请求转发到后台的服务主机上进行处理

这篇好文章是转载于:学新通技术网

  • 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
  • 本站站名: 学新通技术网
  • 本文地址: /boutique/detail/tanhibhgif
系列文章
更多 icon
同类精品
更多 icon
继续加载