RabbitMQ 映象叢集

hujunmin發表於2024-06-27

安裝 erlang

cd /usr/local/src/
wget https://github.com/rabbitmq/erlang-rpm/releases/download/v26.2.5/erlang-26.2.5-1.el8.x86_64.rpm
rpm -ivh erlang-26.2.5-1.el8.x86_64.rpm

#安裝 rabbitmq

cd /usr/local/src/
wget https://github.com/rabbitmq/rabbitmq-server/releases/download/v3.13.3/rabbitmq-server-3.13.3-1.el8.noarch.rpm
rpm -ivh rabbitmq-server-3.13.3-1.el8.noarch.rpm

#開啟自啟動

chkconfig rabbitmq-server on

#服務命令

#檢視狀態
/sbin/service rabbitmq-server status

#啟動
/sbin/service rabbitmq-server start

#停止
/sbin/service rabbitmq-server stop

#開啟web管理頁面(不開啟的話沒有web頁面)

rabbitmq-plugins enable rabbitmq_management

#安裝 mqtt 外掛

rabbitmq-plugins enable rabbitmq_mqtt

#安裝延遲佇列外掛

cd /usr/local/src/
wget https://github.com/rabbitmq/rabbitmq-delayed-message-exchange/releases/download/v3.13.0/rabbitmq_delayed_message_exchange-3.13.0.ez

cp rabbitmq_delayed_message_exchange-3.13.0.ez /usr/lib/rabbitmq/lib/rabbitmq_server-3.13.3/plugins
cd /usr/lib/rabbitmq/lib/rabbitmq_server-3.13.3/plugins
rabbitmq-plugins enable rabbitmq_delayed_message_exchange

#新增賬號 https://juejin.cn/post/7059382641396547615

rabbitmqctl add_user username password
rabbitmqctl set_user_tags username administrator
rabbitmqctl set_permissions -p / username ".*" ".*" ".*"

叢集搭建

#設定 erlang cookie 一致性

cd /var/lib/rabbitmq/
vim .erlang.cookie 
#將所有伺服器上設定一致的

#修改許可權

# 修改使用者組
chown rabbitmq:rabbitmq /var/lib/rabbitmq/.erlang.cookie

# 僅只有所有者可讀
chmod 400 /var/lib/rabbitmq/.erlang.cookie

#修改hostname

vim /etc/hosts
# master
172.*.*.2 app1

#slave
172.*.*.3 app2

#修改主機名

#修改主機名( master )
hostnamectl set-hostname app1

#修改主機名( slave)
hostnamectl set-hostname app2

#修改節點名稱

vim /etc/rabbitmq/rabbitmq.conf
#master 使用這行
NODENAME=rabbit@app1 

#slave 使用這行
#NODENAME=rabbit@app2

slave 設定 cluster 節點

rabbitmqctl stop_app
rabbitmqctl reset
rabbitmqctl join_cluster rabbit@app1
rabbitmqctl start_app

 

相關文章