zookeeper与activemq整合
Posted 你很棒
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了zookeeper与activemq整合相关的知识,希望对你有一定的参考价值。
(一)zookeeper与activemq原理
使用ZooKeeper实现的Master-Slave实现方式,是对ActiveMQ进行高可用的一种有效的解决方案,高可用的原理:使用ZooKeeper(集群)注册所有的ActiveMQ Broker。只有其中的一个Broker可以对外提供服务(也就是Master节点),其他的Broker处于待机状态,被视为Slave。如果Master因故障而不能提供服务,则利用ZooKeeper的内部选举机制会从Slave中选举出一个Broker充当Master节点,继续对外提供服务。
(二)环境
centos版本
#cat /etc/redhat-release CentOS release 6.5 (Final)
关闭selinux和iptables防火墙配置
sed -ri ‘/^SELINUX=/cSELINUX=disable‘ /etc/selinux/config setenforce 0 iptables -I INPUT 1 -s 192.168.92.0/24 -j ACCEPT service iptables save
zookeeper环境
主机IP 消息端口 通信端口 节点目录/usr/local/下 192.168.92.134 2181 2888:3888 zookeeper 192.168.92.135 2181 2888:3888 zookeeper 192.168.92.136 2181 2888:3888 zookeeper
activemq环境
主机IP 消息端口 控制台端口 节点目录/usr/local/下 192.168.92.134 61616 8161 activemq 192.168.92.135 61616 8161 activemq 192.168.92.136 61616 8161 activemq
(3)安装zookeeper
1)基本配置
#node1配置:192.168.92.134 [ -d /tools ] || mkdir /tools cd /tools wget http://mirror.bit.edu.cn/apache/zookeeper/zookeeper-3.3.6/zookeeper-3.3.6.tar.gz tar xf zookeeper-3.3.6.tar.gz -C /usr/local/ ln -sv /usr/local/zookeeper-3.3.6/ /usr/local/zookeeper mkdir /usr/local/zookeeper/{data,log} echo 1 >/usr/local/zookeeper/data/myid echo "export PATH=/usr/local/zookeeper/bin:$PATH" >>/etc/profile ; source /etc/profile ############################################################################### #node2配置:192.168.92.135 [ -d /tools ] || mkdir /tools cd /tools wget http://mirror.bit.edu.cn/apache/zookeeper/zookeeper-3.3.6/zookeeper-3.3.6.tar.gz tar xf zookeeper-3.3.6.tar.gz -C /usr/local/ ln -sv /usr/local/zookeeper-3.3.6/ /usr/local/zookeeper mkdir /usr/local/zookeeper/{data,log} echo 2 >/usr/local/zookeeper/data/myid echo "export PATH=/usr/local/zookeeper/bin:$PATH" >>/etc/profile ; source /etc/profile ############################################################################### #node3配置:192.168.92.136 [ -d /tools ] || mkdir /tools cd /tools wget http://mirror.bit.edu.cn/apache/zookeeper/zookeeper-3.3.6/zookeeper-3.3.6.tar.gz tar xf zookeeper-3.3.6.tar.gz -C /usr/local/ ln -sv /usr/local/zookeeper-3.3.6/ /usr/local/zookeeper mkdir /usr/local/zookeeper/{data,log} echo 3 >/usr/local/zookeeper/data/myid echo "export PATH=/usr/local/zookeeper/bin:$PATH" >>/etc/profile ; source /etc/profile
2)修改配置文件:三台节点的配置相同
cd /usr/local/zookeeper/conf cp zoo_sample.cfg zoo.cfg
#vim zoo.cfg clientPort=2181 server.1=192.168.92.134:2888:3888 server.2=192.168.92.135:2888:3888 server.3=192.168.92.136:2888:3888 dataDir=/usr/local/zookeeper/data dataLogDir=/usr/local/zookeeper/log
3)三台节点启动zookeeper
zkServer.sh start ss -anltup | grep 2181
# zkServer.sh status JMX enabled by default Using config: /usr/local/zookeeper-3.3.6/bin/../conf/zoo.cfg Mode: follower zkServer.sh status JMX enabled by default Using config: /usr/local/zookeeper-3.3.6/bin/../conf/zoo.cfg Mode: leader
(4)安装和配置activemq
1)安装activemq
cd /tools wget https://mirrors.tuna.tsinghua.edu.cn/apache//activemq/5.15.3/apache-activemq-5.15.3-bin.tar.gz tar xf apache-activemq-5.15.3-bin.tar.gz -C /usr/local/ ln -sv /usr/local/apache-activemq-5.15.3/ /usr/local/activemq echo "export PATH=$PATH:/usr/local/activemq/bin" >>/etc/profile;source /etc/profile
2)修改配置文件
cp /usr/local/activemq/conf/activemq.xml{,.bak}
修改配置文件内容如下
#vim /usr/local/activemq/conf/activemq.xml 注释一下内容: <!-- <persistenceAdapter> <kahaDB directory="${activemq.data}/kahadb"/> </persistenceAdapter> --> 修改内容如下:三台主机的hostname各种修改成自己的ip地址即可 <persistenceAdapter> <replicatedLevelDB directory="${activemq.data}/leveldb" replicas="3" bind="tcp://0.0.0.0:0" zkAddress="192.168.92.134:2181,192.168.92.135:2181,192.168.92.136:2181" zkPassword="redhat" hostname="192.168.92.134" sync="local_disk" zkPath="/activemq/leveldb-stores" /> </persistenceAdapter> 修改brokerName:三台服务器必须要一样 <broker xmlns="http://activemq.apache.org/schema/core" brokerName="mq" dataDirectory="${activemq.data}">
启动activemq
activemq start
以上是关于zookeeper与activemq整合的主要内容,如果未能解决你的问题,请参考以下文章
框架篇——Spring整合ActiveMQ(MQ服务端与消费端演示)