centos activemq 集群配置 Networks of Brokers

前端之家收集整理的这篇文章主要介绍了centos activemq 集群配置 Networks of Brokers前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

1、安装JDK运行环境

#cd/opt
#wget--no-check-certificate--no-cookies--header"Cookie:oraclelicense=accept-securebackup-cookie"http://download.oracle.com/otn-pub/java/jdk/8u112-b15/jdk-8u112-linux-x64.tar.gz
#tarzxvfjdk-8u112-linux-x64.tar.gz
#vi/etc/profile添加以下内容

exportJAVA_HOME=/opt/jdk-8u112
exportPATH=$JAVA_HOME/bin:$PATH
exportCLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
#source/etc/profile
#java-version
javaversion"1.8.0_12"
Java(TM)SERuntimeEnvironment(build1.8.0_12-b12)
JavaHotSpot(TM)64-BitServerVM(build25.12-b03,mixedmode)

二、安装配置activemq

在这里我们配置Networks of Brokers集群模式

activemq-1与activemq-2这二个broker就互为主备,发给你的消息会同步到我,发给我的消息也会同步到你,实现了HA,示意图如下:192.168.1.104:61616<-->192.168.1.105:61626

这种HA方案的优点是占用的节点数更少(只需要2个节点),而且2个broker都可以响应消息的接收与发送,性能比zookeeper方案要好一些。

wKiom1kVDY7CWEFEAAEQ1FH8mow454.png-wh_50



#wget
#tar-zxvfapache-activemq-5.14.5-bin.tar.gz
#viconf/activemq.xml192.168.1.104上进行配置(写入192.168.1.105:61626)

<beans
xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans.xsd
http://activemq.apache.org/schema/corehttp://activemq.apache.org/schema/core/activemq-core.xsd">

<beanclass="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<propertyname="locations">
<value>file:${activemq.conf}/credentials.properties</value>
</property>
</bean>

<brokerxmlns="http://activemq.apache.org/schema/core"brokerName="activemq-1">
<networkConnectors>
<networkConnectoruri="static:(tcp://192.168.1.105:61626)"/>
</networkConnectors>
<persistenceAdapter>
<kahaDBdirectory="${activemq.data}/kahadb"/>
</persistenceAdapter>
<transportConnectors>
<transportConnectorname="openwire"
uri="tcp://0.0.0.0:61616?maximumConnections=1000&amp;wireFormat.maxFrameSize=104857600"/>
</transportConnectors>
</broker>

<importresource="jetty.xml"/>
</beans>

同理,在192.168.1.105上配置(写入192.168.1.104:61616)

#viconf/activemq.xml
<beans
xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans.xsd
http://activemq.apache.org/schema/corehttp://activemq.apache.org/schema/core/activemq-core.xsd">

<beanclass="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<propertyname="locations">
<value>file:${activemq.conf}/credentials.properties</value>
</property>
</bean>

<brokerxmlns="http://activemq.apache.org/schema/core"brokerName="activemq-1">
<networkConnectors>
<networkConnectoruri="static:(tcp://192.168.1.104:61616)"/>
</networkConnectors>
<persistenceAdapter>
<kahaDBdirectory="${activemq.data}/kahadb"/>
</persistenceAdapter>
<transportConnectors>
<transportConnectorname="openwire"
uri="tcp://0.0.0.0:61626?maximumConnections=1000&amp;wireFormat.maxFrameSize=104857600"/>
</transportConnectors>
</broker>

<importresource="jetty.xml"/>
</beans>

配置完后,我们分别启动,

#bin/activemqstart
#tail-fdata/activemq.log查看日志可以看到已经建立连接

2017-05-1209:33:43,404|INFO|Establishingnetworkconnectionfromvm://activemq-1?async=false&create=falsetotcp://192.168.1.105:61626|
org.apache.activemq.network.DiscoveryNetworkConnector|main


访问activemq 控制台

http://ip:8161/admin/(默认的账号:admin默认密码:admin)

wKioL1kVFpjiO6MzAADNJvaAl9Y601.png-wh_50

wKiom1kVFpiC4cxnAADDrCUyuoY129.png-wh_50


Producer与Consumer连接到activemq时,配置文件可以这么写:

<beanid="jmsFactory"class="org.apache.activemq.pool.PooledConnectionFactory"destroy-method="stop">
<propertyname="connectionFactory">
<beanclass="org.apache.activemq.ActiveMQConnectionFactory">
<!--broker服务的地址-->
<propertyname="brokerURL"value="failover:(tcp://192.168.1.104:61616,tcp://192.168.1.105:61626)"/>
...
</bean>
</property>
</bean>

性能比zookeeper方案要好一些。

猜你在找的CentOS相关文章