在docker中haproxy的安裝以及mysql的負載均衡配置

HAProxy提供高可用性、負載均衡以及基於TCP和HTTP應用的代理,支持虛擬主機,它是免費、快速並且可靠的一種解決方案
1 什麼是haproxy

HAProxy提供高可用性、負載均衡以及基於TCP和HTTP應用的代理,支持虛擬主機,它是免費、快速並且可靠的一種解決方案。HAProxy特別適用於那些負載特大的web站點,這些站點通常又需要會話保持或七層處理。HAProxy運行在當前的硬件上,完全可以支持數以萬計的併發連接。並且它的運行模式使得它可以很簡單安全的整合進您當前的架構中, 同時可以保護你的web服務器不被暴露到網絡上。

2 haproxy的安裝
1.拉取鏡像
docker pull haproxy
2.配置目錄
mkdir /docker/haproxy-master/
touch /docker/haproxy-master/haproxy.cfg
3.配置haproxy.cfg文件
defaults
    mode            tcp
    log             global
    option          tcplog
    option          dontlognull
    option http-server-close
    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         3000
frontend    mysql
    bind        0.0.0.0:13307
    mode        tcp
    log         global
    default_backend mysql_server

backend     mysql_server
    balance roundrobin
    server mysql1 192.168.228.131:3307 check inter 5s rise 2 fall 3
    server mysql2 192.168.228.131:3308 check inter 5s rise 2 fall 3

listen stats
    mode    http
    bind    0.0.0.0:1080
    stats   enable
    stats   hide-version
    stats uri /haproxyamdin?stats
    stats realm Haproxy\ Statistics
    stats auth admin:admin
    stats admin if TRUE

1080端口爲可視化界面
在docker中haproxy的安裝以及mysql的負載均衡配置在docker中haproxy的安裝以及mysql的負載均衡配置

4.構建相關容器
docker run -p 1080:1080 -p 13307:13307 -d --name haproxy-master -v /docker/haproxy-master/haproxy.cfg:/usr/local/etc/haproxy/haproxy.cfg --privileged=true haproxy
5.負載均衡測試(本地連接)

在docker中haproxy的安裝以及mysql的負載均衡配置在docker中haproxy的安裝以及mysql的負載均衡配置

可以看到訪問不同的server_id。

本文地址:https://www.linuxprobe.com/installation-haproxy-docke.html

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章