我对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. java中List Set Map使用

    @Test         public void run()        {                              ArrayList<String> list= ...

  2. css透明属性

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  3. JS常用的设计模式(12)—— 迭代器模式

    迭代器模式提供一种方法顺序访问一个聚合对象中各个元素,而又不需要暴露该方法中的内部表示. js中我们经常会封装一个each函数用来实现迭代器. array的迭代器: forEach = functio ...

  4. 从Git仓库中恢复已删除的分支、文件或丢失的commit

    亲测可用 因为自己 commit 并且 push 后 因为冲突 提交不了,不小心做了 rebase 代码被 覆盖 用以下命令 还原: 查看所有日志 并记下 hash 值 git reflog 然后用: ...

  5. 高效率的全组合算法(Java版实现)

    博客上看到的一个算法,用Java实现了一个 算法描述: 算法说明:当n大于2时,n个数的全组合一共有(2^n)-1种. 当对n个元素进行全组合的时候,可以用一个n位的二进制数表示取法. 1表示在该位取 ...

  6. hdu2053

    查找1-n中能整除n的数的个数. 如果是偶数的话,结果为0 奇数的话,结果为1 #include <stdio.h> int main(){ int i,cnt,n; while(~sca ...

  7. Unieap3.5Java端常用公用方法

    String OrgId = McssComMethod.getDimensionID(); Date systemDate =  DataStoreUtil.getOracleSystemDate( ...

  8. 九度OJ 1544 数字序列区间最小值

    题目地址:http://ac.jobdu.com/problem.php?pid=1544 题目描述: 给定一个数字序列,查询任意给定区间内数字的最小值. 输入: 输入包含多组测试用例,每组测试用例的 ...

  9. 比较合并工具vimdiff的主要用法归纳

    参考:https://www.ibm.com/developerworks/cn/linux/l-vimdiff/ vimdiff主要用法归纳如下:   1.打开文件 vimdiff file1 fi ...

  10. html/css 关于脱离文档流的几种情况

    所谓的文档流 顾名思义就是按照顺序流下来,指的是html元素从上往下 从左往右的流式排列, 比如说写了5个Div,正常的文档流是依次显示这5个div块: 脱离文档流就是指它所显示的位置和文档代码就不一 ...