ActiveMQ 是Apache出品,最流行的,能力强劲的开源消息总线。ActiveMQ 是一个完全支持JMS1.1和J2EE 1.4规范的 JMS Provider实现,尽管JMS规范出台已经是很久的事情了,但是JMS在当今的J2EE应用中间仍然扮演着特殊的地位.
安装如果出现如下错误:
#error “Newer version of jemalloc required”
make MALLOC=libc #增加这个
make install
修改redis.conf文件
daemonize yes
appendonly yes
logfile
apache-activemq- install
配置java环境:
wget https://archive.apache.org/dist/activemq/5.13.0/apache-activemq-5.13.0-bin.tar.gz .
tar –zxvf apache-activemq-5.13.0-bin.tar.gz
/home/app/apache-activemq-5.13.0/bin
./activemq start #start
./activemq stop #stop
三种运行方式:
(1)普通启动 ./activemq start
(2)启动并指定日志文件 ./activemq start >tmp/smlog
(3)后台启动方式nohup ./activemq start >/tmp/smlog
访问测试:
http://10.1.36.138:8161/admin/
默认密码:
user/pass: admin/admin
http://www.cnblogs.com/gossip/p/5969925.html
/sbin/iptables -I INPUT -p tcp –dport 8161 -j ACCEPT&&/etc/init.d/iptables save&&service iptables restart&&/etc/init.d/iptables status
/sbin/iptables -I INPUT -p tcp –dport 61616 -j ACCEPT&&/etc/init.d/iptables save&&service iptables restart&&/etc/init.d/iptables status
http://activemq.apache.org/overview.html
修改密码:
http://www.open-open.com/lib/view/open1454215248933.html
配置web管理页面的安全认证
默认的web页面用户名密码admin:admin,非常不安全,
编辑jetty-realm.properties文件,(用户:密码,组)
admin: admin123, admin
user: user123, user
配置web管理页面的绑定IP和端口
编辑jetty.xml,查找WebConsolePort
<bean id=”jettyPort” class=”org.apache.activemq.web.WebConsolePort” init-method=”start”>
<!– the default port number for the web console –>
<property name=”host” value=”192.168.0.31″/>
<property name=”port” value=”8161″/>
</bean>
配置MQ连接的安全认证
编辑activemq.xml,在<broker>下加
<plugins>
<simpleAuthenticationPlugin>
<users>
<authenticationUser username=”user” password=”user123″ groups=”users” />
</users>
</simpleAuthenticationPlugin>
</plugins>
禁用不使用的连接协议
编辑activemq.xml,在<transportConnectors>中注销或删除不使用的<transportConnector>
<transportConnectors>
<!– DOS protection, limit concurrent connections to 1000 and frame size to 100MB –>
<transportConnector name=”openwire” uri=”tcp://0.0.0.0:61616?maximumConnections=1000&wireFormat.maxFrameSize=104857600″/>
<!–<transportConnector name=”amqp” uri=”amqp://0.0.0.0:5672?maximumConnections=1000&wireFormat.maxFrameSize=104857600″/>
<transportConnector name=”stomp” uri=”stomp://0.0.0.0:61613?maximumConnections=1000&wireFormat.maxFrameSize=104857600″/>
<transportConnector name=”mqtt” uri=”mqtt://0.0.0.0:1883?maximumConnections=1000&wireFormat.maxFrameSize=104857600″/>
<transportConnector name=”ws” uri=”ws://0.0.0.0:61614?maximumConnections=1000&wireFormat.maxFrameSize=104857600″/>–>
</transportConnectors>
上面我只保留了61616的openwire协议端口
绑定协议连接端口到指定IP
编辑activemq.xml,在<transportConnectors>下找到指定协议的配置,并修改0.0.0.0为要绑定的ip
<transportConnector name=”openwire” uri=”tcp://192.168.0.10:61616?maximumConnections=1000&wireFormat.maxFrameSize=104857600″/>
使用MySql作为持久化保存
编辑activemq.xml,在<beans>下插入如下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.0.20/activemq?relaxAutoCommit=true” />
<property name=”username” value=”activemq” />
<property name=”password” value=”123456″ />
<property name=”poolPreparedStatements” value=”true” />
</bean>
删除或注销掉<persistenceAdapter>下的<kahaD>,添加<jdbcPersistenceAdapter>
<persistenceAdapter>
<!–<kahaDB directory=”${activemq.data}/kahadb”/>–>
<jdbcPersistenceAdapter dataDirectory=”activemq-data” dataSource=”#mysql-ds”/>
</persistenceAdapter>
配置基于JDBC的高可用环境
两个以上activemq使用一样的db配置,
客户端连接url为failover:(tcp://broker1:61616,tcp://broker2:61616)
修改内存
linux下,修改bin/env的ACTIVEMQ_OPTS_MEMORY属性,Xms=最小内存,Xmx=最大内存
ACTIVEMQ_OPTS_MEMORY=”-Xms64M -Xmx1G”
window下,修改activemq.bat,在 if “%ACTIVEMQ_OPTS%” == ” 前设置
set ACTIVEMQ_OPTS=-Xms1G -Xmx1G
注册为Service
linux(RedHat,Centos)下(官方参考文档),运行以下命令注册为service,并设置为开机自动启动
ln -snf bin/activemq /etc/init.d/activemqchkconfig –add activemqchkconfig activemq on
然后就可以使用如下service命令了
service activemq start|stop|status|restart