溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

centos activemq 集群配置 Networks of Brokers

發(fā)布時(shí)間:2020-05-27 06:15:53 來源:網(wǎng)絡(luò) 閱讀:1211 作者:jackjiaxiong 欄目:建站服務(wù)器

1、安裝JDK運(yùn)行環(huán)境

 #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       添加以下內(nèi)容
 
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這二個(gè)broker就互為主備,發(fā)給你的消息會(huì)同步到我,發(fā)給我的消息也會(huì)同步到你,實(shí)現(xiàn)了HA,示意圖如下:192.168.1.104:61616<-->192.168.1.105:61626

這種HA方案的優(yōu)點(diǎn)是占用的節(jié)點(diǎn)數(shù)更少(只需要2個(gè)節(jié)點(diǎn)),而且2個(gè)broker都可以響應(yīng)消息的接收與發(fā)送,性能比zookeeper方案要好一些。

centos activemq 集群配置 Networks of Brokers



#wget 
#tar -zxvf apache-activemq-5.14.5-bin.tar.gz
# vi conf/activemq.xml   192.168.1.104上進(jìn)行配置(寫入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>

配置完后,我們分別啟動(dòng),

# bin/activemq start
#tail -f data/activemq.log 查看日志  可以看到已經(jīng)建立連接

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 控制臺(tái)

http://ip:8161/admin/   (默認(rèn)的賬號(hào):admin 默認(rèn)密碼:admin)

centos activemq 集群配置 Networks of Brokers

centos activemq 集群配置 Networks of Brokers


Producer與Consumer連接到activemq時(shí),配置文件可以這么寫:

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

這種HA方案的優(yōu)點(diǎn)是占用的節(jié)點(diǎn)數(shù)更少(只需要2個(gè)節(jié)點(diǎn)),而且2個(gè)broker都可以響應(yīng)消息的接收與發(fā)送,性能比zookeeper方案要好一些。






向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI