RabbitMQ多种方式安装及管理界面搭建
RabbitMQ多种方式安装及管理界面搭建
测试环境说明
主机名 | ip | 操作系统版本 | docker版本 | rabbitmq版本 | erlang版本 | 安装方式 |
---|---|---|---|---|---|---|
shell | 172.16.7.100 | Centos 7.6.1810 | 19.03.9 | 3.8.14 | 23 | docker |
ansible-tower | 172.16.7.110 | Centos 7.6.1810 | / | 3.8.14 | 23 | yum |
一、安装RabbitMQ
1.docker方式
docker安装请参考:k8s实践(一):Centos7.6部署k8s(v1.14.2)集群中docker安装章节。
1.1下载镜像
[root@shell ~]# docker pull rabbitmq Using default tag: latest latest: Pulling from library/rabbitmq 6e0aa5e7af40: Pull complete d47239a868b3: Pull complete 49cbb10cca85: Pull complete b7c2edd50e35: Pull complete f90847e29a88: Pull complete cf630c043069: Pull complete 40d3331baa6b: Pull complete 13774dd2f339: Pull complete 5c4d53cae261: Pull complete 67eacc1aadd9: Pull complete Digest: sha256:fee70e7e568db7da0043773d3bad64dbdcd922ecfd9a1050e26b49564fad040f Status: Downloaded newer image for rabbitmq:latest docker.io/library/rabbitmq:latest
下载rabbitmq镜像,版本为最新版。
1.2执行安装
[root@shell ~]# docker run -itd --restart=always --name rabbitmq -p 5672:5672 -p 15672:15672 rabbitmq 2ba7589efcf02797575c59a825de4b47e14cc4059bfcd01913b8fbdc8c5d98f9
'-itd':后台运行容器;'--restart=always':主机重启后容器自启动;'--name rabbitmq'容器名为rabbitmq;'-p 5672:5672':将本地的5672端口映射到容器的5672端口;镜像为rabbitmq。
1.3进入容器
[root@shell ~]# docker exec -it rabbitmq bash
通过docker exec命令进入容器rabbitmq并查看状态
完成docker方式的rabbitmq安装。
2.yum方式安装
2.1导入秘钥
[root@ansible-tower ~]# rpm --import https://github.com/rabbitmq/signing-keys/releases/download/2.0/rabbitmq-release-signing-key.asc [root@ansible-tower ~]# rpm --import https://packagecloud.io/rabbitmq/erlang/gpgkey [root@ansible-tower ~]# rpm --import https://packagecloud.io/rabbitmq/rabbitmq-server/gpgkey
Yum将验证其安装的所有软件包的签名,因此该过程的第一步是导入签名密钥
2.2配置安装源
[root@ansible-tower ~]# more /etc/yum.repos.d/rabbitmq.repo # In /etc/yum.repos.d/rabbitmq.repo ## ## Zero dependency Erlang ## [rabbitmq_erlang] name=rabbitmq_erlang baseurl=https://packagecloud.io/rabbitmq/erlang/el/7/$basearch repo_gpgcheck=1 gpgcheck=1 enabled=1 # PackageCloud's repository key and RabbitMQ package signing key gpgkey=https://packagecloud.io/rabbitmq/erlang/gpgkey https://github.com/rabbitmq/signing-keys/releases/download/2.0/rabbitmq-release-signing-key.asc sslverify=1 sslcacert=/etc/pki/tls/certs/ca-bundle.crt metadata_expire=300 [rabbitmq_erlang-source] name=rabbitmq_erlang-source baseurl=https://packagecloud.io/rabbitmq/erlang/el/7/SRPMS repo_gpgcheck=1 gpgcheck=0 enabled=1 # PackageCloud's repository key and RabbitMQ package signing key gpgkey=https://packagecloud.io/rabbitmq/erlang/gpgkey sslverify=1 sslcacert=/etc/pki/tls/certs/ca-bundle.crt metadata_expire=300 ## ## RabbitMQ server ## [rabbitmq_server] name=rabbitmq_server baseurl=https://packagecloud.io/rabbitmq/rabbitmq-server/el/7/$basearch repo_gpgcheck=1 gpgcheck=0 enabled=1 gpgkey=https://packagecloud.io/rabbitmq/rabbitmq-server/gpgkey sslverify=1 sslcacert=/etc/pki/tls/certs/ca-bundle.crt metadata_expire=300 [rabbitmq_server-source] name=rabbitmq_server-source baseurl=https://packagecloud.io/rabbitmq/rabbitmq-server/el/7/SRPMS repo_gpgcheck=1 gpgcheck=0 enabled=1 gpgkey=https://packagecloud.io/rabbitmq/rabbitmq-server/gpgkey sslverify=1 sslcacert=/etc/pki/tls/certs/ca-bundle.crt metadata_expire=300
新建yum源文件rabbitmq.repo
2.3源更新
[root@ansible-tower ~]# yum update -y yum -q makecache -y --disablerepo='*' --enablerepo='rabbitmq_erlang' --enablerepo='rabbitmq_server'
更新源和缓存,方便安装
2.4依赖包及rabbitmq安装
[root@ansible-tower ~]# yum install socat logrotate -y [root@ansible-tower ~]# yum install erlang rabbitmq-server -y
安装依赖包
[root@ansible-tower ~]# yum install erlang rabbitmq-server -y
安装erlang和rabbitmq,rabbitmq由erlang语言编写,所以在安装rabbitmq需安装erlang。
2.5验证
[root@ansible-tower ~]# erl [root@ansible-tower ~]# rabbitmqctl status
安装完成后可以正常运行erl和rabbitmqctl命令
2.6启动rabbitmq
[root@ansible-tower ~]# systemctl list-unit-files |grep mq dev-mqueue.mount static rabbitmq-server.service disabled [root@ansible-tower ~]# systemctl status rabbitmq-server [root@ansible-tower ~]# systemctl enable rabbitmq-server [root@ansible-tower ~]# systemctl start rabbitmq-server
启动rabbitmq并设置为开机启动
完成yum方式的rabbitmq安装。
二、启动web管理界面
RabbitMQ management插件可以提供Web管理界面用来管理如前面所述的虚拟主机、用户等,也可以用来管理队列、交换器、绑定关系、策略、参数等,还可以用来监控RabbitMQ服务的状态及一些数据统计类信息,可谓是功能强大,基本上能够涵盖所有RabbitMQ管理的功能。
在使用Web管理界面之前需要先启用RabbitMQ management插件。
1.启用management插件
[root@ansible-tower ~]# rabbitmq-plugins enable rabbitmq_management [root@ansible-tower ~]# rabbitmq-plugins list
启用查看management插件
2.web登陆
登陆地址:http://172.16.7.110:15672/
web界面已经可以打开,还需要登陆用户
3.新增访问用户
[root@ansible-tower ~]# rabbitmqctl add_user admin Admin123! Adding user "admin" ... Done. Don't forget to grant the user permissions to some virtual hosts! See 'rabbitmqctl help set_permissions' to learn more. [root@ansible-tower ~]# rabbitmqctl set_permissions -p / admin ".*" ".*" ".*" Setting permissions for user "admin" in vhost "/" ... [root@ansible-tower ~]# rabbitmqctl set_user_tags admin administrator Setting tags for user "admin" to [administrator] ... [root@ansible-tower ~]# rabbitmqctl list_users Listing users ... user tags admin [administrator] guest [administrator]
新建用户admin并授权
4.使用admin账号登陆
该账号后期做生产者消费者测试时会用到。
@版权声明:51CTO独家出品,未经允许不能转载,否则追究法律责任