2009年3月29日星期日

ejabberd 2.0.4 Installation and Operation Guide Chapter 6 Clustering

ejabberd 2.0.4 Installation and Operation Guide

工作需要,看了一下文檔,順便翻譯了一下,按照自己理解,不一定是直譯的,看這種學習方式可行否?

原文:
http://www.process-one.net/en/ejabberd/guide_en#htoc73
Chapter 6 Clustering
6.1 How it Works 如何工作

A Jabber domain is served by one or more ejabberd nodes. These nodes can be run on different machines that are connected via a network. They all must have the ability to connect to port 4369 of all another nodes, and must have the same magic cookie (see Erlang/OTP documentation, in other words the file ~ejabberd/.erlang.cookie must be the same on all nodes). This is needed because all nodes exchange information about connected users, s2s connections, registered services, etc…
一个jabber domain可以是1到n个ejabber节点。
这些节点可以运行在不同的机器上,当然是通过网络连接的。
他们使用4369端口互联互通,有相同的magic cookie(见 Erlang/OTP 文档,换句话说 ~ejabberd/.erlang.cookie必须是相同的在所有节点)。
所有节点交换信息比如: 连接用户,s2s 连接,注册服务等诸如此类都会用到。

Each ejabberd node has the following modules:
每一个ejabber node 有以下模块:
* router, --路由
* local router, --本地路由
* session manager, --session管理
* s2s manager. --s2s管理

6.1.1 Router 路由器(模块)

This module is the main router of Jabber packets on each node. It routes them based on their destination's domains. It uses a global routing table. The domain of the packet's destination is searched in the routing table, and if it is found, the packet is routed to the appropriate process. If not, it is sent to the s2s manager.
这个模块是运行在每一个节点的Jabber包的主路由器(main router). 路由基于他们目的域(destination domains). 使用一个通用路由表(a globalrouting table). (发送)包的目的可以从这个路由表中查找,如果找到,(发送)包就被路由到恰当的进程(process), 如果没有找到,包会被送到s2s管理器(s2smanager)

6.1.2 Local Router 本地路由器

This module routes packets which have a destination domain equal to one of this server's host names. If the destination JID has a non-empty user part, it is routed to the session manager,
otherwise it is processed depending on its content.
这个模块路由那些包, 他们的目的域(destination domain)是这台服务器的主机名。
如果目的JID(destination JID) 有一个非空用户空间(non-empty user part), 则将被路由到session 管理器那里(session manager),否则,它将按照它的内容来执行。

6.1.3 Session Manager session管理器

This module routes packets to local users. It looks up to which user resource a packet must be sent via a presence table. Then the packet is either routed to the appropriate c2s process, or stored in offline storage, or bounced back.
这个模块路由包到本地用户。 It looks up to which user resource a packet must be sent via a presence table. 然后这个包被恰当的路由到要么是c2s process, 要么存储在离线存储设备中,或者bounced back(受挫后恢复原状)

6.1.4 s2s Manager

This module routes packets to other Jabber servers. First, it checks if an opened s2s connection from the domain of the packet's source to the domain of the packet's destination exists. If that is the case, the s2s manager routes the packet to the process serving this connection, otherwise a new connection is opened.
这个模块路由包到其他的jabber服务器。
首先,他检查是否有一个打开的s2s connection,该连接从包的来源域到包的目的域。如果确实有, 那么s2s管理器就会路由包到服务这个链接的进程, 否则就新建一个链接。

6.2 Clustering Setup 群集的建立

Suppose you already configured ejabberd on one machine named (first), and you need to setup another one to make an ejabberd cluster. Then do following steps:
假设你已经配置了一个ejabberd在一个已经命名的机器上,接着你想建立另一个来构成一个ejabberd cluster. 那么按照下面的步骤:

1. Copy ~ejabberd/.erlang.cookie file from first to second.
1. 将~ejabber/.erlang.cookie文件从第一个服务器复制到第二个

(我这里是源代码安装,configure按照缺省的进行配置所以位置是
[root@localhost ejabberd]# pwd
/var/lib/ejabberd

[root@localhost ejabberd]# cat .erlang.cookie
PJNBBQWMBVEYRVSFLLMV[root@localhost ejabberd]#

(alt) You can also add `-cookie content_of_.erlang.cookie' option to all `erl' commands below.
(变通方法) 你也可以在erl 命令选项后加上 `-cookie content_of_.erlang.cookie'
2. On second run the following command as the ejabberd daemon user, in the working directory of ejabberd:
在第二个服务器上运行下列命令(ejabberd守护进程用户),在ejabberd的工作目录
erl -sname ejabberd \
-mnesia dir "/var/lib/ejabberd/" \
-mnesia extra_db_nodes "['ejabberd@first']" \
-s mnesia

This will start Mnesia serving the same database as ejabberd@first. You can check this by running the command `mnesia:info().'. You should see a lot of remote tables and a line like the following:
这将开始一个数据库(ejabberd@first)的 Mnesia服务. 你可以通过运行命令`mnesia:info().'来检查他的运行情况。
你会看到n多个远程表和类似以下行说明:
Note: the Mnesia directory may be different in your system. To know where does ejabberd expect Mnesia to be installed by default, call 4.1 without options and it will show some help, including the Mnesia database spool dir.

running db nodes = [ejabberd@first, ejabberd@second]

3. Now run the following in the same `erl' session:
现在运行一下命令在相同的 'erl' session

mnesia:change_table_copy_type(schema, node(), disc_copies).

This will create local disc storage for the database.
这将为这个数据库建立一个本地的存储。


(alt) Change storage type of the scheme table to `RAM and disc copy' on the second node via the Web Admin.
(变更办法) 可以通过Web Admin改变第二个节点的存储类型 为 `RAM and disc copy'

4. Now you can add replicas of various tables to this node with `mnesia:add_table_copy' or `mnesia:change_table_copy_type' as above (just replace `schema' with another table name and `disc_copies' can be replaced with `ram_copies' or `disc_only_copies').
现在你可以加入复制各种各样的表到这个节点,使用`mnesia:add_table_copy' 或 `mnesia:change_table_copy_type'(只要用其他的表名字替换上面'schema'和将'disc_copies'替换为'ram_copies'或'disc_only_copies'.

Which tables to replicate is very dependant on your needs, you can get some hints from the command `mnesia:info().', by looking at the size of tables and the default storage type for each table on 'first'.
复制那些表非常依赖于你的需要,你可以从命令 mnsia:info().中得到相应的信息,表大小,每个表的缺省存储类型


Replicating a table makes lookups in this table faster on this node. Writing, on the other hand, will be slower. And of course if machine with one of the replicas is down, other replicas will be used.
复制一个表,可以使查询这个表较快在这个节点,(读特性), 写,将会较慢, 当然如果某个节点正在复制工作,其他的节点会提供相应的服务。
--大意是说如果复制表到本地节点,读要快一些,相应的写就会慢一些,对于多个节点来说,一个节点正在复制,其他节点在服务中high availability.


Also section 5.3 (Table Fragmentation) of Mnesia User's Guide can be helpful.
当然可以参考Mnesia 用户指南 5.3 (表分片)
(alt) Same as in previous item, but for other tables.

5. Run `init:stop().' or just `q().' to exit from the Erlang shell. This probably can take some time if Mnesia has not yet transfered and processed all data it needed from first.
运行 init:stop() 或 q() 离开erlang shell, 这可能会花费一些时间如果Mnesia没有转换或处理数据从第一个database.

6. Now run ejabberd on second with a configuration similar as on first: you probably do not need to duplicate `acl' and `access' options because they will be taken from first; and mod_irc should be enabled only on one machine in the cluster.
现在运行ejabbered 在第二个节点类似第一个节点: 你可能不需要复制acl和access选项, mod_irc可能只运行在一个集群的其中一部机器上
You can repeat these steps for other machines supposed to serve this domain.


6.3 Service Load-Balancing 负载均衡

6.3.1 Components Load-Balancing 组件均衡

6.3.2 Domain Load-Balancing Algorithm 域均衡算法

ejabberd includes an algorithm to load balance the components that are plugged on an ejabberd cluster. It means that you can plug one or several instances of the same component on each ejabberd cluster and that the traffic will be automatically distributed.
ejabber cluster 包含了一个负载均衡的算法,也就是说,你可以插入一个或n个具有相同组件实例(instance)在每一个ejabbered cluster, 并且自动控制流量分布

The default distribution algorithm try to deliver to a local instance of a component. If several local instances are available, one instance is chosen randomly. If no instance is available locally, one instance is chosen randomly among the remote component instances.
缺省的分布算法尽量交由含有组件的本地实例来处理。 如果存在多个本地实例,将随机挑一个实例。 如果本地没有有效的实例, 将从远程的实例中挑选一个来处理。

If you need a different behaviour, you can change the load balancing behaviour with the option domain_balancing. The syntax of the option is the following:
如果你需要特别的行为,你可以使用domain_balancing选项改变load balancing行为,语法要求如下:

{domain_balancing, "component.example.com", }.

Several balancing criteria are available: 几种均衡标准

* destination: the full JID of the packet to attribute is used. 目的 packet 去的地儿
* source: the full JID of the packet from attribute is used. 源 packet 来的地儿
* bare_destination: the bare JID (without resource) of the packet to attribute is used. 裸的JID, packet要去的
* bare_source: the bare JID (without resource) of the packet from attribute is used. 裸的JID, packet 要来的

If the value corresponding to the criteria is the same, the same component instance in the cluster will be used.
如果这些值的criteria相同,在cluster中有相同组件的instance可用,(用谁都行)
6.3.3 Load-Balancing Buckets

When there is a risk of failure for a given component, domain balancing can cause service trouble. If one component is failing the service will not work correctly unless the sessions are rebalanced.

这里有一个给定组件的风险的问题,如果域均衡会导致服务混乱。

In this case, it is best to limit the problem to the sessions handled by the failing component. This is what the domain_balancing_component_number option does, making the load balancing algorithm not dynamic, but sticky on a fix number of component instances.
在这种情况下,最好是把问题限制在操控failing component的session上, 这也是domain_balancing_component_number参数的作用,就是将load balancing 算法不是动态的设定,而是和几个固定的组件实例绑定在一起。
The syntax is the following:
语法形式:
{domain_balancing_component_number, "component.example.com", N}

没有评论:

发表评论