由于rabbitmq需要erlang环境,在安装前,先要安装好erlang,才能安装rabbitmq,然后下载插件,最后enable插件。
安装erlang
安装erlang的依赖 : yum -y install make gcc gcc-c++ kernel-devel m4 ncurses-devel openssl-devel
下载erlang rpm包: wget https://packages.erlang-solutions.com/erlang/rpm/centos/7/x86_64/esl-erlang_22.1.8-1~centos~7_amd64.rpm
安装: yum install esl-erlang_22.1.8-1~centos~7_amd64.rpm
安装rabbitmq
下载rabbitmq: wget https://github.com/rabbitmq/rabbitmq-server/releases/download/v3.8.2/rabbitmq-server-3.8.2-1.el7.noarch.rpm
导入公钥:rpm –import https://www.rabbitmq.com/rabbitmq-release-signing-key.asc
安装: yum install rabbitmq-server-3.8.2-1.el7.noarch.rpm
错误解决:如果出现错误Error unpacking rpm package rabbitmq-server-3.8.2-1.el7.noarch。请重新下载rabbitmq-server-3.8.2-1.el7.noarch.rpm
设置开启自动启动和web管理界面
chkconfig rabbitmq-server on
rabbitmq-plugins enable rabbitmq_management
添加用户和外网访问
rabbitmqctl add_user admin abc124
rabbitmqctl set_user_tags admin administrator
rabbitmqctl set_permissions -p / admin ‘.*’ ‘.*’ ‘.*’
rabbitmqctl list_user_permissions admin
安装delay插件(默认目录)
下载插件: wget https://github.com/rabbitmq/rabbitmq-delayed-message-exchange/releases/download/v3.8.0/rabbitmq_delayed_message_exchange-3.8.0.ez
复制:cp rabbitmq_delayed_message_exchange-3.8.0.ez /usr/lib/rabbitmq/lib/rabbitmq_server-3.8.2/plugins/
启用:rabbitmq-plugins enable rabbitmq_delayed_message_exchange
单机启动/集群忽略:systemctl start rabbitmq-server
集群化
编辑每台RabbitMQ的cookie文件,以确保各个节点的cookie文件使用的是同一个值。cookie的默认路径为/var/lib/rabbitmq/.erlang.cookie,节点之间通过cookie确定相互是否可通信。
rabbitmq启动报错 .erlang.cookie must be accessible by owner only
解决:在挂载的主机上运行 chmod 600 /var/lib/rabbitmq/.erlang.cookie
配置每台服务器hosts vim /etc/hosts
xxx.xxx.xxx.xxx rmq-broker-test-1
xxx.xxx.xxx.xxx rmq-broker-test-2
xxx.xxx.xxx.xxx rmq-broker-test-3
配置防火墙(生产环境不需要,通过域名映射)
开启防火墙 systemctl start firewalld
配置网页15672端口 firewall-cmd --permanent --add-port=15672/tcp
配置AMQP端口 firewall-cmd --permanent --add-port=5672/tcp
重启服务 systemctl restart firewalld.service
加入集群
rabbitmqctl stop_app
rabbitmqctl reset
rabbitmqctl join_cluster rabbit@rmq-broker-test-2 --ram 内存节点
rabbitmqctl start_app