Difference between revisions of "JMS server: ActiveMQ"
(6 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
+ | [[Category:Linux]] | ||
+ | [[Category:Development]] | ||
+ | |||
=Manual installation= | =Manual installation= | ||
Line 114: | Line 117: | ||
<syntaxhighlight lang="bash"> | <syntaxhighlight lang="bash"> | ||
− | # INPUT | + | #### INPUT |
− | $IPTABLES -A INPUT -p tcp -m state --state NEW --dport 5672 -j ACCEPT | + | # messages |
− | $IPTABLES -A INPUT -p tcp -m state --state NEW --dport 8161 -j ACCEPT | + | $IPTABLES -A INPUT -p tcp -m state --state NEW --dport 5672 -j ACCEPT # AMQP port |
− | $IPTABLES -A INPUT -p tcp -m state --state NEW --dport 8162 -j ACCEPT | + | $IPTABLES -A INPUT -p tcp -m state --state NEW --dport 61616 -j ACCEPT # JMS port |
− | $IPTABLES -A INPUT -p tcp -m state --state NEW --dport | + | |
− | $IPTABLES -A INPUT -p tcp -m state --state NEW --dport | + | # web monitoring |
+ | #$IPTABLES -A INPUT -p tcp -m state --state NEW --dport 8161 -j ACCEPT # HTTP web-console. Not required if you're using Apache2 proxy | ||
+ | #$IPTABLES -A INPUT -p tcp -m state --state NEW --dport 8162 -j ACCEPT # HTTPs web-console. Not required if you're using Apache2 proxy | ||
+ | |||
+ | # JMX monitoring | ||
+ | $IPTABLES -A INPUT -p tcp -m state --state NEW --dport 1099 -j ACCEPT # JVM default RMI port | ||
+ | #$IPTABLES -A INPUT -p tcp -m state --state NEW --dport 11099 -j ACCEPT # JMX standalone port. Not required if you're using default JVM JMX connector on TCP 1616 | ||
# Output | # Output | ||
$IPTABLES -A OUTPUT -p tcp -m state --state NEW --dport 5672 -j ACCEPT | $IPTABLES -A OUTPUT -p tcp -m state --state NEW --dport 5672 -j ACCEPT | ||
+ | $IPTABLES -A OUTPUT -p tcp -m state --state NEW --dport 61616 -j ACCEPT | ||
+ | |||
$IPTABLES -A OUTPUT -p tcp -m state --state NEW --dport 8161 -j ACCEPT | $IPTABLES -A OUTPUT -p tcp -m state --state NEW --dport 8161 -j ACCEPT | ||
$IPTABLES -A OUTPUT -p tcp -m state --state NEW --dport 8162 -j ACCEPT | $IPTABLES -A OUTPUT -p tcp -m state --state NEW --dport 8162 -j ACCEPT | ||
+ | |||
+ | $IPTABLES -A OUTPUT -p tcp -m state --state NEW --dport 1099 -j ACCEPT | ||
$IPTABLES -A OUTPUT -p tcp -m state --state NEW --dport 11099 -j ACCEPT | $IPTABLES -A OUTPUT -p tcp -m state --state NEW --dport 11099 -j ACCEPT | ||
− | |||
</syntaxhighlight> | </syntaxhighlight> | ||
+ | |||
+ | |||
+ | |||
+ | = Logs = | ||
+ | |||
+ | The application's logs are in $ACTIVEMQ/data/activemq.log | ||
+ | |||
+ | <syntaxhighlight lang="bash"> | ||
+ | cat /opt/activemq/data/activemq.log | ||
+ | </syntaxhighlight> | ||
+ | |||
Line 212: | Line 235: | ||
Edit "jetty.xml" [look to the previous §] | Edit "jetty.xml" [look to the previous §] | ||
− | Add | + | Add 2 new ''securityConstraintMapping'' (line 40), " /activemq/*,/activemq-api/*, " |
<syntaxhighlight lang="xml"> | <syntaxhighlight lang="xml"> | ||
<bean id="securityConstraintMapping" class="org.eclipse.jetty.security.ConstraintMapping"> | <bean id="securityConstraintMapping" class="org.eclipse.jetty.security.ConstraintMapping"> | ||
Line 221: | Line 244: | ||
− | Change | + | Change: |
+ | * ''WebAppContext.contextpath'' value to " /activemq " instead of " /admin " | ||
+ | * ''WebAppContext.contextpath'' value to " /activemq-api " instead of " /api " | ||
+ | |||
<syntaxhighlight lang="xml"> | <syntaxhighlight lang="xml"> | ||
<property name="handler"> | <property name="handler"> | ||
Line 233: | Line 259: | ||
<property name="logUrlOnStart" value="true" /> | <property name="logUrlOnStart" value="true" /> | ||
</bean> | </bean> | ||
− | + | ... | |
+ | <bean class="org.eclipse.jetty.webapp.WebAppContext"> | ||
+ | <property name="contextPath" value="/activemq-api" /> | ||
+ | <property name="resourceBase" value="${activemq.home}/webapps/api" /> | ||
+ | <property name="logUrlOnStart" value="true" /> | ||
+ | </bean> | ||
... | ... | ||
</syntaxhighlight> | </syntaxhighlight> | ||
Line 250: | Line 281: | ||
− | ===Apache 2 | + | ===Apache 2 Virtual host and mod_proxy=== |
− | + | Instead of using the port 8161, you can use Apache 2 mod_proxy. | |
− | + | !!CAREFUL!! '''You must let the HTTP access to the REST API'''. | |
+ | |||
+ | Apache2 Virtual Host configuration: | ||
+ | <syntaxhighlight lang="xml"> | ||
+ | <VirtualHost *:80> | ||
+ | ServerAdmin guillaume.diaz@vehco.com | ||
+ | ServerName preprodrtd.vehco.com | ||
+ | |||
+ | ## Proxy | ||
+ | ProxyVia On | ||
+ | ProxyPreserveHost On | ||
+ | <Proxy *> | ||
+ | AddDefaultCharset off | ||
+ | Order deny,allow | ||
+ | Allow from all | ||
+ | </Proxy> | ||
+ | |||
+ | # Active MQ REST web-service, required for hawt.io management | ||
+ | ProxyPass /activemq-api http://localhost:8161/activemq-api | ||
+ | ProxyPassReverse /activemq-api http://localhost:8161/activemq-api | ||
+ | |||
+ | # Redirect everything else to HTTPS | ||
+ | Redirect permanent / https://preprodrtd.vehco.com/ | ||
+ | </VirtualHost> | ||
+ | |||
+ | <VirtualHost *:443> | ||
+ | ... | ||
+ | ## Proxy | ||
+ | ProxyVia On | ||
+ | ProxyPreserveHost On | ||
+ | <Proxy *> | ||
+ | AddDefaultCharset off | ||
+ | Order deny,allow | ||
+ | Allow from all | ||
+ | Satisfy Any | ||
+ | </Proxy> | ||
+ | |||
+ | |||
+ | # ActiveMq HTTP web-console | ||
+ | ProxyPass /activemq http://localhost:8161/activemq | ||
+ | ProxyPassReverse /activemq http://localhost:8161/activemq | ||
+ | |||
+ | # ActiveMq REST web-services, required for hawt.io | ||
+ | ProxyPass /activemq-api http://localhost:8161/activemq-api | ||
+ | ProxyPassReverse /activemq-api http://localhost:8161/activemq-api | ||
+ | </VirtualHost> | ||
+ | </syntaxhighlight> | ||
+ | |||
+ | |||
+ | ===Remote management using HAWT.IO=== | ||
+ | Hawt.io is a wonderful management tool. You can use it to manage a lot of JAVA services, including ActiveMQ ; JMX ; etc. | ||
+ | |||
+ | |||
+ | Official website: http://hawt.io/ | ||
+ | * Download URL: http://hawt.io/getstarted/index.html > You should download the ''hwatio.jar'' file | ||
+ | |||
+ | |||
+ | To execute the program, just run: | ||
<syntaxhighlight lang="bash"> | <syntaxhighlight lang="bash"> | ||
− | + | java -jar hawtio-app-1.3.1.jar --port 8090 | |
− | |||
</syntaxhighlight> | </syntaxhighlight> | ||
+ | Don't hesitate to adjust the port number to your own needs! Default is 8080, which might already been used by Tomcat or Glassfish. | ||
+ | |||
+ | Go to http://localhost:8090/hawtio | ||
+ | |||
+ | |||
+ | Then, configure the following remote connection: | ||
+ | [[File:Hawt.io_ActiveMQ.png|none|Margins]] | ||
+ | Enjoy ActiveMQ ! | ||
=Enable JMX remote management and monitoring= | =Enable JMX remote management and monitoring= | ||
Line 281: | Line 376: | ||
− | Make sure that you're using | + | Make sure that you're using a new JVM connector (line 65): |
<syntaxhighlight lang="xml"> | <syntaxhighlight lang="xml"> | ||
<broker xmlns="http://activemq.apache.org/schema/core" useJmx="true" brokerName="preprodrtd.vehco.com" dataDirectory="${activemq.data}"> | <broker xmlns="http://activemq.apache.org/schema/core" useJmx="true" brokerName="preprodrtd.vehco.com" dataDirectory="${activemq.data}"> | ||
... | ... | ||
<managementContext> | <managementContext> | ||
− | <managementContext createConnector=" | + | <managementContext createConnector="true" /> |
</managementContext> | </managementContext> | ||
... | ... | ||
Line 329: | Line 424: | ||
<syntaxhighlight lang="bash"> | <syntaxhighlight lang="bash"> | ||
# ACTIVEMQ_SUNJMX_START="-Dcom.sun.management.jmxremote.port=11099 " | # ACTIVEMQ_SUNJMX_START="-Dcom.sun.management.jmxremote.port=11099 " | ||
− | ACTIVEMQ_SUNJMX_START="-Dcom.sun.management.jmxremote.port= | + | ACTIVEMQ_SUNJMX_START="-Dcom.sun.management.jmxremote.rmi.port=1099 " |
ACTIVEMQ_SUNJMX_START="$ACTIVEMQ_SUNJMX_START -Dcom.sun.management.jmxremote.password.file=${ACTIVEMQ_CONF}/jmx.password" | ACTIVEMQ_SUNJMX_START="$ACTIVEMQ_SUNJMX_START -Dcom.sun.management.jmxremote.password.file=${ACTIVEMQ_CONF}/jmx.password" | ||
ACTIVEMQ_SUNJMX_START="$ACTIVEMQ_SUNJMX_START -Dcom.sun.management.jmxremote.access.file=${ACTIVEMQ_CONF}/jmx.access" | ACTIVEMQ_SUNJMX_START="$ACTIVEMQ_SUNJMX_START -Dcom.sun.management.jmxremote.access.file=${ACTIVEMQ_CONF}/jmx.access" | ||
Line 336: | Line 431: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
− | !! Note that the | + | !! Note that the '''default JVM RMI port''' will be used [TCP 1099] instead of the standalone one. !! |
+ | |||
+ | |||
+ | No you can access the console remotely using Jconsole or any other client. | ||
+ | |||
+ | URL: service:jmx:rmi:///jndi/rmi://'''<your hostname>''':1099/jmxrmi | ||
+ | |||
+ | |||
+ | ==JMX client== | ||
+ | |||
+ | ===Jconsole=== | ||
+ | |||
+ | You can use JConsole (included in Java JDK) to access the server. | ||
+ | |||
+ | |||
+ | ===ActiveMQ Browser (windows)=== | ||
+ | |||
+ | * Download the latest version of the application: http://sourceforge.net/projects/activemqbrowser/ | ||
+ | |||
+ | * Unzip the file and put it in " /opt/activemq-browser " | ||
+ | |||
+ | * just run the .bat file | ||
Latest revision as of 17:18, 10 June 2014
Contents
Manual installation
Installation
Get Apache Active MQ
Get the latest binary version from: http://activemq.apache.org/download.html
Program setup
- Copy archive to /opt/ directory:
mv apache-activemq-5.9.1-bin.zip /opt/
cd /opt/
- Unzip and create simlink
unzip apache-activemq-5.9.1-bin.zip
ln -s /opt/apache-activemq-5.9.1/ /opt/activemq/
- Set executable flag and symlinks
chmod 755 /opt/activemq/bin/activemq
ln -s /opt/activemq/bin/activemq /usr/bin/activemq
ln -s /opt/activemq/bin/activemq /etc/init.d/activemq
Rights adjustments
- Add non privileged account
adduser -system activemq
addgroup -system activemq
- Adjust user shell
Edit:
vim /etc/passwd
Adjust the user SHELL
activemq:x:116:65534::/home/activemq:/bin/bash
- Adjust user group
Edit:
vim /etc/group
Adjust the group membership
activemq:x:1001:activemq
- Set MQ folder privileges
chown -R activemq:activemq /opt/apache-activemq-5.9.1/
chown -R activemq:activemq /opt/activemq/
Basic configuration
Home + User
- Set home and user
Edit
vim /opt/activemq/bin/activemq
Set after "Configuration" (line ~ 40)
ACTIVEMQ_HOME=”/opt/activemq”
ACTIVEMQ_USER=”activemq”
Runtime configuration
- Create runtime configuration. Generate default settings
/opt/activemq/bin/activemq setup /etc/default/activemq
- Adjust configuration rights
chown root:nogroup /etc/default/activemq
chmod 600 /etc/default/activemq
Add ActiveMQ to boot sequence
cd /etc/init.d
update-rc.d activemq defaults
Remove ActiveMq from boot sequence
update-rc.d -f activemq remove
rm /etc/init.d/activemq
Setup firewall
This is the list of ports that are used by ActiveMQ:
- port 61616 = JMS queue access
- port 11099 = JMX remote console (connector port)
- port 8161 = HTTP manager
- port 8162 = HTTPS manager
- port 5672 = AMQP port
Edit your firewall script:
vim /etc/firewall/firewall-start.sh
#### INPUT
# messages
$IPTABLES -A INPUT -p tcp -m state --state NEW --dport 5672 -j ACCEPT # AMQP port
$IPTABLES -A INPUT -p tcp -m state --state NEW --dport 61616 -j ACCEPT # JMS port
# web monitoring
#$IPTABLES -A INPUT -p tcp -m state --state NEW --dport 8161 -j ACCEPT # HTTP web-console. Not required if you're using Apache2 proxy
#$IPTABLES -A INPUT -p tcp -m state --state NEW --dport 8162 -j ACCEPT # HTTPs web-console. Not required if you're using Apache2 proxy
# JMX monitoring
$IPTABLES -A INPUT -p tcp -m state --state NEW --dport 1099 -j ACCEPT # JVM default RMI port
#$IPTABLES -A INPUT -p tcp -m state --state NEW --dport 11099 -j ACCEPT # JMX standalone port. Not required if you're using default JVM JMX connector on TCP 1616
# Output
$IPTABLES -A OUTPUT -p tcp -m state --state NEW --dport 5672 -j ACCEPT
$IPTABLES -A OUTPUT -p tcp -m state --state NEW --dport 61616 -j ACCEPT
$IPTABLES -A OUTPUT -p tcp -m state --state NEW --dport 8161 -j ACCEPT
$IPTABLES -A OUTPUT -p tcp -m state --state NEW --dport 8162 -j ACCEPT
$IPTABLES -A OUTPUT -p tcp -m state --state NEW --dport 1099 -j ACCEPT
$IPTABLES -A OUTPUT -p tcp -m state --state NEW --dport 11099 -j ACCEPT
Logs
The application's logs are in $ACTIVEMQ/data/activemq.log
cat /opt/activemq/data/activemq.log
Advanced Configuration (all O.S)
Broker settings
Edit configuration file
- Linux ~ manual
vim /opt/activemq/conf/activemq.xml
- Linux ~ auto
vim /etc/activemq/instances-enabled/main/activemq.xml
- Windows
$ACTIVEMQ/conf/activemq.xml
Adjust broker setting
- Set broker name
<broker xmlns="http://activemq.apache.org/schema/core"
brokerName="myServerName"
dataDirectory="${activemq.base}/data">
- Set listener to all interfaces (0.0.0.0)
<transportConnectors>
<transportConnector name="openwire" uri="tcp://0.0.0.0:61616"/>
</transportConnectors>
- Limit queues size
<systemUsage>
<systemUsage>
<memoryUsage>
<memoryUsage limit="64 mb"/>
</memoryUsage>
<storeUsage>
<storeUsage limit="100 gb"/>
</storeUsage>
<tempUsage>
<tempUsage limit="50 gb"/>
</tempUsage>
</systemUsage>
</systemUsage>
Enable HTTP web console
Edit your jetty configuration
Linux ~ Manual
vim /opt/activemq/conf/jetty.xml
- Windows
$ACTIVEMQ/conf/jetty.xml
Adjust broker name and listening port
At the bottom, edit connector :
<property name="connectors">
<list>
<bean id="Connector" class="org.eclipse.jetty.server.nio.SelectChannelConnector">
<property name="port" value="8161" />
<property name="host" value="0.0.0.0" />
</bean>
...
</list>
</property>
Change root context for Web-Console
Edit "jetty.xml" [look to the previous §]
Add 2 new securityConstraintMapping (line 40), " /activemq/*,/activemq-api/*, "
<bean id="securityConstraintMapping" class="org.eclipse.jetty.security.ConstraintMapping">
<property name="constraint" ref="securityConstraint" />
<property name="pathSpec" value="/api/*,/activemq/*,/admin/*,*.jsp" />
</bean>
Change:
- WebAppContext.contextpath value to " /activemq " instead of " /admin "
- WebAppContext.contextpath value to " /activemq-api " instead of " /api "
<property name="handler">
<bean id="sec" class="org.eclipse.jetty.server.handler.HandlerCollection">
<property name="handlers">
<list>
<bean class="org.eclipse.jetty.webapp.WebAppContext">
<!-- property name="contextPath" value="/admin" / -->
<property name="contextPath" value="/activemq" />
<property name="resourceBase" value="${activemq.home}/webapps/admin" />
<property name="logUrlOnStart" value="true" />
</bean>
...
<bean class="org.eclipse.jetty.webapp.WebAppContext">
<property name="contextPath" value="/activemq-api" />
<property name="resourceBase" value="${activemq.home}/webapps/api" />
<property name="logUrlOnStart" value="true" />
</bean>
...
Manage web-users
vim /opt/activemq/conf/jetty-realm.properties
Edit last line
admin: admin, admin
Apache 2 Virtual host and mod_proxy
Instead of using the port 8161, you can use Apache 2 mod_proxy.
!!CAREFUL!! You must let the HTTP access to the REST API.
Apache2 Virtual Host configuration:
<VirtualHost *:80>
ServerAdmin guillaume.diaz@vehco.com
ServerName preprodrtd.vehco.com
## Proxy
ProxyVia On
ProxyPreserveHost On
<Proxy *>
AddDefaultCharset off
Order deny,allow
Allow from all
</Proxy>
# Active MQ REST web-service, required for hawt.io management
ProxyPass /activemq-api http://localhost:8161/activemq-api
ProxyPassReverse /activemq-api http://localhost:8161/activemq-api
# Redirect everything else to HTTPS
Redirect permanent / https://preprodrtd.vehco.com/
</VirtualHost>
<VirtualHost *:443>
...
## Proxy
ProxyVia On
ProxyPreserveHost On
<Proxy *>
AddDefaultCharset off
Order deny,allow
Allow from all
Satisfy Any
</Proxy>
# ActiveMq HTTP web-console
ProxyPass /activemq http://localhost:8161/activemq
ProxyPassReverse /activemq http://localhost:8161/activemq
# ActiveMq REST web-services, required for hawt.io
ProxyPass /activemq-api http://localhost:8161/activemq-api
ProxyPassReverse /activemq-api http://localhost:8161/activemq-api
</VirtualHost>
Remote management using HAWT.IO
Hawt.io is a wonderful management tool. You can use it to manage a lot of JAVA services, including ActiveMQ ; JMX ; etc.
Official website: http://hawt.io/
- Download URL: http://hawt.io/getstarted/index.html > You should download the hwatio.jar file
To execute the program, just run:
java -jar hawtio-app-1.3.1.jar --port 8090
Don't hesitate to adjust the port number to your own needs! Default is 8080, which might already been used by Tomcat or Glassfish.
Go to http://localhost:8090/hawtio
Then, configure the following remote connection:
Enjoy ActiveMQ !
Enable JMX remote management and monitoring
Official documentation: http://activemq.apache.org/jmx.html
Add JMX support
Edit configuration:
vim /opt/activemq/conf/activemq.xml
Adjust the broker tag (line 35), add useJmx="true"
<broker xmlns="http://activemq.apache.org/schema/core" useJmx="true" brokerName="preprodrtd.vehco.com" dataDirectory="${activemq.data}">
...
</broker>
Make sure that you're using a new JVM connector (line 65):
<broker xmlns="http://activemq.apache.org/schema/core" useJmx="true" brokerName="preprodrtd.vehco.com" dataDirectory="${activemq.data}">
...
<managementContext>
<managementContext createConnector="true" />
</managementContext>
...
</broker>
Create JMX users
- User creation
vim /opt/activemq/conf/jmx.access
Add some users. As a reminder:
userMq readonly
adminMq readwrite
- User password
vim /opt/activemq/conf/jmx.password
Set passwords. Usernames must match!
userMq abc123
adminMq abcd1234
JMX settings
Edit activemq launcher
vim /opt/activemq/bin/activemq
Search for ACTIVEMQ_JMX and adjust the lines to:
# ACTIVEMQ_SUNJMX_START="-Dcom.sun.management.jmxremote.port=11099 "
ACTIVEMQ_SUNJMX_START="-Dcom.sun.management.jmxremote.rmi.port=1099 "
ACTIVEMQ_SUNJMX_START="$ACTIVEMQ_SUNJMX_START -Dcom.sun.management.jmxremote.password.file=${ACTIVEMQ_CONF}/jmx.password"
ACTIVEMQ_SUNJMX_START="$ACTIVEMQ_SUNJMX_START -Dcom.sun.management.jmxremote.access.file=${ACTIVEMQ_CONF}/jmx.access"
ACTIVEMQ_SUNJMX_START="$ACTIVEMQ_SUNJMX_START -Dcom.sun.management.jmxremote.ssl=false"
ACTIVEMQ_SUNJMX_START="$ACTIVEMQ_SUNJMX_START -Dcom.sun.management.jmxremote"
!! Note that the default JVM RMI port will be used [TCP 1099] instead of the standalone one. !!
No you can access the console remotely using Jconsole or any other client.
URL: service:jmx:rmi:///jndi/rmi://<your hostname>:1099/jmxrmi
JMX client
Jconsole
You can use JConsole (included in Java JDK) to access the server.
ActiveMQ Browser (windows)
- Download the latest version of the application: http://sourceforge.net/projects/activemqbrowser/
- Unzip the file and put it in " /opt/activemq-browser "
- just run the .bat file
Automatic installation
!! Depending on your distro, you might not have the web console !! This is NOT recommended.
Get binary
apt-get install activemq
Enable instance
- Check instance
cd /etc/activemq/instances-enabled/
ls
... By default you should have an instance enable.
If not:
ln -s /etc/activemq/instances-available/main /etc/activemq/instances-enabled/main
cp /usr/share/activemq/activemq-options /etc/activemq/instances-available/main/options
- Edit settings
vim /etc/activemq/instances-available/main/options
- Adjust $INSTANCE (use 'main')
ACTIVEMQ_BASE="/var/lib/activemq/main"
Create directories
mkdir -p /var/lib/activemq/main/data
mkdir -p /var/lib/activemq/main/data/kahadb
chown -R activemq:activemq /var/lib/activemq/main
chmod -R 755 /var/lib/activemq/main
Kahadb == MQ embedded DB