docker 部署haproxy cpu占用特别高

在部署mysql 主主高可用时,使用haproxy进行负载,在服务部使用的情况下发现服务器cpu占比高,负载也高,因此急需解决这个问题。

1.解决前现状

1.1 部署配置文件

cat > haproxy.cfg << EOF
global
    maxconn     4000
    nbthread    2
    daemon 
defaults
        log     global
        log 127.0.0.1 local3
        mode    http
        option  tcplog
        option  dontlognull
        retries 10
        option redispatch
        maxconn         2000
        timeout connect         30s
        timeout client          10m
        timeout server          10m
        #timeout http-keep-alive 10s
        timeout check           10s
######## 监控界面配置 #################	
listen  admin_stats
	#监控界面的访问的IP和端口
	bind  0.0.0.0:8888
	#访问协议
    mode        http
	#URI相对地址
    stats uri   /dbs
	#统计报告格式
    stats realm     Global\ statistics
	#登陆帐户信息
    stats auth  admin:admin
    # 隐藏HAProxy的版本号
    stats hide-version
    # 管理界面,如果认证成功了,可通过webui管理节点
    stats admin if TRUE
    # 统计页面自动刷新时间
    stats  refresh  30s
listen  mysql
        bind 0.0.0.0:3306
        mode tcp
        #负载均衡算法(轮询算法)
	    #轮询算法:roundrobin
	    #权重算法:static-rr
	    #最少连接算法:leastconn
	    #请求源IP算法:source 
        balance  roundrobin
        # 监控检查需要一个无密码的账号
        # mysql健康检查  haproxy为mysql登录用户名(需要在实体数据有这个账户,且无密码)
	    # option mysql-check  user haproxy 
        server s1 mysql-master1:3306 check weight 1 maxconn 2000 inter 5000 rise 2 fall 2
        server s2 mysql-master2:3306 check weight 1 maxconn 2000 inter 5000 rise 2 fall 2 backup
EOF

cat > dokcer-stark-haproxy.yml << EOF
version: '3'

networks:
  liuhm-net:
    external: true 

services:
  haproxy:
    image: haproxy:alpine
    hostname: haproxy
    volumes:
      - "${
    PWD}/haproxy.cfg:/usr/local/etc/haproxy/haproxy.cfg"
      - "/etc/localtime:/etc/localtime:ro"
    restart: always
    privileged: true
    ports:
      - 8888:8888
      - 3306:3306
    networks:
      - liuhm-net
    deploy:
      mode: global
EOF

在这里插入图片描述

2.解决后


cat > haproxy.cfg << EOF
global
    maxconn     4000
    nbthread    2
    daemon 
    ## tune.disable-zero-copy-forwarding必须配置,不然cpu占比很高
    tune.disable-zero-copy-forwarding                       
defaults
        log     global
        log 127.0.0.1 local3
        mode    http
        option  tcplog
        option  dontlognull
        retries 10
        option redispatch
        maxconn         2000
        timeout connect         30s
        timeout client          10m
        timeout server          10m
        #timeout http-keep-alive 10s
        timeout check           10s
######## 监控界面配置 #################	
listen  admin_stats
	#监控界面的访问的IP和端口
	bind  0.0.0.0:8888
	#访问协议
    mode        http
	#URI相对地址
    stats uri   /dbs
	#统计报告格式
    stats realm     Global\ statistics
	#登陆帐户信息
    stats auth  admin:admin
    # 隐藏HAProxy的版本号
    stats hide-version
    # 管理界面,如果认证成功了,可通过webui管理节点
    stats admin if TRUE
    # 统计页面自动刷新时间
    stats  refresh  30s
listen  mysql
        bind 0.0.0.0:3306
        mode tcp
        #负载均衡算法(轮询算法)
	    #轮询算法:roundrobin
	    #权重算法:static-rr
	    #最少连接算法:leastconn
	    #请求源IP算法:source 
        balance  roundrobin
        # 监控检查需要一个无密码的账号
        # mysql健康检查  haproxy为mysql登录用户名(需要在实体数据有这个账户,且无密码)
	    # option mysql-check  user haproxy 
        server s1 mysql-master1:3306 check weight 1 maxconn 2000 inter 5000 rise 2 fall 2
        server s2 mysql-master2:3306 check weight 1 maxconn 2000 inter 5000 rise 2 fall 2 backup
EOF

cat > dokcer-stark-haproxy.yml << EOF
version: '3'

networks:
  liuhm-net:
    external: true 

services:
  haproxy:
    image: haproxy:2.9.1-alpine
    hostname: haproxy
    volumes:
      - "${
    PWD}/haproxy.cfg:/usr/local/etc/haproxy/haproxy.cfg"
      - "/etc/localtime:/etc/localtime:ro"
    restart: always
    privileged: true
    ports:
      - 8888:8888
      - 3306:3306
    networks:
      - liuhm-net
    deploy:
      mode: global
EOF

实际配置后没有飙升
在这里插入图片描述

相关推荐

  1. 如何清理Docker占用的磁盘空间?

    2024-01-06 13:10:03       28 阅读

最近更新

  1. TCP协议是安全的吗?

    2024-01-06 13:10:03       19 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2024-01-06 13:10:03       19 阅读
  3. 【Python教程】压缩PDF文件大小

    2024-01-06 13:10:03       20 阅读
  4. 通过文章id递归查询所有评论(xml)

    2024-01-06 13:10:03       20 阅读

热门阅读

  1. 阿里的通义灵码在android studio上的使用方法

    2024-01-06 13:10:03       53 阅读
  2. 07GoF之工厂模式

    2024-01-06 13:10:03       27 阅读
  3. K8S三种发布方式和声明式资源管理

    2024-01-06 13:10:03       32 阅读
  4. [原创][R语言]股票分析实战[8]:因子与subset的关系

    2024-01-06 13:10:03       31 阅读
  5. iOS基础之修饰符

    2024-01-06 13:10:03       42 阅读
  6. mysql 通过sql计算部门路径的方法

    2024-01-06 13:10:03       38 阅读