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 ...
随机推荐
- python walk函数
os.walk方法 import os for i in os.walk(r'C:\Users\jack\Desktop\test\3_语文语文版七年级上册\1_一单元'): print(i[0]) ...
- [内核]Linux UserSpace和Kernel之间如何联系
转自:http://blog.csdn.net/dreaming_my_dreams/article/details/8272586 应用层和驱动的衔接,一直是一个老大难问题,若弄不清楚,总觉得驱动写 ...
- Qt下QTableWidget的使用
1.QTableWidget的基本设置 ui->tableWidget->setColumnCount(11); ui->tableWidget->setRowCount(Nu ...
- sudo非交互式输入密码
sudo非交互式输入密码 编辑 删除 我们在使用sudo命令的时候,为了避免交互,可以使用 echo 'password' |sudo -S cmd 这样的方式,通过管道传入密码,就不用手动输入了. ...
- Entity Framework(三):使用特性(数据注解)创建表结构
一.理解Code First及其约定和配置 传统设计应用的方式都是由下而上的,即我们习惯优先考虑数据库,然后使用这个以数据为中心的方法在数据之上构建应用程序.这种方法非常适合于数据密集的应用或者数据库 ...
- ActionContextCleanUp
ActionContextCleanUp作用 延长action中属性的生命周期,包括自定义属性,以便在jsp页面中进行访问,让actionContextcleanup过滤器来清除属性,不让acti ...
- 异常之*** buffer overflow detected ***
*** buffer overflow detected *** 是sprintf()超出buff大小
- Apache -- 压力测试工具ab.exe
ab全称ApacheBench是Apache超文本传输协议(HTTP)的性能测试工具.是描绘当前所安装的Apache的执行性能, 主要是显示你安装的Apache每秒可以处理多少个请求Apache自带的 ...
- php -- 判断文件是否存在
file_exists is_file is_dir 基本上,PHP的 file_exists = is_dir + is_file 写程序验证一下: 分别执行1000次,记录所需时间. ------ ...
- 【SPOJ】8222. Substrings(后缀自动机)
http://www.spoj.com/problems/NSUBSTR/ 题意:给一个字符串S,令F(x)表示S的所有长度为x的子串中,出现次数的最大值.求F(1)..F(Length(S)) 这题 ...