Zookeeper+ActiveMQ集群实现

基础环境:

系统环境:centos6.7

软件包:zookeeper-3.4.10.tar.gz

主机ip 消息端口 通信端口
192.168.33.17 2181 2888:3888
192.168.33.18 2181 2888:3888
192.168.33.19 2181 2888:3888
主机ip 集群间的通信端口 消息端口 控制台端口
192.168.33.17

62621

61616

8161
192.168.33.18

62621

61616

8161
192.168.33.19

62621

61616

8161
zookeeper集群安装配置(需要在所有集群节点配置):

0.ZooKeeper依赖于Java,请先安装好java,并配置好环境变量。

1.配置ZooKeeper环境变量

# vim /etc/profile
export ZOOKEEPER=/usr/local/zookeeper-3.4.10
export PATH=$ZOOKEEPER/bin:$PATH

2.修改配置文件名

mv zoo_sample.cfg zoo.cfg

3. 修改配置文件

vim zoo.cfg

主要修改两个地方,如下:

(1)data文件目录默认不存在需要手动创建

dataDir=/usr/local/zookeeper-3.4.10/data

(2)配置文件最后增加集群服务器ip及端口信息

server.1=192.168.33.17:2888:3888
server.2=192.168.33.18:2888:3888
server.3=192.168.33.19:2888:3888

4.在Zookeeper主目录下创建data目录

mkdir data
cd data/

在data文件夹下建立myid(三个节点,0,1,2)

#vim myid

0

5.启动zookeeper

cd /usr/local/zookeeper-3.4.10/bin
./zkServer.sh start

6.查看ZooKeeper进程

[root@localhost bin]# jps
2406 QuorumPeerMain
2487 Jps

7.查看节点状态(可以看到该节点角色为master)

# ./zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /usr/local/zookeeper-3.4.10/bin/../conf/zoo.cfg
Mode: leader
ActiveMQ集群配置:

1.vim usr/local/activemq5.15/conf/activemq.xml

(1)修改brokerName,三台机器的brokerName相同,都为"activemq-cluster"

<broker xmlns="http://activemq.apache.org/schema/core" brokerName="activemq-cluster" dataDirectory="${activemq.data}">

(2)修改数据库为replicatedLevelDB

注:hostname 填写本机的ip

<persistenceAdapter>
<!--
            <kahaDB directory="${activemq.data}/kahadb"/>
-->

        <replicatedLevelDB
                directory="${activemq.data}/leveldb"
                replicas="3"
                bind="tcp://0.0.0.0:62621"
                zkAddress="192.168.33.17:2181,192.168.33.18:2181,192.168.33.19:2181"
                hostname="192.168.33.19"
                zkPath="/activemq/leveldb-stores"
/>
        </persistenceAdapter>

2.三台mq机器分别启动mq服务

/usr/local/activemq5.15/bin/activemq start

3.集群测试

访问http://192.168.33.17:8161/

http://192.168.33.18:8161/

http://192.168.33.19:8161/

可以发现只有一台机器能够访问到,则集群配置成功

4.zookeeper client端,查看zookeeper集群信息

zkCli.sh

[zk: localhost:2181(CONNECTED) 4]  ls /activemq/leveldb-stores
[00000000002, 00000000003, 00000000001]

可以看到有三个节点信息

5.通过idea,安装zookeeper插件,也可以查询到ActiveMq集群信息

A1D217FC-0384-1EEB-EFC5-ED482A6F91AC.png

01

{"id":"activemq-cluster","container":null,"address":"tcp://192.168.33.18:62621","position":-1,"weight":1,"elected":"0000000001"}

02

{"id":"activemq-cluster","container":null,"address":null,"position":-1,"weight":1,"elected":null}

03

{"id":"activemq-cluster","container":null,"address":null,"position":-1,"weight":1,"elected":null}

可以看到,192.68.33.18为目前active的机器。

收藏 (0)
评论列表
正在载入评论列表...
我是有底线的
为您推荐
    暂时没有数据