centos7下Openfire安装+集群+Hazelcast插件+Haproxy

来源:互联网 发布:个人如何开源节流 知乎 编辑:程序博客网 时间:2024/05/18 01:13

首先介绍一下在centos7下如何安装openfire

1、升级一下yum

#yum update

2、删除系统中自带的JAVA插件

#yum -y remove java*

3、配置java环境

下载jdk-7u79-Linux-x64.tar.gz到/tmp/下(路径随意) 
进入/tmp/ 
将jdk-7u79-linux-x64.tar.gz解压到/usr/local/,并改名为jdk

#tar -zxvf jdk-7u79-linux-x64.tar.gz -C /usr/local#mv jdk-7u79-linux-x64 jdk

配置环境变量

#vi /etc/profile

在profile文件末尾加入:

JAVA_HOME=/usr/local/jdkPATH=$JAVA_HOME/bin:$PATHCLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jarexport JAVA_HOMEexport PATHexport CLASSPATH 

保存退出,使/etc/profile里的配置立即生效

#source /etc/profile

4、下载openfire在linux下的安装包

#wget http://download.openpkg.org/components/cache/openfire/openfire_4_0_3.tar.gz

5、解压

将openfire_4_0_3.tar.gz解压到/usr/local/,并改名为openfire

#tar -zxvf openfire_4_0_3.tar.gz -C /usr/local

解压后/usr/local/下直接是openfire无需重命名

6、启动openfire

进入/usr/local/openfire/bin执行如下命令启动openfire

#./openfire.sh

为你需要的n个主机做同样的步骤

其次介绍如何配置openfire

在配置openfire之前需要安装并配置MySQL数据库(mysql作为数据库服务器一般单独安装在另外一台主机上,另外centos7下yum软件包中用mariaDB替代了mysql)

在MySQL中为openfire创建一个数据库(以用户名root登录,密码123456)

mysql -uroot -p

创建的数据库名称叫做”openfire”,然后添加新的用户”test”并且密码设置为”123456”

MariaDB [(none)]> CREATE DATABASE openfire CHARACTER SET='utf8';MariaDB [(none)]> CREATE USER 'test'@'%' IDENTIFIED BY '123456';MariaDB [(none)]> GRANT ALL ON openfire.* TO 'test'@'%';MariaDB [(none)]> FLUSH PRIVILEGES;MariaDB [(none)]> quit

创建好数据库之后开始对n个openfire进行同样的配置

openfire设置

openfire配置登录: http ://openfire服务器地址:9090/ 
首先进行语言配置 选择简体中文 
其次进行服务器设置 
 
这里域统一设置为centos(可以随意设置,但是所有的openfire必须一致,而且在用户登录时,username@host中的host就是这个域) 
再进行数据库设置-标准连接 
 
所有的openfire必须设置为同样的数据库。(这一步非常重要) 
接下来选择初始设置 


最后配置一下服务器的登录密码,默认用户名admin 

注意,因为所有的openfire服务器共享一个数据库,所有所有的openfire服务器的登录用户名和密码都一样,除了第一次需设置登录密码外,后续的openfire设置登录密码这一步可以选择跳过这一步



为所有的openfire服务器进行上述设置

基本配置完成以后就开始进行集群配置

1、关闭openfire集群上的所有服务器 结束掉启动脚本openfire.sh

2、每台服务器都应该做如下操作

进入openfire的安装目录 /usr/local/openfire/plugins,将从openfire官网下载的hazelcasr.jar和broadcast.jar插件复制到 plugins目录

(下载地址:http://www.igniterealtime.org/projects/openfire/plugins.jsp)

3、在集群的其他插件重复2的操作

4、重启集群中的所有openfire服务器

切换到

/usr/local/openfire

执行

chmod +x ./bin/openfire.sh
./bin/openfire.sh

重启之后登录网页管理页面在插件中就可以看到安装好的hazelcasr和broadcast插件


5、插件管理

进入服务器管理中的集群


进入集群管理,在集群设置启用集群


启用之后就可看到集群了


6、集群配置

注意事项

hazelcast最新版3.5.2的配置有重要修改

官方给出的

With the multicast auto-discovery mechanism, Hazelcast allows cluster members to find each other using multicast communication. The cluster members do not need to know the concrete addresses of the other members, they just multicast to all the other members for listening. It depends on your environment if multicast is possible or allowed.

通过组播自动发现机制,hazelcast允许集群成员自动发现而不需要知道准确的地址。 
通过这个机制,无需在对< tcp-ip>进行配置

<join>    <multicast enabled="true">        <multicast-group>224.2.2.3</multicast-group>        <multicast-port>54327</multicast-port>    </multicast>    <tcp-ip enabled="false"/>    <aws enabled="false"/> </join>

如果需要手动配置集群成员的地址则需要关闭< multicast>

集群如下

主机内网ip应用主机1192.168.1.26openfire主机1192.168.1.53openfire


配置如下(openfire/plugins/hazelcast/classes/hazelcast-cache-config.xml)

<join>    <multicast enabled="false">    </multicast>    <tcp-ip enabled="true">        <member>192.168.1.26:5701</member>        <member>192.168.1.53:5701</member>    </tcp-ip>    <aws enabled="false"/> </join>

如果按照之前版本的配置里面< tcp-ip>中的节点是< hostname>则会报错,服务器日志为:

org.jivesoftware.openfire.plugin.util.cache.ClusteredCacheFactory - Unable to start clustering - continuing in local modecom.hazelcast.config.InvalidConfigurationException: cvc-complex-type.2.4.a: Invalid content was found starting with element 'hostname'. One of '{"http://www.hazelcast.com/schema/config":required-member, "http://www.hazelcast.com/schema/config":member, "http://www.hazelcast.com/schema/config":interface, "http://www.hazelcast.com/schema/config":members, "http://www.hazelcast.com/schema/config":member-list}' is expected.

7、负载均衡(Haproxy配置在centos上)

安装 Haproxy(此处为测试安装在53上)

yum install haproxy

配置 Haproxy

vi /etc/haproxy/haproxy.cfg

添加如下内容

listen openfirexmpp :15222    mode tcp    option log-health-checks    option redispatch    option tcplog    balance roundrobin    server p1 192.168.1.53:5222 check    server p2 192.168.1.26:5222 checklisten xmpp-openfirexmpp23 :15223    mode tcp    option log-health-checks    option redispatch    option tcplog    balance roundrobin    server p1 192.168.1.53:5223 check    server p2 192.168.1.26:5223 checklisten openfirehttp :17070    mode tcp    option log-health-checks    option redispatch    option tcplog    balance roundrobin    server p1 192.168.1.53:7070 check    server p2 192.168.1.26:7070 checklisten xmpp-7443 :17443    mode tcp    option log-health-checks    option redispatch    option tcplog    balance roundrobin    server p1 192.168.1.53:7443 check    server p2 192.168.1.26:7443 checklisten openfireadmin :19090    mode tcp    option log-health-checks    option redispatch    option tcplog    balance roundrobin    server p1 192.168.1.53:9090 check    server p2 192.168.1.26:9090 check

重启haproxy

service haproxy restart


注册客户端



成功登陆



原创粉丝点击