天天看點

搭建分布式資料庫負載均衡運作環境的一些配置記錄(3)haproxy

首先建立了兩個tomcat伺服器

sudo docker run --name tomcat -p 8090:8080 -d tomcat

編輯index.html可以顯示頁面内容

docker cp index.html tomcat:/usr/local/tomcat/webapps/ROOT

  173.16.80.107:8090  

  173.16.80.70:8090 

下載下傳haproxy

centos下sudo yum install haproxy

ubuntu下sudo apt-get install package 安裝包

一般在/etc/haproxy

編輯配置檔案 sudo vi haproxy.cfg

global

    log         127.0.0.1 local2

    chroot      /var/lib/haproxy

    pidfile     /var/run/haproxy.pid

    maxconn     4000

    user        root

    group       root

    daemon

    # turn on stats unix socket

    stats socket /var/lib/haproxy/stats

defaults

    log global

    mode http

    option http-keep-alive

    option httplog

    timeout connect 5000ms

    timeout client 10000ms

    timeout server 50000ms

    timeout http-request 20000ms

    balance roundrobin

listen stats

    mode http

    log 127.0.0.1 local0 err

    bind  0.0.0.0:1088

    stats enable

    stats hide-version

    stats uri     /stats

    stats refresh 30s

    stats auth    admin:admin

    stats admin if TRUE

listen tomcat

    bind 0.0.0.0:5222

    mode http

    maxconn 300

    log 127.0.0.1 local0 debug

    balance roundrobin

    server  static1 173.16.80.107:8090 check inter 2000 fall 3 weight 30

    server  static2 173.16.80.70:8090 check inter 2000 fall 3 weight 30

重新啟動[chenwb@hadoop03 haproxy]$ sudo systemctl restart haproxy

運作 [chenwb@hadoop03 haproxy]$ sudo haproxy -f /etc/haproxy/haproxy.cfg

檢查兩個tomcat是否成功 

浏覽器位址欄輸入配置的ip+端口 出現以下頁面

搭建分布式資料庫負載均衡運作環境的一些配置記錄(3)haproxy

然後在浏覽器位址欄輸入

​​http://173.16.80.70:1088/stats​​

繼續閱讀