设为首页 收藏本站
查看: 5104|回复: 0

[经验分享] Activemq 安全机制以及稳定性研究

[复制链接]

尚未签到

发表于 2017-2-28 11:32:23 | 显示全部楼层 |阅读模式
  1) 安全接入机制:
  activemq启动时加载配置文件$ACTIVEMQ_HOME/conf/activemq.xml, 在activemq.xml的<broker>节点中添加以下元素以提供对建立连接时的用户名/密码的支持:



<plugins>
    <simpleAuthenticationPlugin>
      <users>
        <authenticationUser username="system" password="manager"
            groups="users,admins"/>
        <authenticationUser username="user" password="password"
            groups="users"/>
        <authenticationUser username="guest" password="password" groups="guests"/>
      </users>
    </simpleAuthenticationPlugin>
      <!--  lets configure a destination based authorization mechanism -->
    <authorizationPlugin>
        <map>
          <authorizationMap>
            <authorizationEntries>
              <authorizationEntry queue=">" read="admins" write="admins" admin="admins" />
              <authorizationEntry queue="USERS.>" read="users" write="users" admin="users" />
              <authorizationEntry queue="GUEST.>" read="guests" write="guests,users" admin="guests,users" />
              <authorizationEntry topic=">" read="admins" write="admins" admin="admins" />
              <authorizationEntry topic="USERS.>" read="users" write="users" admin="users" />
              <authorizationEntry topic="GUEST.>" read="guests" write="guests,users" admin="guests,users" />
              <authorizationEntry topic="ActiveMQ.Advisory.>" read="guests,users" write="guests,users" admin="guests,users"/>
            </authorizationEntries>
            <!-- let's assign roles to temporary destinations. comment this entry if we don't want any roles assigned to temp destinations  -->
            <tempDestinationAuthorizationEntry>  
              <tempDestinationAuthorizationEntry read="tempDestinationAdmins" write="tempDestinationAdmins" admin="tempDestinationAdmins"/>
           </tempDestinationAuthorizationEntry>               
          </authorizationMap>
        </map>
     </authorizationPlugin>
   </plugins>
  其中对哪种用户能够访问哪些类型的队列做了限制。
  在客户端java连接activemq的配置如下:



<bean id="connectionFactory" class="org.apache.activemq.ActiveMQConnectionFactory">
                <property name="brokerURL">
            <value>tcp://10.100.8.5:61616?wireFormat.maxInactivityDuration=0&amp;jms.useAsyncSend=true</value>
        </property>
<property name="userName" value="system"/>
<property name="password" value="manager"/>
    </bean>
  2)限定只能从本地连接activemq:
  <transportConnectors>
  <transportConnector name="openwire" uri="tcp://0.0.0.0:61616" />
  </transportConnectors>
  将上面的0.0.0.0改为localhost或127.0.0.1即可限定只能从本机连接。
  3) 主备机机制:
  将连接的url设置为:

    failover:(tcp://primary:61616,tcp://secondary:61616)?randomize=false

  当primary断开后,会自动地连接secondary.
  例如:



<bean id="connectionFactory" class="org.apache.activemq.ActiveMQConnectionFactory">
        <!-- mq's URL -->
        <!-- wireFormat.maxInactivityDuration=0 means never close the inactive connection -->
        <property name="brokerURL">
            <value>failover:(tcp://localhost:61616?wireFormat.maxInactivityDuration=0,tcp://10.100.8.5:61616?wireFormat.maxInactivityDuration=0)?randomize=false&amp;jms.useAsyncSend=true</value>
        </property>
    </bean>
  注意当使用failover:时,jms.*类型的参数写在括号外面才对,否则activemq不能正确解析。

4)在同一个机器上启动多个MQ Broker:

Master的配置文件为conf/activemq.xml, 将其复制一份,保存为activemq2.xml,然后做如下的修改:
1.        修改broker的name属性,如:brokerName=”slaveBroker”, 添加broker的属性 masterConnectorURI="tcp://masterhost:62001"
2.        修改data directory位置,使其不与master的data directory重复:
<persistenceAdapter>
       <kahaDB directory=”${activemq.base}/data/kahaDB2” />
</persistenceAdapter>

3.        修改WEB控制台配置:
web控制台的配置在jetty.xml中,复制这个文件保存为jetty2.xml,然后将jetty2.xml作为web控制台的配置文件:
<import resource=”jetty2.xml”/>
然后在jetty2.xml中修改web服务的端口以避免冲突:
<bean id=”Connector” …>
       <property name=”port” value=”8102” />
</bean>

启动slave broker:
cd  ${activemq-base}/bin
./activemq xbean:activemq2.xml  &

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-348395-1-1.html 上篇帖子: 学习WebX的一些小心得 下篇帖子: Maven2的配置文件settings.xml
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表