Tigase8集群配置是很簡單的,本文從實驗的角度來了解tigase集群配置及啟動。
首先你先能保證在機器上能跑單機版本的代碼,如果還沒有,先移步看前面的博客吧<IDEA 上 Tigase8.0 源代碼編譯運行>
1、准備工作:內網中至少兩台主機:
我就以我本地實驗來做參考:
主機A:[192.168.3.2] 主機名[llooper]
主機B:[192.168.3.5] 主機名[shirley-pc]
2、修改 C:\Windows\System32\drivers\etc\hosts 文件,配置名字映射使得A.B主機之間互通
192.168.3.5 Shirley-PC 192.168.3.2 llooper
3、修改Tigase的配置文件
A主機:
'admin = [ 'admin@llooper' ] 'cluster-mode' = true 'cluster-nodes' = [ 'llooper' , 'Shirley-PC' ] 'config-type' = 'default' 'default-virtual-host' = 'llooper' 'debug' = [ 'server', 'cluster','eventbus' ] 'cl-comp' { 'connect-all' = true } dataSource { 'pool-size' = 1 default () { uri = 'jdbc:mysql://A數據源' } }
B主機:
'admin = [ 'admin@Shirley-PC' ] 'cluster-mode' = true 'cluster-nodes' = [ 'llooper' , 'Shirley-PC' ] 'config-type' = 'default' 'default-virtual-host' = 'Shirley-PC' 'debug' = [ 'server', 'cluster','eventbus' ] 'cl-comp' { 'connect-all' = true } dataSource { 'pool-size' = 1 default () { uri = 'jdbc:mysql://B數據源' } }
集群相關的配置也就以下三個屬性需要注意下:
'cluster-mode' = true //開啟集群模式 'cluster-nodes' = [ 'llooper' , 'Shirley-PC' ] //集群全部的主機域名 'cl-comp' { 'connect-all' = true //動態地將不在集群配置中的節點加入到集群中,默認為false }
4、注意:目前集群user模塊數據庫必需使用不同的數據源,如果同用一個數據庫,不同域下的注冊用戶都在同一個user模塊表中。通過vhost-manager在users表中,查詢出UID,再通過vhosts-lists作為key在tig_pairs表中查詢庫加載<vhost>,如果都同用一個數據源,那么vhost包含所有域。當eventbus組件發出給另一個域的數據包在MessageRouter中查詢vhost發現本地包含該域,所以導致數據包又投回來本機處理,從而出現數據包死循環的問題。
<vhost anon="true" tls-required="false" enabled="true" s2s-secret="15b43189-2b23-46ae-9dc6-ab0acdceafe5" hostname="llooper" max-users="0" register="true" domain-filter="ALL"><comps></comps><other></other></vhost>
<vhost anon="true" tls-required="false" enabled="true" s2s-secret="1434ac98-8ba1-41e2-a57e-6559fb94d921" hostname="shirley-pc" max-users="0" register="true" domain-filter="ALL"><comps></comps><other></other></vhost>
5、分別啟動 XMPPServer ,成功運行服務!
6、使用PSI 進行測試:連接不同的域進行注冊用戶,然后進行互加好友,互發消息:
A域和B域的賬號互通消息,證明集群消息能相互轉發成功!
7、最后,為了方便用戶在調試Tigase代碼,附上一件我修改過的配置。配置上,組件的線程數量被我修改為1. 為了串行執行,便於從日志中分析流程。
'admins' = [ 'admin@llooper' ] 'cluster-mode' = true 'cluster-nodes' = [ 'llooper' , 'Shirley-PC' ] 'config-type' = 'default' 'default-virtual-host' = 'llooper' 'debug' = [ 'server', 'cluster','eventbus' ] 'cl-comp' { 'connect-all' = true } logging (class: tigase.conf.LoggingBean) { debug = [ 'server', 'cluster', 'eventbus' ] rootHandlers = [ 'java.util.logging.ConsoleHandler', 'java.util.logging.FileHandler' ] rootLevel = CONFIG 'shutdown-thread-dump' = true handlers { 'java.util.logging.ConsoleHandler' { formatter = 'tigase.util.log.LogFormatter' level = ALL } 'java.util.logging.FileHandler' { append = true count = 1 formatter = 'tigase.util.log.LogFormatter' level = ALL limit = 10000000 pattern = 'logs/tigase.log' } } } dataSource { 'pool-size' = 1 default () { uri = 'jdbc:mysql://數據源地址' } } userRepository { default () {} } authRepository { default () {} } 'cl-comp' { 'connect-all' = true } amp () { 'processing-in-threads' = 1 'processing-out-threads' = 1 } bosh () { 'processing-in-threads' = 1 'processing-out-threads' = 1 seeOtherHost {} } c2s () { 'processing-in-threads' = 1 'processing-out-threads' = 1 seeOtherHost {} } http (class: tigase.http.HttpMessageReceiver) {} 'message-router' () { 'processing-in-threads' = 1 'processing-out-threads' = 1 } s2s () { 'processing-in-threads' = 1 'processing-out-threads' = 1 } 'sess-man' () { 'processing-in-threads' = 1 'processing-out-threads' = 1 amp (class: tigase.xmpp.impl.MessageAmp) { threadsNo = 1 message (class: tigase.xmpp.impl.Message) { threadsNo = 1 } msgoffline (class: tigase.xmpp.impl.OfflineMessages) { threadsNo = 1 } } 'default-handler' () { threadsNo = 1 } disco () { threadsNo = 1 } 'domain-filter' (class: tigase.xmpp.impl.DomainFilter) { threadsNo = 1 } 'http://jabber.org/protocol/commands' (class: tigase.xmpp.impl.JabberIqCommand) { threadsNo = 1 } 'http://jabber.org/protocol/jingle' (class: tigase.xmpp.impl.Jingle, active: false) { threadsNo = 1 } 'http://jabber.org/protocol/offline' (class: tigase.xmpp.impl.FlexibleOfflineMessageRetrieval, active: false) { threadsNo = 1 } 'http://jabber.org/protocol/stats' (class: tigase.xmpp.impl.JabberIqStats) { threadsNo = 1 } 'invisible-command' (class: tigase.xmpp.impl.InvisibleCommand, active: false) { threadsNo = 1 } 'jabber:iq:auth' (class: tigase.xmpp.impl.JabberIqAuth) { threadsNo = 1 } 'jabber:iq:iq' (class: tigase.xmpp.impl.JabberIqIq, active: false) { threadsNo = 1 } 'jabber:iq:last-marker' (class: tigase.xmpp.impl.LastActivityMarker, active: false) { threadsNo = 1 } 'jabber:iq:privacy' (class: tigase.xmpp.impl.JabberIqPrivacy) { threadsNo = 1 } 'jabber:iq:private' (class: tigase.xmpp.impl.JabberIqPrivate) { threadsNo = 1 } 'jabber:iq:register' (class: tigase.xmpp.impl.JabberIqRegister) { threadsNo = 1 } 'jabber:iq:roster' (class: tigase.xmpp.impl.JabberIqRoster) { threadsNo = 1 } 'jabber:iq:version' (class: tigase.xmpp.impl.JabberIqVersion) { threadsNo = 1 } message (class: tigase.xmpp.impl.Message, active: false) { threadsNo = 1 } 'message-all' (class: tigase.xmpp.impl.MessageAll, active: false) { threadsNo = 1 } 'message-carbons' (class: tigase.xmpp.impl.MessageCarbons) { threadsNo = 1 } 'message-vhost-forward' (class: tigase.xmpp.impl.MessageForwarding, active: false) { threadsNo = 1 } mobile_v1 (class: tigase.xmpp.impl.MobileV1, active: false) { threadsNo = 1 } mobile_v2 (class: tigase.xmpp.impl.MobileV2, active: false) { threadsNo = 1 } mobile_v3 (class: tigase.xmpp.impl.MobileV3, active: false) { threadsNo = 1 } motd (class: tigase.xmpp.impl.MotdProcessor, active: false) { threadsNo = 1 } msgoffline (class: tigase.xmpp.impl.OfflineMessages, active: false) { threadsNo = 1 } 'pep-simple' (class: tigase.xmpp.impl.PepPlugin, active: false) { threadsNo = 1 } 'presence-offline' (class: tigase.xmpp.impl.PresenceOffline, active: false) { threadsNo = 1 } 'presence-state' (class: tigase.xmpp.impl.PresenceState) { threadsNo = 1 } 'presence-subscription' (class: tigase.xmpp.impl.PresenceSubscription) { threadsNo = 1 } 'remote-roster-management' (class: tigase.xmpp.impl.RemoteRosterManagement, active: false) { threadsNo = 1 } scriptCommandProcessor (class: tigase.component.ComponenScriptCommandProcessor) {} 'session-close' (class: tigase.server.xmppsession.SessionManager$SessionCloseProc) { threadsNo = 1 } 'session-open' (class: tigase.server.xmppsession.SessionManager$SessionOpenProc) { threadsNo = 1 } starttls (class: tigase.xmpp.impl.StartTLS) { threadsNo = 1 } 'urn:ietf:params:xml:ns:xmpp-bind' (class: tigase.xmpp.impl.BindResource) { threadsNo = 1 } 'urn:ietf:params:xml:ns:xmpp-sasl' (class: tigase.xmpp.impl.SaslAuth) { threadsNo = 1 } 'urn:ietf:params:xml:ns:xmpp-session' (class: tigase.xmpp.impl.SessionBind) { threadsNo = 1 } 'urn:xmpp:blocking' (class: tigase.xmpp.impl.BlockingCommand) { threadsNo = 1 } 'urn:xmpp:csi:0' (class: tigase.xmpp.impl.ClientStateIndication) { threadsNo = 1 logic (class: tigase.xmpp.impl.MobileV2) { threadsNo = 1 } } 'urn:xmpp:extdisco:2' (class: tigase.server.extdisco.ExternalServiceDiscoveryProcessor, active: false) { threadsNo = 1 } 'urn:xmpp:ping' (class: tigase.xmpp.impl.UrnXmppPing) { threadsNo = 1 } 'urn:xmpp:time' (class: tigase.xmpp.impl.EntityTime) { queueSize = null threadsNo = 1 } 'vcard-temp' (class: tigase.xmpp.impl.VCardTemp) { threadsNo = 1 } 'vcard-xep-0292' (class: tigase.xmpp.impl.VCard4) { threadsNo = 1 } writer (class: tigase.server.xmppsession.SessionManager$SMPacketWriter) {} zlib (class: tigase.xmpp.impl.StartZLib) { threadsNo = 1 } } ws2s () { 'processing-in-threads' = 1 'processing-out-threads' = 1 seeOtherHost {} }