Kubernetes 安装

CentOS 安装 HAProxy 实现 TCP 负载均衡

2019-07-20  本文已影响0人  Danielme

HAProxy可以实现 TCP 负载均衡

  1. 关闭防火墙
    systemctl stop firewalld
    systemctl disable firewalld
    
  2. 修改 SELINUX
    setenforce 0
    sed -i 's/^SELINUX=enforcing$/SELINUX=permissive/' /etc/selinux/config
    
  3. 安装 haproxy
    yum install -y haproxy
    
  4. 修改 haproxy 配置
    cat <<EOF > /etc/haproxy/haproxy.cfg
    global
        log         127.0.0.1 local2
    
        chroot      /var/lib/haproxy
        pidfile     /var/run/haproxy.pid
        maxconn     65000
        user        haproxy
        group       haproxy
        daemon
    
        stats socket /var/lib/haproxy/stats
    
    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                 65000
    
    
    frontend tcp_master_frontend
        bind                    *:26443
        mode                    tcp
        log                     global
        option                  tcplog
        timeout client          60s
        maxconn                 65000
        default_backend         tcp_master_backend
    
    backend tcp_master_backend
        mode                    tcp
        option                  tcplog
        option                  log-health-checks
        balance                 roundrobin
        timeout queue           5s
        timeout connect         1s
        timeout server          60s
        server  master01        192.168.1.108:6443 check
        server  master02        192.168.1.110:6443 check
        server  master03        192.168.1.109:6443 check
    EOF
    
  5. 注册 haproxy 为自动服务
    systemctl daemon-reload
    systemctl enable haproxy
    systemctl restart haproxy
    
  6. 检查 haproxy 启动状态
    systemctl staus haproxy
      ● haproxy.service - HAProxy Load Balancer
        Loaded: loaded (/usr/lib/systemd/system/haproxy.service; enabled; vendor preset: disabled)
        Active: active (running) since Sat 2019-07-20 17:44:23 CST; 888ms ago
    
上一篇下一篇

猜你喜欢

热点阅读