1.下载安装ActiveMQ
下载地址:http://activemq.apache.org/download-archives.html选择相应的版本,笔者选择的是:apache-activemq-5.9.0-bin.tar.gz
解压文件:
[wch@localhost ActiveMQ]$ tar -zxvf apache-activemq-5.9.0-bin.tar.gz
进入解压后的目录apache-activemq-5.9.0,如下:
[wch@localhost ActiveMQ]$ cd apache-activemq-5.9.0
[wch@localhost apache-activemq-5.9.0]$ ll
total 9956
-rwxr-xr-x.1 wch wch 10105484Oct142013 activemq-all-5.9.0.jar
drwxrwxr-x.5 wch wch 4096Oct806:34 bin
drwxr-xr-x.2 wch wch 4096Oct806:34 conf
drwxr-xr-x.3 wch wch 4096Oct806:45 data
drwxr-xr-x.2 wch wch 4096Oct806:34 docs
drwxr-xr-x.8 wch wch 4096Oct806:34 examples
drwxr-xr-x.6 wch wch 4096Oct806:34 lib
-rw-r--r--.1 wch wch 40580Oct142013 LICENSE
-rw-r--r--.1 wch wch 3334Oct142013 NOTICE
-rw-r--r--.1 wch wch 2610Oct142013 README.txt
drwxrwxr-x.6 wch wch 4096Oct806:45 tmp
drwxr-xr-x.8 wch wch 4096Oct806:34 webapps
drwxrwxr-x.3 wch wch 4096Oct806:34 webapps-demo
- bin,放置启动、停止、注册服务等命令文件。
- conf,配置文件,包括broker、jetty、log等配置文件。
- data,放置消息缓存(kahadb)、jetty中jsp编译后的class、AMQ日志等文件。
- docs,帮助文档
- examples,应用示例
- lib,依赖的jar包
- webapps,AMQ下的web应用,包括web console 和 file server。
- webapps-demo,demo应用,默认不能访问,如需访问需要在conf/jetty.xml文件中配置。
- activemq-all-5.10.1.jar, AMQ的开发用的jar包
- 其它文件,包括license、notice和 readme
修改文件:apache-activemq-5.9.0/bin/activemq设置Java运行环境,如下:
# Location of the java installation
# Specify the location of your java installation using JAVA_HOME, or specify the
# path to the "java" binary using JAVACMD
# (set JAVACMD to "auto" for automatic detection)
#JAVA_HOME="" 此处可以设置JAVA_HOME
JAVACMD="auto"
2.启动ActiveMQ
1.activeMQ具有三种启动方式
(1)普通启动
./activemq start
(2)启动并指定日志文件
./activemq start /tmp/smlog
(3)后台启动方式
nohup ./activemq start /tmp/smlog
前两种方式下在命令行窗口关闭时或者ctrl+c时导致进程退出,采用后台启动方式则可以避免这种情况。
2.启动如下:
[wch@localhost bin]$ ./activemq start
INFO:Using default configuration
(you can configure options in one of these file:/etc/default/activemq /home/wch/.activemqrc)
INFO:Invoke the following command to create a configuration file
./activemq setup [/etc/default/activemq |/home/wch/.activemqrc ]
INFO:Using java '/usr/bin/java'
INFO:Starting- inspect logfiles specified in logging.properties and log4j.properties to get details
INFO: pidfile created :'/home/wch/SoftWare/ActiveMQ/apache-activemq-5.9.0/data/activemq-localhost.localdomain.pid'(pid '3658')
检查是否已启动:
[wch@localhost bin]$ ps -ef | grep java.*active.*
wch 39891507:42 pts/000:00:04/usr/bin/java -Xms1G-Xmx1G-Djava.util.logging.config.file=logging.properties -Dhawtio.realm=activemq -Dhawtio.role=admins -Dhawtio.rolePrincipalClasses=org.apache.activemq.jaas.GroupPrincipal-Djava.security.auth.login.config=/home/wch/SoftWare/ActiveMQ/apache-activemq-5.9.0/conf/login.config -Dcom.sun.management.jmxremote -Djava.awt.headless=true -Djava.io.tmpdir=/home/wch/SoftWare/ActiveMQ/apache-activemq-5.9.0/tmp -Dactivemq.classpath=/home/wch/SoftWare/ActiveMQ/apache-activemq-5.9.0/conf;-Dactivemq.home=/home/wch/SoftWare/ActiveMQ/apache-activemq-5.9.0-Dactivemq.base=/home/wch/SoftWare/ActiveMQ/apache-activemq-5.9.0-Dactivemq.conf=/home/wch/SoftWare/ActiveMQ/apache-activemq-5.9.0/conf -Dactivemq.data=/home/wch/SoftWare/ActiveMQ/apache-activemq-5.9.0/data -jar /home/wch/SoftWare/ActiveMQ/apache-activemq-5.9.0/bin/activemq.jar start
wch 40432490007:44 pts/000:00:00 grep java.*active.*
[wch@localhost bin]$
或者使用如下命令:
[wch@localhost bin]$ netstat -anlp | grep -E 'java'
(Not all processes could be identified, non-owned process info
will not be shown, you would have to be root to see it all.)
tcp 00:::61613:::* LISTEN 3989/java
tcp 00:::61614:::* LISTEN 3989/java
tcp 00:::61616:::* LISTEN 3989/java
tcp 00:::37712:::* LISTEN 3989/java
tcp 00:::1883:::* LISTEN 3989/java
tcp 00:::8161:::* LISTEN 3989/java
tcp 00:::5672:::* LISTEN 3989/java
unix 2[] STREAM CONNECTED 295113989/java
unix 2[] STREAM CONNECTED 295073989/java
ActiveMQ默认采用61616端口提供JMS服务,使用8161端口提供管理控制台服务。
3.使用浏览器登入ActiveMQ控制台
ActiveMQ控制台地址:http://192.168.110.100:8161/admin/ 使用默认的用户名密码(用户名:admin 密码:admin)登入,如下:
手动设置用户名密码,需要修改文件apache-activemq-5.9.0/conf/jetty-realm.properties,如下:
# Defines users that can access the web (console, demo, etc.)
# username: password [,rolename ...]
admin: admin, admin
user: user, user
3.简单配置
配置文件都在conf文件夹下,主要有activemq.xml、jetty.xml和log4j.properties。
1.配置broker的端口
修改activemq.xml中下面的端口号
<transportConnectors>
<!-- DOS protection, limit concurrent connections to 1000 and frame size to 100MB -->
<transportConnectorname="openwire"uri="tcp://0.0.0.0:61616?maximumConnections=1000&wireFormat.maxFrameSize=104857600"/>
<transportConnectorname="amqp"uri="amqp://0.0.0.0:5672?maximumConnections=1000&wireFormat.maxFrameSize=104857600"/>
<transportConnectorname="stomp"uri="stomp://0.0.0.0:61613?maximumConnections=1000&wireFormat.maxFrameSize=104857600"/>
<transportConnectorname="mqtt"uri="mqtt://0.0.0.0:1883?maximumConnections=1000&wireFormat.maxFrameSize=104857600"/>
<transportConnectorname="ws"uri="ws://0.0.0.0:61614?maximumConnections=1000&wireFormat.maxFrameSize=104857600"/>
</transportConnectors>
2.配置jetty的端口
修改jetty.xml中的下面内容。
<beanid="jettyPort"class="org.apache.activemq.web.WebConsolePort"init-method="start">
<!-- the default port number for the web console -->
<propertyname="host"value="0.0.0.0"/>
<propertyname="port"value="8161"/>
</bean>
3.配置启动demo工程
在jetty.xml中找到org.eclipse.jetty.webapp.WebAppContext,增加下面的内容。
<beanclass="org.eclipse.jetty.webapp.WebAppContext">
<propertyname="contextPath"value="/demo"/>
<propertyname="resourceBase"value="${activemq.home}/webapps-demo/demo"/>
<propertyname="logUrlOnStart"value="true"/>
</bean>
4.ActiveMQ架构图
-------------------------------------------------------------------------------------------------------------------------------