haproxy給mysql做負載平衡,haproxymysql

來源:互聯網
上載者:User

haproxy給mysql做負載平衡,haproxymysql
一、首先安裝haproxywget http://haproxy.1wt.eu/download/1.4/src/haproxy-1.4.24.tar.gztar zcvf haproxy-1.4.24.tar.gzcd haproxy-1.4.24make TARGET=linux26 PREFIX=/usr/local/haproxy #將haproxy安裝到/usr/local/haproxymake install PREFIX=/usr/local/haproxy#PREFIX必須用大寫,否則無法安裝到指定目錄/usr/local/haproxy中二、配置在/usr/local/haproxy/etc/下建立haproxy.cfg設定檔。內容為:
global        log 127.0.0.1   local0 info    #日誌相關        log 127.0.0.1   local1 notice        maxconn 4096        chroot /usr/local/haproxy        uid root        gid root        daemon        #debug        #quiet        pidfile /usr/local/haproxy/haproxy.pid defaults        log     global        mode    http        #option httplog        option  dontlognull        retries 3        option redispatch        maxconn         2000        contimeout      5000        clitimeout      50000        srvtimeout      50000 listen  mysql        bind 0.0.0.0:23306    #代理連接埠        mode tcp              #模式 TCP        option mysql-check user root   #mysql健全狀態檢查  root為mysql登入使用者名稱        balance roundrobin            #調度演算法        server mysql1 192.168.153.128:3306 weight 1 check  inter 1s rise 2 fall 2 #健全狀態檢查加上check        server mysql2 192.168.153.134:3306 weight 1 check  inter 1s rise 2 fall 2listen stats     #監控           mode http           bind 0.0.0.0:8888           stats enable           stats uri /dbs           stats realm Global\ statistics           stats auth admin:admin
#option mysql-check user root #mysql健全狀態檢查 root為mysql登入使用者名稱 注釋掉 
兩個使用者都要開啟mysql服務三、啟動[root@web2 etc]# /usr/local/haproxy/sbin/haproxy -f /usr/local/haproxy/etc/haproxy.cfg
[root@web2 etc]# cd ../sbin/
[root@web2 sbin]# ls
haproxy
[root@web2 sbin]# ps -ef | grep haproxy
root 4223 1 0 18:12 ? 00:00:00 /usr/local/haproxy/sbin/haproxy -f /usr/local/haproxy/etc/haproxy.cfg
root 4228 3754 0 18:12 pts/0 00:00:00 grep haproxy
[root@web2 sbin]# 四、訪問ip:8888/dbs輸入admin admin登入   

相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.