haproxy部署

15 阅读1分钟

一、准备

  1. 基本检查

# OS内核检查!!! 必须net.ipv4.tcp_keepalive_time=30
vim /etc/sysctl.conf
新增或者修改
net.ipv4.tcp_keepalive_time= 30
  1. 安装job

使用Jenkins

jenkins-ops.hwwt2.com/job/%E8%BF%…

  1. VIP信息




二、部署harpoxy




三、配置haproxy

  1. 172.25.188.208的haproxy.cnf

# haproxy配置文件
vi /etc/haproxy/haproxy.cfg

global
  daemon
  user haproxy
  group haproxy
  nbproc 2
  maxconn 10000
  stats socket /var/run/haproxy-master.sock mode 660 level admin
  log 127.0.0.1 local2 info
userlist dataplaneapi
  user admin insecure-password adminpwd

#haproxy 状态查看配置
listen stats
    mode http
    bind 0.0.0.0:9110
    stats enable
    stats refresh 5s
    stats uri     /stats
    # Enable Prometheus Exporter
    http-request use-service prometheus-exporter if { path /metrics }

#前端代理端口
frontend tcpproxy
    bind 0.0.0.0:8511
    mode tcp
    option tcplog
    default_backend consul

#代理的后端服务地址及端口
backend consul
    balance roundrobin
            #服务名及主机IP
            server 172.25.188.208 172.25.188.208:8500 check
            server 172.25.188.209 172.25.188.209:8500 check

验证 http://172.25.188.208:9110/stats

  1. 172.25.188.209的haproxy.cnf

# haproxy配置文件
vi /etc/haproxy/haproxy.cfg

global
  daemon
  user haproxy
  group haproxy
  nbproc 2
  maxconn 10000
  stats socket /var/run/haproxy-master.sock mode 660 level admin
  log 127.0.0.1 local2 info
userlist dataplaneapi
  user admin insecure-password adminpwd

#haproxy 状态查看配置
listen stats
    mode http
    bind 0.0.0.0:9110
    stats enable
    stats refresh 5s
    stats uri     /stats
    # Enable Prometheus Exporter
    http-request use-service prometheus-exporter if { path /metrics }

#前端代理端口
frontend tcpproxy
    bind 0.0.0.0:8511
    mode tcp
    option tcplog
    default_backend consul

#代理的后端服务地址及端口
backend consul
    balance roundrobin
            #服务名及主机IP
            server 172.25.188.208 172.25.188.208:8500 check
            server 172.25.188.209 172.25.188.209:8500 check

验证:打开http://172.25.188.209:9110/stats




四、安装keepalived




五、配置keepalived




六、启动keepalived和haproxy




七、监控对接

  1. 对接监控

参考自定义类监控

使用的Jenkins:jenkins-ops.hwwt2.com/job/techops…

# 确认
# 查看Prometheus metrics (2.0版本以下的haproxy不支持 metrics)
http://172.21.27.35:1080/metrics



八、补充

参考

AI haproxy版本升级WBS