ActiveMQ Master/Slave master-slave configuration

ActiveMQ master-slave configuration

@author:wushuang

Database version: MySQL 5.7

Operating System: CentOS Linux 7

ActiveMQ version: apache-activemq-5.14.3

I. Introduction

The official website introduces that ActiveMQ has three ways to implement Master/Slave, namely Shared File System Master Slave, JDBC Master Slave, and Replicated LevelDB Store. Among them, the Shared File System Master Slave needs to build a shared file system. It is troublesome to check the implementation, so I give up; the Replicated LevelDB Store has been officially abandoned and removed, and only version 5.9.0 is available; therefore, the JDBC Master Slave mode is used for ActiveMQ master-slave configuration.

The link is: http://activemq.apache.org/masterslave.html



2. Installation

1.vmware creates two new virtual machines, the system I installed is CentOS 7.

2. Install JDK and use openjdk1.8.

3. Download ActiveMQ from the official website and extract it to the specified path of the two virtual machines.

Specific installation instructions can be found on the official website: http://activemq.apache.org/getting-started.html

3. Install the database

JDBC Master Slave supports a variety of databases, this example uses MySQL.

Machine performance is limited, so install MySQL on one of the virtual machines. Production ActiveMQ and MySQL should not be installed on the same machine.

1. After the installation is complete, log in to MySQL and create a user manager whose password is also manager:

CREATE USER manager@'%' identified by 'manager';

2. Create database activemq: CREATE DATABASE activemq;

3. Authorize the manager to have all operation permissions on the database activemq:

GRANT ALL on activemq.* TO manager@'%' identified by 'manager';

4. Refresh permissions: FLUSH PRIVILEGES;

 

4. Configure Master/Slave

1. Open [activemq_install_dir]/conf/activemq.xml in one of the virtual machines, and add the data source bean after </broker>. I use c3p0:


 

2. Modify the content of persistenceAdapter as shown below:



 

Among them, createTablesOnStartup is true when it is started for the first time, and needs to be set to false later, so there is no need to create a table every time it is started.

3. Copy the activemq.xml to the same path of ActiveMQ of another virtual machine, overwrite the original configuration file, and modify the IP of jdbcUrl to the IP of the previous machine.

4. Download mchange-commons-java-0.2.10.jar, c3p0-0.9.5.1.jar, mysql-connector-java-5.1.38.jar, and copy these three jars to the lib under ActiveMQ on the two machines directory ([activemq_install_dir]/lib).

5. Start ActiveMQ of one of the virtual machines, this MQ becomes the Master, and three new tables will be automatically created in the database activemq:

ACTIVEMQ_ACKS、ACTIVEMQ_LOCK、ACTIVEMQ_MSGS

6. Start the ActiveMQ of another virtual machine, this MQ becomes a Slave, and regularly obtains the exclusive lock of the Master, as shown in the figure:



 

7. At this time, close the master ActiveMQ, then the slave ActiveMQ acquires the exclusive lock and becomes the master, as shown in the figure:



 

8. Open the ActiveMQ that was just closed again, then this MQ becomes a Slave, and it still regularly tries to obtain the exclusive lock of the master, as shown in the figure:



 

 

5. Remarks

1. High availability of ActiveMQ can be achieved through JDBC Master Slave, but the pressure is concentrated on the database, so the database is the main performance bottleneck.

2. In this example, there is only one instance of MySql. If MySQL hangs, ActiveMQ cannot be used. Therefore, the production environment also needs to avoid the single point of failure of MySQL, and use clustering or active-standby switching to avoid this situation.

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326814277&siteId=291194637
Recommended