注:因為 RabbitMQ 本身不提供負載均衡,下面我們就搭建 HAProxy,用作 RabbitMQ 叢集的負載均衡。
目錄
1.HAProxy安裝包... 1
2. haproxy安裝... 1
3.編輯haproxy.cfg檔案... 2
4.啟動... 4
5.登陸... 4
1.HAProxy安裝包
安裝包下載下傳位址 https://src.fedoraproject.org/repo/pkgs/haproxy/
2. haproxy安裝
Uname –a 檢視伺服器資訊
make TARGET =linux310 ARCH=x86_64 PREFIX = /data/RabbitMQ/haproxy /
然後會在指定目錄下看到新安裝的
haproxy
make install PREFIX=/data/RabbitMQ/haproxy
3.編輯haproxy.cfg檔案
編輯haproxy.cfg檔案(注:haproxy.cfg檔案需要自己手工建立編輯)檔案内容具體如下:
# this config needs haproxy-1.1.28 or haproxy-1.2.1
global
log 127.0.0.1 local0
log 127.0.0.1 local1 notice
#log loghost local0 info
maxconn 4096
chroot /usr/share/haproxy
uid 99
gid 99
daemon
#debug
#quiet
defaults
log global
mode tcp
option tcplog
option dontlognull
retries 3
option redispatch
maxconn 2000
timeout connect 5000
timeout client 50000
timeout server 50000
listen rabbitmq_local_cluster 10.10.169.30:5670
mode tcp
balance roundrobin
server rabbit 192.168.101.48:5672 check inter 5000 rise 2 fall 3
server rabbit_1 192.168.101.49:5672 backup check inter 5000 rise 2 fall 3
listen admin_stats
bind 0.0.0.0:8100
mode http
option httplog
stats enable
stats uri /stats
stats refresh 5s
4.啟動
安裝部署好haproxy,啟動haproxy使用如下指令:
./haproxy -f /data/RabbitMQ/haproxy/examples/haproxy.cfg
檢測到haproxy程序存在
5.登陸
登陸192.168.101.48:8100/stats 預設賬戶密碼 admin/admin 如果需要修改密碼,可以去haproxy.cfg 檔案進行編輯修改。