首页 技术 正文
技术 2022年11月10日
0 收藏 723 点赞 4,054 浏览 3646 个字

概述


基于ZooKeeper + ActiveMQ + replicatedLevelDB,在Windows平台的主从部署方案。主从部署可以提供数据备份、容错[1]的功能,但是不能提供负载均衡的功能。 注:

  1. 容错:主服务器宕掉,再选出一台作为作为主服务器,来提供服务。

部署图


AMQ学习笔记 – 14. 实践方案:基于ZooKeeper + ActiveMQ + replicatedLevelDB的主从部署 

简单说明

ActiveMQ提供了队列、本地持久化的功能,ZooKeeper提供了主从选举的功能。Producers将消息发送给主从队列体系[1],Consumers从主从队列体系中获取消息。注:[1] 主从队列体系 – 除Producers、Consumers之外的,由ZooKeeper + ActiveMQ + replicatedLevelDB组成的体系。

模拟环境


1.软件环境

  1. 操作系统 –  Windows7
  2. JDK – 1.7
  3. activemq – 5.13.2
    下载包:apache-activemq-5.13.2-bin.zip
  4. zookeeper – 3.4.8
    下载包:zookeeper-3.4.8.tar.gz

2.网络环境

  1. 机器1
    ip:192.168.74.55
    zookeeper port:2181
    activemq port:61616
  2. 机器2
    ip:192.168.74.26
    zookeeper port:2181
    activemq port:61616
  3. 机器3
    ip:192.168.74.25
    zookeeper port:2181
    activemq port:61616

实施


1.安装、配置、启动ZooKeeper

  1. 将zookeeper-3.4.8.tar.gz解压缩到合适的路径。
  2. 复制conf/zoo_sample.cfg为conf/zoo.cfg
  3. 在conf/zoo.cfg中指定dataDir、dataLogDir、各服务器及端口信息
     # The number of milliseconds of each tick
    tickTime=2000
    # The number of ticks that the initial
    # synchronization phase can take
    initLimit=10
    # The number of ticks that can pass between
    # sending a request and getting an acknowledgement
    syncLimit=5
    # the directory where the snapshot is stored.
    # do not use /tmp for storage, /tmp here is just
    # example sakes.
    # dataDir=/tmp/zookeeper
    dataDir=F:/temp/zookeeper-3.4.8/data
    dataLogDir=F:/temp/zookeeper-3.4.8/log
    server.1=192.168.74.55:2888:3888
    server.2=192.168.74.26:2888:3888
    server.3=192.168.74.25:2888:3888
    # the port at which the clients will connect
    clientPort=2181
    # the maximum number of client connections.
    # increase this if you need to handle more clients
    #maxClientCnxns=60
    #
    # Be sure to read the maintenance section of the
    # administrator guide before turning on autopurge.
    #
    # http://zookeeper.apache.org/doc/current/zookeeperAdmin.html#sc_maintenance
    #
    # The number of snapshots to retain in dataDir
    #autopurge.snapRetainCount=3
    # Purge task interval in hours
    # Set to "0" to disable auto purge feature
    #autopurge.purgeInterval=1

    修改内容:
    1) 注释掉第12行2) 第13行,添加dataDir3) 第14行,添加dataLogDir4) 第15-17行,以server.A=B:C:D的形式指定三台服务器
       A – 数字,表示服务器的编号
       B – 服务器的ip
       C – 服务器与集群中的Leader服务器交换信息的端口
       D – 用来执行选举时服务器相互通信的端口(万一集群中的 Leader 服务器挂了,需要一个端口来重新进行选举,选出一个新的 Leader)

  4. 新建myid文件
    在dataDir指定的路径下,新建myid文件,文件内容是当前服务器的编号(和conf/zoo.cfg中的server编号对应)。
    e.g. 192.168.74.55机器的内容为:1
  5. 启动
    先切换到zookeeper目录,再启动(可以尝试设置PATH)
     D:\tools\PowerCmd>E:
    E:\>cd E:\418备份区\工作任务\20160318_消息队列\zookeeper-3.4.8
    E:\418备份区\工作任务\20160318_消息队列\zookeeper-3.4.8>bin\zkServer.cmd

2.安装、配置、启动ActiveMQ

  1. 将apache-activemq-5.13.2-bin.zip加压缩到合适的目录。
  2. 修改conf/activemq.xml文件内容
    将默认的<persistenceAdapter>配置的内容注释掉,添加基于replicatedLevelDB的持久化配置:
     <!--
    <persistenceAdapter>
    <kahaDB directory="${activemq.data}/kahadb"/>
    </persistenceAdapter>
    -->
    <persistenceAdapter>
    <replicatedLevelDB
    directory="${activemq.data}/leveldb"
    replicas="3"
    bind="tcp://0.0.0.0:0"
    zkAddress="192.168.74.55:2181,192.168.74.26:2181,192.168.74.25:2181"
    hostname="192.168.74.55"
    sync="local_disk"
    zkPath="/activemq/leveldb-stores"
    />
    </persistenceAdapter>

    注意:1) zkAddress依次指定三台服务器的ip和ZooKeeper的监听端口2) hostname为每一台服务器的ip地址,三台服务器根据实际情况修改

  3. 启动ActiveMQ
    先切换到安装目录,再启动(可以尝试设置PATH)
     cd E:\418备份区\工作任务\20160318_消息队列\apache-activemq-5.13.2
    bin\activemq start

3.在客户端程序中指定brokerURL

 # use the following property to configure the default connector
java.naming.provider.url=failover:(tcp://192.168.74.55:61616,tcp://192.168.74.26:61616,tcp://192.168.74.25:61616)?initialReconnectDelay=1000

说明:brokerURL以”failover:(tcp://ip-1:amq-port-1,tcp://ip-2:amq-port-2,tcp://ip-3:amq-port-3)”的形式配置,则客户端会尝试依次进行连接;失败则继续尝试连接下一个。引入ZooKeeper之后,只有被选定为主服务器那一台可以被连接。

相关补充


1.已知情况

  1. 超过一半的故障,则体系失效
    如果有2台ActiveMQ故障,则体系不再工作,且会阻塞客户端(同步的客户端会被阻塞)

2.未确定内容

  1. 对上文的部署方案是否有改进建议。
  2. 将Producers、Consumers直接集成到应用系统,还是再抽出一层?
  3. 对于一半以上的故障,如何预防?
    — 如何获得宕机提醒?如何实现自动重启?
  4. 面向日志的采集,应该选择哪种消息传送模式(队列、发布/订阅)?
  5. 计划对上述的体系进行压力测试,以获取吞吐量的上限值;对测试的方案有何建议?

3.新问题

  1. Consumer异常阻塞是否会导致其他Consumer阻塞?

参考文章


  1. 基于zookeeper+leveldb搭建activemq集群
    主从部署的实施方案。
  2. 分布式服务框架 Zookeeper — 管理分布式环境中的数据
    简单了解ZooKeeper
  3. ActiveMQ实现负载均衡+高可用部署方案
    主从部署和集群部署的区别、实现
  4. Replicated LevelDB Store
    官网有对配置的参数进行详细的解说

来自为知笔记(Wiz)

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,083
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,558
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,407
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,180
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,817
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,900