vim /etc/hosts
10.10.21.197 rabbit1
10.10.21.198 rabbit2node
#分別命名
hostname rabbit1
hostname rabbit2vim
vim /etc/yum.repos.d/rabbitmq.repo
[bintray-rabbitmq-server]
name=bintray-rabbitmq-rpm
baseurl=https://dl.bintray.com/rabbitmq/rpm/rabbitmq-server/v3.7.x/el/7/
gpgcheck=0
repo_gpgcheck=0
enabled=1服務器
[rabbitmq-erlang]
name=rabbitmq-erlang
baseurl=https://dl.bintray.com/rabbitmq-erlang/rpm/erlang/22/el/7
gpgcheck=1
gpgkey=https://dl.bintray.com/rabbitmq/Keys/rabbitmq-release-signing-key.asc
repo_gpgcheck=0
enabled=1cookie
yum install rabbitmq-serversession
cp /usr/share/doc/rabbitmq-server-3.7.20/rabbitmq.config.example /etc/rabbitmq/rabbitmq.configapp
systemctl start rabbitmq-serverdom
rabbitmqctl add_user admin 123456
rabbitmqctl set_permissions admin ".*" ".*" ".*"
rabbitmqctl set_user_tags admin administratortcp
rabbitmq-plugins enable rabbitmq_management
rabbitmq-plugins listpost
scp /var/lib/rabbitmq/.erlang.cookie 192.168.10.202:/var/lib/rabbitmq/.erlang.cookieurl
#兩臺
chmod 400 /var/lib/rabbitmq/.erlang.cookie
systemctl stop rabbitmq-server
rabbitmq-server -detached
# 在要加入集羣的節點操做
rabbitmqctl stop_app #中止應程序
rabbitmqctl reset #清空元數據
rabbitmqctl join_cluster rabbit@rabbit1 --ram #將rabbitmq-server1添加到集羣當中,併成爲內存節點,不加--ram默認是磁盤節點
rabbitmqctl start_app #不要忘記啓動應用程序
# 移除節點
# 軟刪除
# 若是想要把節點從集羣中移除,可以使用以下命令實現:
rabbitmqctl stop_app
rabbitmqctl reset
rabbitmqctl start_app
rabbitmqctl cluster_status
# 硬刪除
# 直接刪掉集羣中的某個節點
rabbitmqctl forget_cluster_node rabbit@Demo20
# 更改成鏡像模式
rabbitmqctl set_policy ha-all "#" '{"ha-mode":"all"}'
#####################我把RabbitMQ的管理界面也放在HAProxy後面了###############################
listen rabbitmq_admin
bind 0.0.0.0:15673
server rabbitmq1 10.10.21.197:15672
server rabbitmq2 10.10.21.198:15672
#####################RabbitMQ服務代理###########################################listen rabbitmq_cluster 0.0.0.0:5673 mode tcp stats enable balance roundrobin option tcpka option tcplog timeout client 3h timeout server 3h timeout connect 3h #balance url_param userid #balance url_param session_id check_post 64 #balance hdr(User-Agent) #balance hdr(host) #balance hdr(Host) use_domain_only #balance rdp-cookie #balance leastconn #balance source //ip server rabbitmq1 10.10.21.197:5672 check inter 5s rise 2 fall 3 #check inter 2000 是檢測心跳頻率,rise 2是2次正確認爲服務器可用,fall 3是3次失敗認爲服務器不可用 server rabbitmq2 10.10.21.198:5672 check inter 5s rise 2 fall 3