ActiveMQ and Tomcat Setup
- Launch Instance with Volumes
- Launch an EC2 instance with two EBS volumes.
- Mount the secondary volume to
/opt
. - Install ActiveMQ and mysql-connector
- Download the ActiveMQ package from the official website:
wget https://www.apache.org/dyn/closer.cgi?filename=/activemq/6.1.3/apache-activemq-6.1.3-bin.tar.gz&action=download
- Extract the tar file into the
/opt
directory: tar -xzf apache-activemq-6.1.3-bin.tar.gz -C /opt
- Extract the tar file into the
- Download the mysql-connector and extract it. wget https://dev.mysql.com/get/Downloads/Connector-J/mysql-connector-j-9.0.0.tar.gz tar -xzvf mysql-connector-j-9.0.0.tar.gz
- Configure ActiveMQ
- Update the ActiveMQ configuration file:
vim /opt/apache-activemq-6.1.3/conf/activemq.xml
- Modify the following: • Change the broker name • Change the PersistenceAdapter block with jdbc to use mysql as its database. • Remove all the transportConnector expect the openwire.
• Add this lines at the end of file before
- Update Jetty Configuration
- Edit the Jetty configuration file and modify the host as follows: vim /opt/apache-activemq-6.1.3/conf/jetty.xml
- Change the line:
- Create ActiveMQ Service
- Create a systemd service file for ActiveMQ: vim /etc/systemd/system/activemq.service
- Content of the service file: [Unit] Description=Apache ActiveMQ Message Broker After=network-online.target
[Service]
Type=forking
User=activemq
Group=activemq
WorkingDirectory=/opt/apache-activemq-6.1.3/bin
ExecStart=/opt/apache-activemq-6.1.3/bin/activemq start
ExecStop=/opt/apache-activemq-6.1.3/bin/activemq stop
Restart=on-abort
[Install]
WantedBy=multi-user.target
- Enable and start the ActiveMQ service:
systemctl enable activemq.service
systemctl start activemq.service
- Install Java
- Install Java 22 and Java 8: yum install java java-1.8.0 -y
- Create a symbolic link for Java 8:
ln -s /usr/lib/jvm/java-1.8.0-amazon-corretto.aarch64/jre/bin/java /usr/bin/java8
- Install Tomcat 9
- Download Tomcat 9 from the official website: wget https://dlcdn.apache.org/tomcat/tomcat-9/v9.0.93/bin/apache-tomcat-9.0.93.tar.gz
- Extract the tar file into the
/opt
directory: tar -xzf apache-tomcat-9.0.93.tar.gz -C /opt- Rename the extracted directory: mv /opt/apache-tomcat-9.0.93 /opt/notification_tomcat
- Configure Tomcat
- Edit the
catalina.sh
file: vim /opt/notification_tomcat/bin/catalina.sh - Add the following configuration: JAVA_HOME="/usr/lib/jvm/java-1.8.0-amazon-corretto.aarch64/jre/" CATALINA_OPTS="-Xmx512m -Xss256m -Xms256m -XX:PermSize=256m -XX:MaxPermSize=512m -XX:NewSize=128m" JAVA_OPTS="$JVM_OPTS -Dproperties.filepath=$CATALINA_BASE/conf/learningPlatform.properties -Dexclusion.properties=$CATALINA_BASE/conf/exclusion.properties" CATALINA_OPTS="$CATALINA_OPTS -Dinstance_base=$CATALINA_BASE -Dfile.encoding=UTF-8"
- Clean Up Tomcat
- Delete the existing files from the
webapps
directory: rm -rf /opt/notification_tomcat/webapps/* - Migrate Application
- Copy the
notification-consumer
directory from the old server to the new server'swebapps
directory. - Update Configuration Files
- Add the
learningPlatform.properties
andexclusion.properties
files in theconf
directory: vim /opt/notification_tomcat/conf/learningPlatform.properties #Notification Consumer will connect to the below ActiveMQ notification.broker.url=failover:(tcp://test-activemq1.loudcloudsystems.com:61612,tcp://test-activemq2.loudcloudsystems.com:61612)?initialReconnectDelay=100
- Delete the existing files from the
vim /opt/notification_tomcat/conf/exclusion.properties
to=@gail.com,@fake.com,@v.l,@qq.com
- Create Tomcat Service
- Create a systemd service file for Tomcat:
vim /etc/systemd/system/tc_notification.service
- Content of the service file: [Unit] Description=Apache Tomcat 9 Web Application Server After=network.target
[Service]
Type=forking
Environment="JAVA_HOME=/usr/bin/java8"
Environment="CATALINA_PID=/opt/notification_tomcat/temp/tomcat.pid"
Environment="CATALINA_HOME=/opt/notification_tomcat"
Environment="CATALINA_OPTS=-Xms512M -Xmx1024M -server -XX:+UseParallelGC"
ExecStart=/opt/notification_tomcat/bin/startup.sh
ExecStop=/opt/notification_tomcat/bin/shutdown.sh
User=root
Group=root
RestartSec=10
Restart=always
[Install]
WantedBy=multi-user.target
- Enable and start the Tomcat service: systemctl enable tc_notification.service systemctl start tc_notification.service
- Verify Setup
- Once both services are active, verify the ActiveMQ setup by accessing the web interface: http://:8161
Top comments (0)