当前位置: 代码迷 >> 综合 >> rabbitmq+haproxy 集群高可用一
  详细解决方案

rabbitmq+haproxy 集群高可用一

热度:26   发布时间:2024-01-09 05:19:09.0


环境
主机 192.168.2.47      hidden1(主机名)
主机 192.168.2.48      hidden2 (主机名)
介绍:1, 先两台主机更改好主机名 2,部署单机rabbitmq   3,然后再加入 集群

一,rabbitmq 单机安装(两台主机都做同样的操作)
1. 安装erlang

[root@hidden1 ~]yum install -y gcc gcc-c++ glibc-devel make ncurses-devel openssl-devel autoconf java-1.8.0-openjdk-devel git

RabbbitMQ基与erlang开发,首先安装erlang,这里采用yum方式。

 [root@hidden1 ~]vim /etc/yum.repos.d/rabbitmq-erlang.repo
````
[rabbitmq-erlang]
name=rabbitmq-erlang
baseurl=https://dl.bintray.com/rabbitmq/rpm/erlang/20/el/7
gpgcheck=1
gpgkey=https://dl.bintray.com/rabbitmq/Keys/rabbitmq-release-signing-key.asc
repo_gpgcheck=0
enabled=1
````
[root@hidden1 ~] yum install erlang

需要安装验证签名的公钥;
[root@hidden1 ~] rpm --import https://packages.erlang-solutions.com/rpm/erlang_solutions.asc
2. 安装RabbitMQ
1)下载RabbitMQ
[root@hidden1 ~] wget https://github.com/rabbitmq/rabbitmq-server/releases/download/v3.7.4/rabbitmq-server-3.7.4-1.el7.noarch.rpm
2)导入认证签名
[root@hidden1 ~] rpm --import https://www.rabbitmq.com/rabbitmq-release-signing-key.asc
3)安装
yum安装使用已下载的rpm包本地安装,但可能会涉及到取依赖包,同样需要导入认证签名;
下载安装请见:http://www.rabbitmq.com/install-rpm.html

[[root@hidden1 ~] yum install rabbitmq-server-3.7.4-1.el7.noarch.rpm -y
3.配置文件 rabbitmq.conf
手工建目录,将配置样例文件拷贝到配置目录并改名

[root@hidden1 ~] mkdir -p /etc/rabbitmq
[root@hidden1 ~] cp /usr/share/doc/rabbitmq-server-3.7.4/rabbitmq.config.example /etc/rabbitmq/rabbitmq.config
另外还可以建环境配置文件:
[root@hidden1 ~]/etc/rabbitmq/rabbitmq-env.conf
````
RABBITMQ_MNESIA_BASE=/home/data/rabbitmq/data
RABBITMQ_LOG_BASE=/home/data/rabbitmq/log
RABBITMQ_PLUGINS_DIR=/usr/lib/rabbitmq/lib/rabbitmq_server-3.7.4/plugins
````
4. 启动
1)设置开机启动
[root@hidden1 ~] systemctl enable rabbitmq-server
2)启动
[root@hidden1 ~] systemctl start rabbitmq-server
5. 验证
1)查看状态
[root@hidden1 ~] systemctl status rabbitmq-server
6. 安装web管理插件
management plugin默认就在RabbitMQ的发布版本中,enable即可 服务重启,配置生效
[root@hidden1 ~] rabbitmq-plugins enable rabbitmq_management
7. 设置iptables
tcp4369端口用于集群邻居发现;
tcp5671,5672端口用于AMQP 0.9.1 and 1.0 clients使用;
tcp15672端口用于http api与rabbitadmin访问,后者仅限在management plugin开启时;
tcp25672端口用于erlang分布式节点/工具通信
[root@hidden1 ~] vim /etc/sysconfig/iptables
````
-A INPUT -p tcp -m state --state NEW -m tcp --dport 4369 -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 5671 -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 5672 -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 15672 -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 25672 -j ACCEPT
````
[root@hidden1 ~] service iptables restart
8. Management plugin登录账
1)guest账号
abbit默认只有guest账号,但为了安全,guest账号只能从localhost登录,如果需要guest账号可以远程登录,可以设置rabbitmq.conf文件:
根据说明,取消第64行参数的注释与句末的符号;建议不开启guest账号的远程登录;
服务重启,配置生效。
[root@hidden1 ~] vim /etc/rabbitmq/rabbitmq.config
2)CLI创建登录账号
“rabbitmqctl add_user”添加账号,并设置密码
[root@hidden1 ~] rabbitmqctl add_user admin admin@123
”rabbitmqctl set_user_tags”设置账号的状态
[root@hidden1 ~] rabbitmqctl set_user_tags admin administrator
“rabbitmqctl set_permissions”设置账号的权限

[root@hidden1 ~] rabbitmqctl set_permissions -p "/" admin ".*" ".*" ".*"

“rabbitmqctl list_users”列出账号
[root@hidden1 ~] rabbitmqctl list_users

9. Management plugin登录验证
浏览器访问:http://192.168.2.47:15672                                                                                                                                                                                                                                                                             
 

  相关解决方案