环境准备
本次实验使用的是VMvare虚拟机。详情如下
hostname: node1.server
ip地址:192.168.0.150 网卡:eth0,eth1
系统及硬件:CentOS 7.2 内存2G,硬盘50G
一、 什么是RabbitMq
消息队列又称为MQ,应用程序间的消息通信工具,其有利于程序解耦、多语言集成、异步通信、扩展和简单负载均衡等,是生产-消费者模型的典型代表。常见MQ产品有RabbitMQ ZeroMQ Kafka等等。
RabbitMQ,老牌MQ产品,基于erlang语言,实现对AMQP等协议的支持,重量级,适合企业级应用开发;Kafka,linkedin开源MQ产品,追求高吞吐量,适合于大量数据的收集业务,如互联网业务产生的大量日志数据;ZeroMQ,号称最快的MQ,提供了一套异步消息通信库,可实现RabbitMQ不能实现的高级复杂队列;Kafka和RabbitMQ都需要搭建消息代理服务器,采用中间件模式。ZeroMQ采用非中间件模式,不需要搭建消息代理服务器;
二、 部署
# yum
install
gcc
gcc
-c++
make
gcc
gcc
-c++ kernel-devel m4 ncurses-devel openssl-devel
zlib
zlib-devel xmlto libgnomeui-devel nc libX* java* tk unixODBC unixODBC-devel -y
# yum install http://dl.fedoraproject.org/pub/epel/7/x86_64/e/epel-release-7-5.noarch.rpm -y
# yuminstall rabbitmq-server -y
# systemctl enable rabbitmq-server.service
# systemctl start rabbitmq-server.service
Job for rabbitmq-server.service failed becausethe control process exited with error code. See "systemctl statusrabbitmq-server.service"and"journalctl -xe" for details.
解决方法:
修改主机名和hosts
修改前:
# hostnamectl status
Static hostname: node1.server
Icon name: computer-vm
Chassis: vm
Machine ID: d359f0058624494aa3c144477c6d97b8
Boot ID: bdd32e5df98a41259a441a079c0c44b3
Virtualization: vmware
Operating System: CentOS Linux 7 (Core)
CPE OS Name: cpe:/o:centos:centos:7
Kernel: Linux 3.10.0-327.el7.x86_64
Architecture: x86-64
修改后:
# hostnamectl --static set-hostname node1 # hostnamectl status
Static hostname: node1
Transient hostname: node1.server
Icon name: computer-vm
Chassis: vm
Machine ID: d359f0058624494aa3c144477c6d97b8
Boot ID: bdd32e5df98a41259a441a079c0c44b3
Virtualization: vmware
Operating System: CentOS Linux 7 (Core)
CPE OS Name: cpe:/o:centos:centos:7
Kernel: Linux 3.10.0-327.el7.x86_64
Architecture: x86-64
# cat /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.0.150 node1
启用Rabbitmq的web管理插件
RabbitMQ提供了一套插件机制,方便功能扩展。这里介绍一个最常用的:rabbitmq_management。这款插件提供了完善的web管理和监控功能,提供了各项指标。
# rabbitmq-plugins enable rabbitmq_management
The following plugins have been enabled:
Mochiweb
Webmachine
rabbitmq_web_dispatch
amqp_client
rabbitmq_management_agent
rabbitmq_management
Applying plugin configuration to [email protected] started 6 plugins.
新建Rabbitmq用户并授权
# rabbitmqctl add_user openstack openstack
Creating user "openstack" ... # rabbitmqctl set_permissions openstack ".*" ".*" ".*"
Setting permissions for user "openstack" in vhost "/" ...
# systemctl restart rabbitmq-server.service 查看Rabbit的端口,其中5672是服务端口,15672是web管理端口,25672是做集群的端口
# ss -tunlp|grep 5672
在web界面添加openstack用户,设置权限,首次登陆必须使用账号和密码,必须都是guest
role设置为administrator,并设置openstack的密码为openstack
若想要监控Rabbit,即可使用下图中的API