rabbitMQ 安装,集群搭建, 编码
RabbitMQ
一、背景
命令行工具:
http://www.rabbitmq.com/man/rabbitmqctl.1.man.html
介绍入门文章:
http://blog.csdn.net/anzhsoft/article/details/19563091
内容比较清晰: http://www.diggerplus.org/archives/3110
Exchange、Queue
producer把消息发送到Exchange(带上route key),consumer声明queue(带上bind key),然后根据结合Exchange的类型(fanout、direct、topic、headers),进行路由到不同的queue上面。
fanout(广播):route key和 bind key不生效,所有bind到改Exchange的queue都会收到同一份message。bind的时候,queue的名称必须不一样(如果一样,两个一样的consumer,只有其中一个能收到消息)
direct:必须要route key 和 bind key完全相等,才会收到(一个queue可以提供多个bind key到Exchange,只要其中一个满足,就会收到消息;多个queue也可以用同一个bind key,这样会收到同样的消息)
topic:对route key进行了简单的正则匹配
同时还支持RPC模式:
如果在Exchange上面没有bind一个queue,即使producer发送的是一个持久化消息,后面再bind queue的consumer也是收不到之前的消息的。所以queue必须要先创建,如果想一直收到消息,queue必须是持久化的。
q, err := ch.QueueDeclare( | |
"queuename", // name | |
true, // durable | |
false, // delete when usused | |
true, // exclusive | |
false, // no-wait | |
nil, // arguments | |
) |
同样,如果想consumer没起来之前,也能收到producer之前发送的消息,那需要提前把对应的queue name创建好,bind好对应的Exchange
二、开搞,部署,搭建集群
可参考集群部署:
http://blog.csdn.net/jljf_hh/article/details/17381425
部署之前,必须要弄明白erlang cookie这个玩意儿。
Rabbitmq的集群是依附于erlang的集群来工作的,所以必须先构建起erlang的集群景象。Erlang的集群中各节点是经由过程一个magic cookie来实现的,这个cookie存放在 $home/.erlang.cookie 中(像我的root用户安装的就是放在我的root/.erlang.cookie中),文件是400的权限。所以必须包管各节点cookie对峙一致,不然节点之间就无法通信。
Erlang cookie
Erlang nodes use a cookie to determine whether they are allowed to communicate with each other - for two nodes to be able to communicate they must have the same cookie. The cookie is just a string of alphanumeric characters. It can be as long or short as you like.
Erlang will automatically create a random cookie file when the RabbitMQ server starts up. The easiest way to proceed is to allow one node to create the file, and then copy it to all the other nodes in the cluster.
On Unix systems, the cookie will be typically located in ll /var/lib/rabbitmq/.erlang.cookie or$HOME/.erlang.cookie.
On Windows, the locations are C:\Users\Current User\.erlang.cookie(%HOMEDRIVE% + %HOMEPATH%\.erlang.cookie) orC:\Documents and Settings\Current User\.erlang.cookie, and C:\Windows\.erlang.cookie for RabbitMQ Windows service. If Windows service is used, the cookie should be placed in both places.
As an alternative, you can insert the option "-setcookie cookie" in the erl call in the rabbitmq-server andrabbitmqctl scripts.
参考:http://www.tuicool.com/articles/YbYvIj
Ubuntu上面部署:
直接参考官网,几个命令就搞掂:
To use our APT repository:
1)Add the following line to your /etc/apt/sources.list:
deb http://www.rabbitmq.com/debian/ testing main
(Please note that the word testing in this line refers to the state of our release of RabbitMQ, not any particular Debian distribution. You can use it with Debian stable, testing or unstable, as well as with Ubuntu. We describe the release as "testing" to emphasise that we release somewhat frequently.)
(optional) To avoid warnings about unsigned packages, add our public key to your trusted key list using apt-key(8):
2)wget http://www.rabbitmq.com/rabbitmq-signing-key-public.asc
sudo apt-key add rabbitmq-signing-key-public.asc
3)Run apt-get update.
Install packages as usual; for instance,
sudo apt-get install rabbitmq-server
CentOS上面部署:
安装一个erlang的安装环境:
rpm -i http://mirror.bjtu.edu.cn/fedora-epel/6/x86_64/epel-release-6-8.noarch.rpm
yum install erlang
安装rabbitMQ(RPM链接可以从http://www.rabbitmq.com/install-rpm.html来获取)
rpm -ivh http://www.rabbitmq.com/releases/rabbitmq-server/v3.4.2/rabbitmq-server-3.4.2-1.noarch.rpm
虽然总结起来是这么几行,特么的琢磨了好几个小时。
安装完毕之后,就可以组织集群了。
启动:/sbin/service rabbitmq-server start
可以通过命令开启管理界面插件:rabbitmq-plugins enable rabbitmq_management
然后:http://IP:15672/ 进入管理界面来查看rabbitMQ的信息。
开始搭建集群:
1。添加用户
在两台机器分别创建一个用户,并设置为管理员,否则通过管理界面是无法登陆的。
rabbitmqctl add_user sky password
rabbitmqctl set_user_tags sky administrator
2.同步erlang cookie 数据
如果修改erlang cookie文件之前,erlang的进程和rabbitmq已经启动,把他们都stop或者kill掉。改完erlang cookie之后再重启
Erlang cookie的路径上面说过,保证内容一致即可。
3.配置hosts,把各个节点的host name和 IP配置在hosts中,以便可以相互通信
这里的hostname 是 rabbit@OLYMTECH 格式中@后面的文字,例如这里是:10.12.13.54 OLYMTECH
4.分别启动两个节点
rabbitmq-server -detached
5.在从节点上面,join到master节点,
host2# rabbitmqctl stop_app
host2# rabbitmqctl join_cluster rabbit@OLYMTECH PS:这里OLYMTECH是不用执行这个的,是让OLYMTECH以外的node加入到以他为名的cluster中去
host2# rabbitmqctl start_app如果加入和启动成功,就能在管理界面上面看到节点信息了(这里两个节点都是持久化类型的,如果有需要可以在join_cluster 加上—ram选项,配置为内存节点):
这里如果出现启动或stop失败,ps rabbit进程,按个全部kill掉,再重来一遍。
6.添加策略
rabbitmqctl set_policy ha-all "^ha\." '{"ha-mode":"all"}'
凡是ha. 开始的queue的数据,会同步到集群的所有node
OK,这样就搭建好了,然后就可以写代码搞起了。
这里如果要做负载,HA,就需要在前面搭一套TCP的代理,负责监听转发,例如:HAProxy, LVS+keepalive。我还没搞过。
程序连接时报错:
2014/12/16 11:44:31 emit_log.go:14: Failed to connect to RabbitMQ: Exception (403) Reason: "no access to this ghost"
是因为没有配置该用户的访问权限,可以通过
rabbitmqctl add_vhost skytest
来添加,并赋予权限:
rabbitmqctl set_permissions -p sky skytest ".*" ".*" ".*"
同样,代码在连接的时候,必须制定对应的vhost,否则是没有访问权限滴:
conn, err := amqp.Dial("amqp://sky:password@10.44.55.66:5672/skytest”)
go语言的库,可参考:
https://godoc.org/github.com/streadway/amqp
rabbitMQ 安装,集群搭建, 编码的更多相关文章
- RabbitMQ入门教程(十四):RabbitMQ单机集群搭建
原文:RabbitMQ入门教程(十四):RabbitMQ单机集群搭建 版权声明:本文为博主原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明. 本文链接:https://b ...
- RabbitMQ之集群搭建
1.RabbitMQ集群模式RabbitMQ集群中节点包括内存节点(RAM).磁盘节点(Disk,消息持久化),集群中至少有一个Disk节点. 2.普通模式(默认) 对于普通模式,集群中 ...
- Consul安装集群搭建
1 consul的安装和配置 1.1 consul agent 命令介绍 下载consul_1.0.0_linux_amd64.zip解压,里面只有一个consul可执行文件,其中,consul最常用 ...
- rabbitmq普通集群搭建详细步骤
由于工作需求,需要安装rabbitmq,学习之余,记录一下安装过程 准备基础编译环境yum install gcc glibc-devel make ncurses-devel openssl-dev ...
- RabbitMQ镜像集群搭建
RabbitMQ 官网 https://www.rabbitmq.com/ 小编使用的系统环境是CentOS7.4 系统 IP hostname CentOS7.4 1.1.1.1 hostname0 ...
- RabbitMQ单机集群搭建出现Error: unable to perform an operation on node 'rabbit1@ClusterNode1'
参考链接:https://www.cnblogs.com/daryl/archive/2017/10/13/7645749.html 全部步骤和参考链接相同. 前八部都正常,在第九步会报错Error: ...
- rabbitmq安装集群
centos 7.3 64 172.18.39.241 k8s-mini-241172.18.39.242 k8s-mini-242172.18.39.243 k8s-master-243 vim / ...
- RabbitMQ的安装及集群搭建方法
RabbitMQ安装 1 安装erlang 下载地址:http://www.erlang.org/downloads 博主这里采用的是otp_src_19.1.tar.gz (200MB+) [roo ...
- rabbitmq安装、集群搭建
rabbitmq的安装: CentOS上面部署: 首先修改hosts文件 修改hosts文件vi /etc/hosts1.1.1.1 hostname 2.2.2.2 hostname 3.3.3.3 ...
随机推荐
- iOS中autolaylout和sizeclass的理解
没发现居然有三四个月没写博客了,好惭愧.都是加班太多了,还好现在换了一家,还是得继续写啊. 主要是学习了http://onevcat.com/上的内容写的笔记,并自己动手操作了一下. 已经排好版了,懒 ...
- Eclipse报Caused by: java.lang.OutOfMemoryError: PermGen space解决思路
一.修改tomcat/bin目录下的catalina.bat 在“rem ----- Execute The Requested Command ----------------------”下加入 ...
- LigerUI 树状列表折叠显示
http://blog.csdn.net/haojuntu/article/details/8626040 —————————————————————————————————————————————— ...
- Linux环境PHP7.0.2安装
PHP7和HHVM比较PHP7的在真实场景的性能确实已经和HHVM相当, 在一些场景甚至超过了HHVM.HHVM的运维复杂, 是多线程模型, 这就代表着如果一个线程导致crash了, 那么整个服务就挂 ...
- 2015 Multi-University Training Contest 5 1009 MZL's Border
MZL's Border Problem's Link: http://acm.hdu.edu.cn/showproblem.php?pid=5351 Mean: 给出一个类似斐波那契数列的字符串序列 ...
- 31Mybatis_mybatis和spring整合-mapper代理开发
案例结构图:
- Applet是java的自动执行方式(这是它的优势,主要用于HTML)
进度条:ProgressBar. JcomboBox:下拉菜单:在AWT中同类组件是choice. JlistPanel:选择列表 BorderPanel:设置边框 JsplitPanel:可将容器分 ...
- 使用JavaScript 和 CSS 实现图像缩放和剪裁(转)
英文原文:Scale and Crop an Image using Javascript and CSS 在页面上需要裁减和缩放一张图片是一个常见问题.缩放图片比较简单的方法是使用image的hig ...
- hdu 3791:二叉搜索树(数据结构,二叉搜索树 BST)
二叉搜索树 Time Limit : 2000/1000ms (Java/Other) Memory Limit : 32768/32768K (Java/Other) Total Submiss ...
- 怎么用MathType解决Word公式排版很乱的问题
现在办公室起草文件,期刊论文投稿.学校试着编辑都要先在Word中编辑好后再打印出来.在Word中编辑这些文本内容时,如果遇到公式就要使用专门的MathType公式编辑器.而有很多人在用MathType ...