我对rabbitmq学习还不深入,这些翻译仅仅做资料保存,希望不要误导大家。

With exchanges, bindings, and queues under your belt, you might think you have all

the coolness that is Rabbit figured out. But if you’ve played around much with Rabbit,

you know there’s one nagging concept we haven’t talked about yet: the vhost. Within

every RabbitMQ server is the ability to create virtual message brokers called virtual

hosts (vhosts).

vhost:每个rabbitmq服务器内部创建的虚拟的消息broker被称为vhost。

Each one is essentially a mini-RabbitMQ server with its own queues,

exchanges, and bindings … and, more important, its own permissions. This lets you

safely use one RabbitMQ server for multiple applications without worrying that your

Sudoku app might delete queues used by your lost Fido tracker. Vhosts are to Rabbit

what virtual machines are to physical servers: they allow you to run data for multiple

applications safely and securely by providing logical separation between instances.

This is useful for anything from separating multiple customers on the same Rabbit to

avoiding naming collisions on queues and exchanges.

vhost对于rabbit相当于虚拟机对于物理机:

通过逻辑上的分隔,允许你的程序安全的运行数据。

隔离在同一个rabbit上的多consumer来避免queue和exchange的重名,这很有用。

Where otherwise you might

have to run multiple Rabbits and gain all the management headaches that come with

that, you can instead run one Rabbit and build up or tear down vhosts on demand.

Vhosts are so fundamental to the concept of AMQP that you have to specify one

when you connect. RabbitMQ makes it easy to get started by including a default vhost

called / right out of the box. If you don’t need multiple vhosts, just use the default one.

It’s accessible using the default guest username with password guest, though you should

change the password for security (more on this in chapter 3).

否则你必须允许多个rabbit。

你可以只启动一个rabbit,在需要的时候创建或者销毁vhost。

Vhosts are so fundamental to the concept of AMQP that you have to specify one

when you connect.

rabbitmq包含一个名为"/"的默认vhost。

如果你不需要多个vhost,就使用这个默认的。

默认的账号密码为guset:guest,为了安全,最好修改。

An interesting property

of AMQP is that it doesn’t specify whether permissions are per vhost or server-wide.

This is left up to the broker developer and in RabbitMQ’s case permissions are per vhost.

When you create a user in Rabbit, it’s usually assigned to at least one vhost and will

only be able to access queues, exchanges, and bindings on those assigned vhosts. Also,

when you’re designing your messaging architecture, keep in mind that separation

between vhosts is absolute. You can’t bind an exchange on vhost banana_tree to a

queue on vhost oak_tree. This is actually a good thing, not only for security, but also

for portability. Imagine for a second that you’ve designed the check cashing tier of

your magnificent banking app to use its own vhost. You might initially put this vhost

on the same Rabbit that houses the vhosts for other tiers of your app.

AMQP有一个有趣的特性,权限范围并没有指定是vhost还是整个服务器。

这取决于broker开发者,在rabbitmq中权限范围是vhost。

当你在rabbitmq中创建了一个用户,通常被分配到最晚创建的vhost中,并且只能

访问整个vhost上的queue,exchange,binding。

同样,当你在设置你的消息体系时,记得vhost之间是绝对隔离的。

你不能绑定一个vhost上的exchange到另外一个vhost的queue上。

这是好事,并不只是为了安全,同样是为了可移植性。

But one day

your customers start cashing millions of checks—good for you but bad for the Rabbit

server. Check cashing needs to be on a Rabbit server with less load. If the check cashing

tier had used the default vhost, you would have to worry about naming collisions

(queues and exchanges) when you point it to the new Rabbit server. But since it has its

own vhost, you can safely move everything to any other Rabbit server and instantly

start handling the new load without any name collisions. Hence, we highly recommend

identifying the common functionality groups in your infrastructure (such as

web logging) and giving each one its own vhost. Also, keep in mind that when you create

a vhost on a RabbitMQ cluster, it’s created across the entire cluster. Just as vhosts

eliminate needing to run a RabbitMQ server for every tier in your infrastructure, they

also avoid making you create different clusters for each tier.

记住当你在一个rabbitmq cluster上创建一个vhost,整个vhost会横跨所有的cluster。

to do:

We’ve talked about all of the great benefits of vhosts, but how do you create them?

Vhosts and permissions are unique in that they’re the only primitives in AMQP (unlike

queues, exchanges, and bindings) that can’t be created using the AMQP protocol. For

RabbitMQ they’re created using the rabbitmqctl utility found in the ./sbin/ directory

of your RabbitMQ installation. To create a vhost simply run rabbitmqctl

add_vhost [vhost_name], where [vhost_name] is the vhost you want to create. Deleting

a vhost is similarly simple: rabbitmqctl delete_vhost [vhost_name]. Once a vhost

has been created, you can connect to it and start adding your queues and exchanges.

If you need to find out what vhosts are running on a particular Rabbit server, run

rabbitmqctl list_vhosts and voila! There they are:

$ ./sbin/rabbitmqctl list_vhosts

Listing vhosts ...

/

oak

sycamore

...done.

我们已经说完了所有vhost的优点,但是如何创建他?

vhost和权限都是唯一存在的,他们是AMQP中无法通过AMQP协议创建的元件。

在rabbitmq中使用rabbitmqctl创建,rabbitmqctl在rabbitmq的安装目录的sbin中。

创建一个vhost只需要执行 rabbitmqctl add_vhost [vhost_name]。

如果一个vhost已经被创建了,你可以连接上去,添加queue和exchange。

如果你需要查看rabbitmq服务器上有哪些vhost,执行rabbitmqctl list_vhosts。

NOTE

Typically you’ll run rabbitmqctl directly on the server with the

RabbitMQ node you want to manage. But you can also pass the -n

rabbit@[server_name] option before any command to manage a remote

RabbitMQ node. The node identifier (rabbit@[server_name]) is split into

two parts at the @: the left half is the Erlang application name and will almost

always be rabbit, and the right half is the server hostname or IP address. You

need to make sure the server running the Rabbit node and the workstation

you’re running rabbitmqctl on have the same Erlang cookie installed. For

more info on Erlang cookies, check out section 3.4.1.

Now that you’ve secured your queues and exchanges with vhosts, it’s time to talk

about making sure critical messages don’t disappear when Rabbit crashes or reboots.

须知

你可以在rabbitmq节点上直接运行rabbitmqctl来管理,也可以通过传入-n rabbit@[server_name]

参数来管理一个远程的rabbitmq节点。节点标识(rabbit@[server_name])分为2部分,

由"@"分隔:左边是erlang程序名,一定是填写rabbit;右边是服务器名或者IP地址。

[译]rabbitmq 2.4 Multiple tenants: virtual hosts and separation的更多相关文章

  1. Configure Apache Virtual Hosts - CentOS 7

    Difficulty: 2Time: 15 minutes Want to host websites on your server? Using Apache? Great. This articl ...

  2. How To Set Up Apache Virtual Hosts on CentOS 6

    About Virtual Hosts 虚拟主机,用于在一个单一IP地址上,运行多个域.这对那些想在一个VPS上,运行多个网站的人,尤其有用.基于用户访问的不同网站,给访问者显示不同的信息.没有限制能 ...

  3. Memory Layout for Multiple and Virtual Inheritance

    Memory Layout for Multiple and Virtual Inheritance(By Edsko de Vries, January 2006)Warning. This art ...

  4. [转]Windows 下 Apache Virtual hosts 简单配置

    From : http://blog.csdn.net/wuerping/article/details/4164362 /* Author : Andrew.Wu [ Created on : 20 ...

  5. [译]RabbitMQ教程C#版 - “Hello World”

    [译]RabbitMQ教程C#版 - “Hello World”   先决条件本教程假定RabbitMQ已经安装,并运行在localhost标准端口(5672).如果你使用不同的主机.端口或证书,则需 ...

  6. #Virtual hosts #Include conf/extra/httpd-vhosts.conf 开启就不能启动apache

    #Virtual hosts#Include conf/extra/httpd-vhosts.conf我只要把其中任何一个开启就是吧#去掉就启动不了apache.怎么回事error.log是这样的ht ...

  7. [译]rabbitmq 2.1 Consumers and producers (not an economics lesson)

    我对rabbitmq学习还不深入,这些翻译仅仅做资料保存,希望不要误导大家. For now, all you need to know is that producers create messag ...

  8. [译]rabbitmq 2.5 Where’s my message? Durability and you

    我对rabbitmq学习还不深入,这些翻译仅仅做资料保存,希望不要误导大家. There’s a dirty secret about creating queues and exchanges in ...

  9. [译]rabbitmq 2.2 Building from the bottom: queues

    我对rabbitmq学习还不深入,这些翻译仅仅做资料保存,希望不要误导大家. You have consumers and producers under your belt, and now you ...

随机推荐

  1. VS/Visual studio 源代码编辑器里的空处出现点号解决办法

    此原因是不小心按错了键盘上的组合键Ctr+E+S, 再次按Ctr+E+S可消除.

  2. cacti快速安装

    一.cacti概述 1. cacti是用php语言实现的一个软件,它的主要功能是用snmp服务获取数据,然后用rrdtool储存和更新数据,当用户需要查看数据的时候用rrdtool生成图表呈现给用户. ...

  3. javascript 实现HashTable(哈希表)

    一.javascript哈希表简介 javascript里面是没有哈希表的,一直在java,C#中有时候用到了这一种数据结构,javascript里面若没有,感觉非常不顺手.细细看来,其实javasc ...

  4. b2c项目基础架构分析(二)前端框架 以及补漏的第一篇名词解释

    继续上篇,上篇里忘记了也很重要的前端部分,今天的网站基本上是以一个启示页,然后少量的整页切换,大量的浏览器后台调用web服务局部.动态更新页面显示状态这种方式在运作的,从若干年前简单的ajax流行起来 ...

  5. Sql server 数据库 int 和guid 两者的比较

    我们公司的数据库全部是使用GUID做主键的,很多人习惯使用int做主键.所以呢,这里总结一下,将两种数据类型做主键进行一个比较. 使用INT做主键的优点: 1.需要很小的数据存储空间,仅仅需要4 by ...

  6. Android IOS WebRTC 音视频开发总结(四一)-- QQ和webrtc打洞能力pk

    很多人知道webrtc打洞能力很强,到底有多强但是不知道,比较好的方法就是跟QQ对比,但大多数公司很难模拟各种网络环境进行测试,比如联通,铁通,电信,移动,所以这次请小师妹在实验室下进行了一个比较全面 ...

  7. 3D模型文件读写.Net SDK

    AnyCAD .Net/C++ SDK支持多种3D/2D文件格式,比如BREP.STEP.IGES.STL.DXF.3DS.OBJ.FBX.SKP.IFC.DAE……等,根据使用场景提供不同的API. ...

  8. IOS CLLocationManager定位反编码位置信息

    //获取位置和坐标#if __IPHONE_OS_VERSION_MAX_ALLOWED > __IPHONE_7_1        if (IOS_VERSION >= 8.0) {   ...

  9. Face++云相册应用IOS源码

    该源码是一个不错的相册应用,Face++云相册应用源码,以人脸识别作为用户注册和登录的依据,登录后可以进入用户的云相册空间,并对相册进行上传图片或删除图片,另添加了分享功能. <ignore_j ...

  10. 自制docker basic image

    docker的安装和入门见官网教程:http://docs.docker.com/ 下面是自制docker basic image的步骤,以ubuntu为例. 1. 安装debootstrap apt ...