系統環境:centos6.7java
軟件包: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 | 62621apache |
61616vim |
8161 |
192.168.33.18 | 62621centos |
61616bash |
8161 |
192.168.33.19 | 62621服務器 |
61616tcp |
8161 |
0.ZooKeeper依賴於Java,請先安裝好java,並配置好環境變量。ide
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
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集羣信息
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的機器。