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
 #tar zxvf jdk-8u112-linux-x64.tar.gz
 #vi /etc/profile       添加以下内容
 
export JAVA_HOME=/opt/jdk-8u112
export PATH=$JAVA_HOME/bin:$PATH
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
#source /etc/profile
#java -version
java version "1.8.0_12"
Java(TM) SE Runtime Environment (build 1.8.0_12-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.12-b03, mixed mode)

二、安装配置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 -zxvf apache-activemq-5.14.5-bin.tar.gz
# vi conf/activemq.xml   192.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/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">

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

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

  <import resource="jetty.xml"/>
</beans>

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

#vi conf/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/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">

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

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

  <import resource="jetty.xml"/>
</beans>

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

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

2017-05-12 09:33:43,404 | INFO  | Establishing network connection from vm://activemq-1?async=false&create=false to tcp://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时,配置文件可以这么写:

<bean id="jmsFactory" class="org.apache.activemq.pool.PooledConnectionFactory" destroy-method="stop">
    <property name="connectionFactory">
        <bean class="org.apache.activemq.ActiveMQConnectionFactory">
            <!--broker服务的地址-->
            <property name="brokerURL" value="http://xiangcun168.blog.51cto.com/4788340/failover:(tcp://192.168.1.104:61616,tcp://192.168.1.105:61626)"/>
            ...
        </bean>
    </property>
</bean>

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




本文出自 “xiangcun168” 博客,请务必保留此出处http://xiangcun168.blog.51cto.com/4788340/1924888

赞 (0) 评论 分享 ()