ActiveMQ介绍

  1. ActiveMQ Apache出品,最流行的,能力强劲的开源消息总线。ActiveMQ 是一个完全支持JMS1.1J2EE 1.4规范的 JMS Provider实现,尽管JMS规范出台已经是很久的事情了,但是JMS在当今的J2EE应用中间仍然扮演着特殊的地位。

特性:
1.支持多种语言和协议编写客户端。如:Java、C、C++、C#、Python等
2.完全支持JMS1.1和J2EE 1.4规范 (持久化,XA消息,事务)
3.消息的持久化支持Memory、KahaDB、LevelDB、Database方式
4.设计上保证了高性能的集群,客户端-服务器,点对点

安装包准备:

jdk-7u79-linux-x64.tar.gz
apache-activemq-5.11.0.redhat-621084-bin.zip //这里采用的是Redhat版本的,开源下载地址
mysql-connector-java-5.1.13.jar //放到$activemq_dir/lib目录下

部署结构

安装 - 图1

JDK安装

检查系统自带的jdk版本

[root@localhost ~]# java -version
[root@localhost ~]# rpm -qa | grep java

卸载自带的JDK的信息[没有自带JDK可不执行]

[root@localhost ~]# rpm -e java-1.7.0-openjdk-1.7.0.79-2.5.5.4.el6.x86_64
[root@localhost ~]# rpm -e java-1.6.0-openjdk-1.6.0.35-1.13.7.1.el6_6.x86_64

tar.gz包安装

进入/opt目录
[root@localhost ~]# cd /opt/
解压安装包
[root@localhost ~]# tar -zxf jdk-7u79-linux-x64.tar.gz -C /opt
[root@localhost ~]# cd /opt
对解压的目录重命名
[root@localhost ~]# mv jdk1.7.0_79 jdk
改变/opt/jdk的目录权限
[root@localhost ~]# chown -R root.root /opt/jdk
[root@localhost ~]# ls -ld /opt/jdk

配置环境变量,在/etc/profile文件下添加

[root@localhost ~]# cp -a /etc/profile /etc/profile.ori
[root@localhost ~]# ll /etc/profile*

[root@localhost ~]# echo ‘export JAVA_HOME=/opt/jdk’ >> /etc/profile
[root@localhost ~]# echo ‘export CLASSPATH=$JAVA_HOME/lib’ >> /etc/profile
[root@localhost ~]# echo ‘export PATH=$JAVA_HOME/bin:$PATH’ >> /etc/profile

执行环境变量

[root@localhost ~]# source /etc/profile

查看设置的环境变量

[root@localhost ~]# echo $PATH
[root@localhost ~]# echo $CLASSPATH
[root@localhost ~]# echo $JAVA_HOME

查看java版本

[root@localhost ~]# java -version
安装 - 图2

ActiveMQ安装

[root@localhost ~]# tar -zxvf apache-activemq-5.11.0.redhat-621084-bin.zip
[root@localhost ~]# cd apache-activemq-5.11.0.redhat-621084
[root@localhost ~]# vi conf/users.properties
将#admin=admin这行前的注释去除
[root@localhost ~]# vi conf/groups.properties
将#admins=admin这行前的注释去除
[root@localhost ~] vi conf/activemq.xml

1.开JMX远程管理功能:
broker标签 添加 “useJmx=”true””

2.managementContext修改为:

3.添加MySQL持久化方式

  1. <persistenceAdapter>
  2. <jdbcPersistenceAdapter dataDirectory="${activemq.base}/data" dataSource="#mysql-ds" lockKeepAlivePeriod="5000" >
  3. <locker>
  4. <lease-database-locker lockAcquireSleepInterval="10000"/>
  5. </locker>
  6. </jdbcPersistenceAdapter>
  7. </persistenceAdapter>

4.添加Mysql的Bean

  1. <bean id="mysql-ds" class="org.apache.commons.dbcp2.BasicDataSource" destroy-method="close">
  2. <property name="driverClassName" value="com.mysql.jdbc.Driver"/>
  3. <property name="url" value="jdbc:mysql://192.168.1.123:3306/mq?relaxAutoCommit=true"/>
  4. <property name="username" value="root"/>
  5. <property name="password" value="123456"/>
  6. <property name="maxTotal" value="200"/>
  7. <property name="poolPreparedStatements" value="true"/>
  8. </bean>

5.添加virtualTopic

  1. <destinationIterceptors>
  2. <virtualDestinationInterceptor>
  3. <virtualDestinations>
  4. <virtualTopic name=">" prefix="Foo.*." selectorAware="false"/>
  5. </virtualDestinations>
  6. </virtualDestinationInterceptor>
  7. </destinationInterceptors>

6.添加免密认证

plugins标签下添加如下内容:

  1. <simpleAuthenticationPlugin anonymousAccessAllowed="true">
  2. <users>
  3. <authenticationUser username="admin" password="admin" groups="users,admins"/>
  4. </users>
  5. </simpleAuthenticationPlugin>
  6. <!-- Lets configure a destination based authorization mechanism -->
  7. <authorizationPlugin>
  8. <map>
  9. <authorizationMap>
  10. <authorizationEntries>
  11. <authorizationEntry queue=">" read="admins,anonymous" write="admins,anonymous" admin="admins,anonymous" />
  12. <authorizationEntry topic=">" read="admins,anonymous" write="admins,anonymous" admin="admins,anonymous" />
  13. <authorizationEntry topic="ActiveMQ.Advisory.>" read="guests,users,anonymous" write="guests,users,anonymous" admin="guests,users,anonymous"/>
  14. </authorizationEntries>
  15. </authorizationMap>
  16. </map>
  17. </authorizationPlugin>

[root@localhost ~] vi /etc/hosts

添加如下:

主机IP ** **主机名(通过hostname可以得到)