ActiveMq+zookeeper+levelDB集群整合配置

环境:linux系统,jdk1.7  三台linux系统电脑。我这里使用一台window,分别远程3台linux电脑。三台电脑的ip分别为10.0.88.10 ,10.0.88.11 ,10.0.88.12

第一步:下载activemq 和zookeeper,levelDB会activemq自带有,所以不需要下载,把下载好的压缩包发送到所有的linux上,(我这里是把下载好的压缩包放在当前window下的tomcat,root目录下,可在linux终端上使用命令:curl -o activeMq.tar.gz http://10.0.10.37:8080/apache-linux-activemq-5.11.1-bin.tar.gz把activemq下载下来)关键就是配置好zookeeper集群和activemq集群。

第二步:登录linux系统,在某个目录下新建文件activemq,使用curl -o activeMQ.tar.gz  http://10.0.10.37:8080/apache-linux-activemq-5.11.1-bin.tar.gz 下载activeMQ.tar.gz,相应的把zookeeper.tar.gz下载到activemq目录下,分别解压这两个文件放在activeMQ文件夹下,和zookeeper文件夹下。

第三步:当linux系统的所有的压缩包都解压好了,所有的文件都准备好了, zookeeper比如在目录/home/activemq/zookeeper目录下,activemq在/home/activemq/activemq目录下,那么我们先来配置zookeeper,在zookeeper/conf目录下找到zoo_sample.cfg文件,使用命令cp  -f zoo_sample.cfg zoo.cfg 复制成zoo.cfg文件,使用命令vi zoo.cfg  再按键盘I,进入编辑状态,修改zoo.cfg内容为

 
 

# 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.

# the port at which the clients will connect

clientPort=2181

# the directory where the snapshot is stored.

dataDir=/home/ activemq/zookeeper/data/data

# the port at which the clients will connect

dataLogDir=/home/activemq/zookeeper/data/log

# add diffenrent server

server.1=10.0.88.10:2888:3888

server.2=10.0.88.11:2888:3888

server.3=10.0.88.12:2888:3888

这里有dataDir=/home/ activemq/zookeeper/data/data和

dataLogDir=/home/activemq/zookeeper/data/log

如果没有这些目录,我们需要新建这些目录

建好目录之后,在dataDir目录下,新建myid文件,使用命令:touch  myid 新建文件,内容为当前机子ip所对应的zoo.cfg中server.x中的x,比如:按照上面配置zoo.cfg当前电脑ip为10.0.88.12,则myid的内容就为3,这里注意:myid文件中不能留任何空格,空行,zoo.cfg文件中的注释#与注释内容之间需要加一个空格,不是注释的,前面不能留空格和不能重写相同的变量。

第四步:上面配置完之后,需要配置一下环境变量,方便操作,先使用命令才cd /进入根目录,使用root权限,使用vi /etc/profile,编辑profile文件,在PATH面前添加配置如下:

export ZOOKEEPER=/home/activemq/zookeeper

export PATH=$PATH:$ZOOKEEPER/bin:$ZOOKEEPER/conf

这里注意conf目录也要添加进来,要不可能会报错的

配置好之后,使用命令:source  /etc/profile 使配置生效。

第五步:配置好上述之后,接下来就是测试了

使用zkServer.sh start 命令启动zookeeper,中途可能会出现一些错误,当出现错误或者查看zkServer.sh status命令的时候,不正常,可以查看dataDir或者dataLogDir目录下的zookeeper.out文件,里面有相应的启动记录,启动每个电脑的zookeeper服务器时,使用zkServer.sh status 查看状态,如果如图有出现红圈中的mode字样说明配置成功了:

在配置过程中,我遇到的问题,有端口被占用的,弄了好久,后来还是解决了,端口占用的进程名QuorumPeerMain这也是zookeeper进程名称,使用命令

ps -ef | grep QuorumPeerMain 查出进程ID,使用kill -9  进程ID  结束进程。

Zookeeper配置大概就这些了

下面我们配置activemq

配置activemq比较简单

自从activemq5.9.0开始,activemq的集群实现方式取消了传统的Master-Slave方式,增加了基于zookeeper+leveldb的实现方式,其他两种方式:目录共享和数据库共享依然存在。本文主要阐述基于zookeeper和leveldb搭建activemq集群,这里需要特别提醒,本文实现的集群仅提供主备功能,避免单点故障,没有负载均衡功能。

在conf目录下找到activemq.xml 把里面内容的

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

替换成

 
 

<replicatedLevelDB

directory="${activemq.data}/leveldb"

replicas="3"

bind="tcp://0.0.0.0:0"

zkAddress="10.0.88.10:2181,10.0.88.11:2181,10.0.88.12:2181"

<!-- zkPassword="password"-->

hostname="10.0.88.10"

sync="local_disk"

zkPath="/activemq/leveldb-stores"

/>

这里的hostname要写当前机子ip

接下来配置环境变量,方便操作。由于我的系统是64位的,所以我在profile后新添加一条语句:

export  $PATH:/home/ activemq /activemq /bin/linux-x86-64

不同的位数系统,选择不同的activemq,如果是32位的好像是

export  $PATH:/home/ activemq /activemq /bin/linux-x86-32

那么配置完成了,使用source  /etc/profile使命令生效

activemq start 启动

在这里要先启动zookeeper 在启动activemq

配置好了,测试一下,使用命令:http://10.0.88.10:8161/admin/index.jsp如果能运行,说明activemq启动成功,如果把10.0.88.10上的activemq关闭了,这个链接还可以访问,说明配置已经成功。

注意事项:如果activemq启动出错的,我们可以在启动目录下的wrapper.log文件查看哪里出错。

配置注意事项

1、  zoo.cfg文档开头和结尾不能留空格

2、  myid前后不能留换行和空格

3、  zookeeper 进程名为QuorumPeerMain

4、  zoo.cfg配置文件写法需要注意,不能重写同一个变量

activemq在不同权限下可以启动两个不同的activemq服务,如果某个机子上有activemq关闭了,客户端还可以访问,说明还有一个activemq在启动

优化配置待续

修改activemq文件改变内存ACTIVEMQ_OPTS_MEMORY="-Xms256M -Xmx384M -XX:PermSize=256M -XX:MaxPermSize=384M"

注意的问题:

1、         通过failover方式进行连接,多个AMQ实例地址使用英文逗号隔开,当某个实例断开时会自动重连,但如果所有实例都失效,failover默认情况下会无限期的等待下去,不会有任何提示

2、        不要频繁的建立和关闭连接JMS使用长连接方式,一个程序,只要和JMS服务器保持一个连接就可以了,不要频繁的建立和关闭连接。频繁的建立和关闭连接,对程序的性能影响还是很大的。这一点和jdbc还是不太一样的。

3、      JMS的Connection的start()和stop()方法代价很高,不能经常调用。我们试用的时候,写了个jms的connection pool,每次将connection取出pool时调用start()方法,归还时调用stop()方法,然而后来用jprofiler发现,一般的 cpu时间都耗在了这两个方法上

4、      网址http://www.blogjava.net/livery/articles/316269.html

代码:activemq.xml

<!--

Licensed to the Apache Software Foundation (ASF) under one or more

contributor license agreements.  See the NOTICE file distributed with

this work for additional information regarding copyright ownership.

The ASF licenses this file to You under the Apache License, Version 2.0

(the "License"); you may not use this file except in compliance with

the License.  You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software

distributed under the License is distributed on an "AS IS" BASIS,

WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

See the License for the specific language governing permissions and

limitations under the License.

-->

<!-- START SNIPPET: example -->

<beans

xmlns="http://www.springframework.org/schema/beans"

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd

http://activemq.apache.org/schema/core http://activemq.apache.org/schema/core/activemq-core.xsd">

<!-- Allows us to use system properties as variables in this configuration file -->

<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">

<property name="locations">

<value>file:${activemq.conf}/credentials.properties</value>

</property>

</bean>

<!-- Allows accessing the server log -->

<bean id="logQuery" class="io.fabric8.insight.log.log4j.Log4jLogQuery"

lazy-init="false" scope="singleton"

init-method="start" destroy-method="stop">

</bean>

<!--

The <broker> element is used to configure the ActiveMQ broker.

-->

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

<destinationPolicy   >

<policyMap>

<policyEntries>

<policyEntry topic=">" topicPrefetch="10000" producerFlowControl="false" useCache="true" >

<!-- The constantPendingMessageLimitStrategy is used to prevent

slow topic consumers to block producers and affect other consumers

by limiting the number of messages that are retained

For more information, see:

http://activemq.apache.org/slow-consumer-handling.html

-->

<pendingSubscriberPolicy>

<vmCursor />

</pendingSubscriberPolicy>

<pendingDurableSubscriberPolicy>

<storeDurableSubscriberCursor/>

</pendingDurableSubscriberPolicy>

<!-- <pendingMessageLimitStrategy>

<constantPendingMessageLimitStrategy limit="1000"/>

</pendingMessageLimitStrategy>-->

</policyEntry>

<policyEntry queue=">" producerFlowControl="true" queuePrefetch="10000" memoryLimit="100mb" useCache="true">

<pendingQueuePolicy>

<vmQueueCursor/>

</pendingQueuePolicy>

<pendingDurableSubscriberPolicy>

<storeDurableSubscriberCursor/>

</pendingDurableSubscriberPolicy>

<pendingQueuePolicy>

<storeCursor />

</pendingQueuePolicy>

<slowConsumerStrategy>

<abortSlowConsumerStrategy  abortConnection="false"/><!-- 30second -->

</slowConsumerStrategy>

</policyEntry>

</policyEntries>

</policyMap>

</destinationPolicy>

<networkConnectors>

<networkConnector uri="static:(tcp://10.0.88.10:61616,tcp://10.0.88.11:61616,tcp://10.0.88.12:61616)"/>

</networkConnectors>

<!--

The managementContext is used to configure how ActiveMQ is exposed in

JMX. By default, ActiveMQ uses the MBean server that is started by

the JVM. For more information, see:

http://activemq.apache.org/jmx.html

-->

<managementContext>

<managementContext createConnector="false"/>

</managementContext>

<!--

Configure message persistence for the broker. The default persistence

mechanism is the KahaDB store (identified by the kahaDB tag).

For more information, see:

http://activemq.apache.org/persistence.html

-->

<persistenceAdapter>

<replicatedLevelDB

directory="${activemq.data}/leveldb"

replicas="3"

bind="tcp://0.0.0.0:0"

zkAddress="10.0.88.10:2181,10.0.88.11:2181,10.0.88.12:2181"

hostname="10.0.88.12"

sync="local_disk"

zkPath="/activemq/leveldb-stores"

/>

</persistenceAdapter>

<!--

The systemUsage controls the maximum amount of space the broker will

use before disabling caching and/or slowing down producers. For more information, see:

http://activemq.apache.org/producer-flow-control.html

-->

<systemUsage>

<systemUsage>

<memoryUsage>

<memoryUsage percentOfJvmHeap="70" />

</memoryUsage>

<storeUsage>

<storeUsage limit="100 gb"/>

</storeUsage>

<tempUsage>

<tempUsage limit="50 gb"/>

</tempUsage>

</systemUsage>

</systemUsage>

<!--

The transport connectors expose ActiveMQ over a given protocol to

clients and other brokers. For more information, see:

http://activemq.apache.org/configuring-transports.html

-->

<transportConnectors>

<!-- DOS protection, limit concurrent connections to 1000 and frame size to 100MB -->

<transportConnector name="openwire" uri="tcp://0.0.0.0:61616?maximumConnections=10000&amp;wireFormat.maxFrameSize=1048576000"/>

<transportConnector name="amqp" uri="amqp://0.0.0.0:5672?maximumConnections=1000&amp;wireFormat.maxFrameSize=104857600"/>

<transportConnector name="stomp" uri="stomp://0.0.0.0:61613?maximumConnections=1000&amp;wireFormat.maxFrameSize=104857600"/>

<transportConnector name="mqtt" uri="mqtt://0.0.0.0:1883?maximumConnections=1000&amp;wireFormat.maxFrameSize=104857600"/>

<transportConnector name="ws" uri="ws://0.0.0.0:61614?maximumConnections=1000&amp;wireFormat.maxFrameSize=104857600"/>

</transportConnectors>

<!-- destroy the spring context on shutdown to stop jetty -->

<shutdownHooks>

<bean xmlns="http://www.springframework.org/schema/beans" class="org.apache.activemq.hooks.SpringContextHook" />

</shutdownHooks>

</broker>

<!--

Enable web consoles, REST and Ajax APIs and demos

The web consoles requires by default login, you can disable this in the jetty.xml file

Take a look at ${ACTIVEMQ_HOME}/conf/jetty.xml for more details

-->

<import resource="jetty.xml"/>

</beans>

<!-- END SNIPPET: example -->

ActiveMq+zookeeper+levelDB集群整合配置的更多相关文章

  1. 关于ActiveMQ+Zookeeper做集群时,解决启动报错:java.io.IOException: com/google/common/util/concurrent/internal/InternalFutureFailureAccess

    这个问题我也是无意间碰到的,之前一直是使用单机的ActiveMQ,所以也没这个问题,但是做集群时碰到这个问题,问题是这样子出现的: 首先,我准备了三台虚拟机,然后使用 Replicated Level ...

  2. centos6下ActiveMQ+Zookeeper消息中间件集群部署记录

    由于最近一个项目并发请求压力比较大,所以考虑改进架构,引入消息中间件集群作为一个缓冲消息队列,具体需求:1)将大量的WebService请求报文发送到mq集群之中,并保持消息先后顺序2)保证每个消息的 ...

  3. ZooKeeper笔记--集群安装配置 【转】

    ZooKeeper是一个分布式开源框架,提供了协调分布式应用的基本服务,它向外部应用暴露一组通用服务——分布式同步(Distributed Synchronization).命名服务(Naming S ...

  4. JAVAEE——宜立方商城08:Zookeeper+SolrCloud集群搭建、搜索功能切换到集群版、Activemq消息队列搭建与使用

    1. 学习计划 1.solr集群搭建 2.使用solrj管理solr集群 3.把搜索功能切换到集群版 4.添加商品同步索引库. a) Activemq b) 发送消息 c) 接收消息 2. 什么是So ...

  5. hadoop+yarn+hbase+storm+kafka+spark+zookeeper)高可用集群详细配置

    配置 hadoop+yarn+hbase+storm+kafka+spark+zookeeper 高可用集群,同时安装相关组建:JDK,MySQL,Hive,Flume 文章目录 环境介绍 节点介绍 ...

  6. 初识ZooKeeper与集群搭建实例

    原文链接:http://www.linuxidc.com/Linux/2015-02/114230.htm zookeeper是什么 Zookeeper,一种分布式应用的协作服务,是Google的Ch ...

  7. 四:ZooKeeper的集群,伪集群,单机的搭建

    一:ZooKeeper服务安装包下载 第一步:打开zooKeeper官网

  8. 基于zookeeper(集群)+LevelDB的ActiveMq高可用集群安装、配置、测试

    一. zookeeper安装(集群):http://www.cnblogs.com/wangfajun/p/8692117.html  √ 二. ActiveMq配置: 1. ActiveMq集群部署 ...

  9. ActiveMQ 高可用集群安装、配置(ZooKeeper + LevelDB)

    ActiveMQ 高可用集群安装.配置(ZooKeeper + LevelDB) 1.ActiveMQ 集群部署规划: 环境: JDK7 版本:ActiveMQ 5.11.1 ZooKeeper 集群 ...

随机推荐

  1. 构建千万级web访问架构

    . HTML静态化 其实大家都知道,效率最高.消耗最小的就是纯静态化的html页面,所以我们尽可能使我们的网站上的页面采用静态页面来实现,这个最简单的方法其实也是最有效的方法.但是对于大量内容并且频繁 ...

  2. Spark之路 --- Scala IDE Maven配置(使用开源中国的Maven库)和使用

    为什么要使用Maven 摘自百度百科的介绍 Maven是基于项目对象模型(POM),可以通过一小段描述信息来管理项目的构建,报告和文档的软件项目管理工具.Maven 除了以程序构建能力为特色之外,还提 ...

  3. TIANKENG’s rice shop

    Problem Description TIANKENG managers a pan fried rice shop. There are n kinds of fried rice numbere ...

  4. 移植最新u-boot(裁剪和修改默认参数)之韦东山笔记

    1.下载.建立source insight工程.编译.烧写.如果无运行分析原因 tar xjf u-boot-2012.04.01.tar.bz2 cd u-boot-2012.04.01 make ...

  5. u-boot移植为tiny6410步骤

    1. 修改顶层Makefile文件 2. 修改arch/arm/cpu/arm1176/s3c64xx/cpu_init.S 3. 修改arch/arm/cpu/arm1176/s3c64xx/Mak ...

  6. java+mysql实现保存图片到数据库,以及读取数据库存储的图片

    一:建表 二:获取数据库连接 1:导入mysql的驱动jar包,mysql-connector-java-5.1.8-bin.jar 2:写代码连接数据库,如下: /** * */ package c ...

  7. poj 1679 次小生成树

    次小生成树的求法: 1.Prime法 定义一个二维数组F[i][j]表示点i到点j在最小生成树中的路径上的最大权值.有个知识就是将一条不在最小生成树中的边Edge加入最小生成树时,树中要去掉的边就是E ...

  8. IIS设置允许下载.exe文件解决方法(转)

    最近很多客户使用IIS服务器,然后提示返现宝下载无法找到等无法下载的问题. 返现宝是.exe安装文件,部分服务器或主机可能无法下载. 第一.如果是自己服务器或VPS请按如下设置: 1.设置MIME,让 ...

  9. saltstack实战4--综合练习2

    Saltstack配置管理-功能模块-安装haproxy 配置管理,我们分了3层 最底层是系统初始化部分 倒数二层是功能模块,就是具体的产品的安装了 假如你的环境需要nginx,php,memcach ...

  10. jquery jsonp实现跨域

    html代码: $("#testJsonp").click(function(){ $.ajax({ url: "http://www.test.cc/1.php&quo ...