ActiveMQ介绍
ActiveMQ 是Apache出品,最流行的,能力强劲的开源消息总线。ActiveMQ 是一个完全支持JMS1.1和J2EE 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目录下
部署结构
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
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持久化方式
<persistenceAdapter>
<jdbcPersistenceAdapter dataDirectory="${activemq.base}/data" dataSource="#mysql-ds" lockKeepAlivePeriod="5000" >
<locker>
<lease-database-locker lockAcquireSleepInterval="10000"/>
</locker>
</jdbcPersistenceAdapter>
</persistenceAdapter>
4.添加Mysql的Bean
<bean id="mysql-ds" class="org.apache.commons.dbcp2.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="com.mysql.jdbc.Driver"/>
<property name="url" value="jdbc:mysql://192.168.1.123:3306/mq?relaxAutoCommit=true"/>
<property name="username" value="root"/>
<property name="password" value="123456"/>
<property name="maxTotal" value="200"/>
<property name="poolPreparedStatements" value="true"/>
</bean>
5.添加virtualTopic
<destinationIterceptors>
<virtualDestinationInterceptor>
<virtualDestinations>
<virtualTopic name=">" prefix="Foo.*." selectorAware="false"/>
</virtualDestinations>
</virtualDestinationInterceptor>
</destinationInterceptors>
6.添加免密认证
plugins标签下添加如下内容:
<simpleAuthenticationPlugin anonymousAccessAllowed="true">
<users>
<authenticationUser username="admin" password="admin" groups="users,admins"/>
</users>
</simpleAuthenticationPlugin>
<!-- Lets configure a destination based authorization mechanism -->
<authorizationPlugin>
<map>
<authorizationMap>
<authorizationEntries>
<authorizationEntry queue=">" read="admins,anonymous" write="admins,anonymous" admin="admins,anonymous" />
<authorizationEntry topic=">" read="admins,anonymous" write="admins,anonymous" admin="admins,anonymous" />
<authorizationEntry topic="ActiveMQ.Advisory.>" read="guests,users,anonymous" write="guests,users,anonymous" admin="guests,users,anonymous"/>
</authorizationEntries>
</authorizationMap>
</map>
</authorizationPlugin>
[root@localhost ~] vi /etc/hosts
添加如下:
主机IP ** **主机名(通过hostname可以得到)