我对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. MySQL数据库获取汉字拼音的首字母函数

    需求简介:最近的一个项目,想实现如下图所示的显示效果.很明显,如果能够获取对应的汉字词组的拼音首字母就可以实现了,如果是固定的几个汉字,人为的拼一下就可以了,不过项目中有多处功能是需要这个效果的,并且 ...

  2. 学习总结 DML数据库增删改语句

    insert into score t values('111','3-105',88)--插入一行数据 insert into score(sno,cno) values('111','3-105' ...

  3. No.006 ZigZag Conversion

    6. ZigZag Conversion Total Accepted: 98584 Total Submissions: 398018 Difficulty: Easy The string &qu ...

  4. Windows Server 2012下安装Hyper-V虚拟机

    Windows Server 2012下安装Hyper-V虚拟机 Win server 2012系统中Hyper-V 性能进一步提高,广大爱好者都尝试体验它,可是有不少朋友无法正确安装虚拟机,尽管在网 ...

  5. JS常用的设计模式(8)——访问者模式

    GOF官方定义: 访问者模式是表示一个作用于某个对象结构中的各元素的操作.它使可以在不改变各元素的类的前提下定义作用于这些元素的新操作.我们在使用一些操作对不同的 对象进行处理时,往往会根据不同的对象 ...

  6. solr5.5教程-schema.xml部分配置

    本文章全部内容均翻译自solr自带的配置文件. 1.Field结点说明 name: 必须的,field的名字 type:        必须的,fieldType部分所定义的type的名字 index ...

  7. leetcode 7

    此题实现比较简单,但是边界处理比较麻烦.题目要求是以32位考虑,所以可表达的数的范围是-2147483648~2147483648. 我们需要判断当前的数翻转之后是否在这个范围中,我的思路是首先对当前 ...

  8. 理解CSS中BFC

    BFC(Block Formatting Context) 是Web页面中盒模型布局的CSS渲染模式.它的定位体系 属于 常规文档流 .摘自 W3C : 浮动,绝对定位元素, inline-block ...

  9. sed的惯常用法

    1:注释掉某一行这个经常会遇到的,把配置文件里某一行注释掉.让他不起作用.sed -i -e ’121 s/^/#/’ /usr/local/apache2/conf/httpd.conf上面一行命令 ...

  10. Solaris的vi

    进入输入模式i: 在光标之前插入a: 在光标之后插入o: 在下面新建一行输入I: 光标移动到本行首插入A: 光标移动到本行末尾插入O: 在上面新建一行输入 移动光标M:移到屏幕中间一行的行首L:移到屏 ...