d

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore.

15 St Margarets, NY 10033
(+381) 11 123 4567
ouroffice@aware.com

 

KMF

The Best Way To Migrate a RabbitMQ Server

Introduction

As the userbase of my company increased over time, I realized it was necessary to apply auto-scaling to my servers. It required server migration. Migrating RabbitMQ settings meant a lot of repetitive tasks to ensure a smooth migration process; rather than perform this, I discovered a relationship between the RabbitMQ settings and the hostname, which ultimately decreased repetition.

In this article, I’ll explain how to migrate RabbitMQ using the hostname.

A Basic Way To Migrate RabbitMQ (Using RabbitMQCTL)

In order to migrate RabbitMQ to the same existing server setting, you need to manually set each of the settings (such as vhost, username, permission, etc.) from the existing server. For example, there is a RabbitMQ server consisted of the settings which the Vhost is test and username is Claudia. If you migrate this server, you will go through the following steps.

Check the Existing Server RabbitMQ Setting

1. Check the vhost

2. Check the username

Try To Migrate To the RabbitMQ Server

1. Install the RabbitMQ server on a new server

2. Create a vhost using rabbitmqctl on the new server

3. Create a user using rabbitmqctl on the new server

4. Set user permission using rabbitmqctl on the new server

It is easy to migrate the RabbitMQ server using this way when the server has some vhost, user, etc… But if the server has many settings, it is inefficient to migrate this way because it will take a lot of time. (Maybe it requires repetition according to the settings.)

Therefore, I will introduce a new migration way without repetition that works.

A New Way To Migrate RabbitMQ Using Copy and Setting Hostname

For using the new way, we need to check the setting files. You can find the setting files on /var/lib/rabbitmq. Thus, let’s start a migration using these files.

Check the Existing Server RabbitMQ Setting

Try To Migrate the RabbitMQ Server

1. Find the setting files on the existing server

You can find the setting files according to the following command. (Tip: the path of RabbitMQ setting files is /var/lib/rabbitmq.)

2. Install the RabbitMQ server on a new server.

3. Copy the setting file of the existing server to /var/lib/rabbitmq/mnesia on the new server

4. Change the hostname

If the hostname is not equal to the past one, the new server will not work properly.

5. Restart the RabbitMQ server

Check the RabbitMQ Setting on the New Server

You can see that the migration is completed successfully:

With this method, no matter how many settings you have, it is easy to complete the migration.

How Is This Possible?

When starting the RabbitMQ server, it reads the environment files from the base directory according to rabbitMQ_NODENAME. Let’s check the initialization environment process of the rabbitmq-server code, which is a function(get_prefixed_env_var).

rabbit_env.erl#L464-473

rabbit_env.erl#L744-L836

This means that if you copy the existing setup file format to the base directory /var/lib/RabbitMQ/mnesia, the setup will be applied as it is. In addition, you can see this type of setup files such as rabbit@<hostname>-<option> because of the default value of RabbitMQ_NODENAME(rabbit@<hostname>).

Therefore, if you have a hostname that is not the same as the existing server, the server will not run normally.

Conclusion

There are many different ways to migrate RabbitMQ, but it is difficult to find a way to do it easily and quickly. If you need to migrate RabbitMQ with complex settings, I recommend you use this hostname and the setup file copy method. Maybe using hostname makes for a more easy time to migrate RabbitMQ.

Credit: Source link

Previous Next
Close
Test Caption
Test Description goes like this