Install RabbitMq on Amamzon EC2 (Amazon Linux 2)
Tags: rabbitmq, aws, awqp, messagebrokers
Published: 2020-04-19 15:25:25

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/02vxknkjfeztade855ko.png)

### Update all the packages to the latest version available.

```
sudo yum -y update
```

--------
### Package Dependencies before installing RabbitMq
In order to intall rabbitmq, we need to have these packages available:
 1. erlang
 2. socat
 3. logrotate

--------
### Enable the EPEL repository

Standard repositories might not provide all the packages that can be installed on CentOS, Red Hat Enterprise Linux (RHEL), or Amazon Linux-based distributions. Enabling the EPEL repository provides additional options for package installation


1.Amazon Linux 2

Install the EPEL release package for EL 7 and enable the EPEL repository.
   
```
sudo yum install -y https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
sudo yum-config-manager --enable epel
```

2.Amazon Linux AMI

The EPEL repository is already installed on the original version of Amazon Linux, but you must enable it. You can enable this repository either by using the yum-config-manager command or by editing the epel.repo file.
    
```
sudo yum-config-manager --enable epel
 ```
See more at [ec2-enable-epel](https://aws.amazon.com/premiumsupport/knowledge-center/ec2-enable-epel/)

--------
### Install Erlang

```
sudo yum install erlang --enablerepo=epel
```
   
   
>TIP: Prevent Erlang unwanted upgrades
>To do this, follow:

Install package named yum-plugin-versionlock (called yum-versionlock in RHEL 5).
   
```
yum install yum-plugin-versionlock
```
   	
The `/etc/yum/pluginconf.d/versionlock.list` will be created on the system.
   
To install or lock the version of the gcc package, add that package name to the `/etc/yum/pluginconf.d/versionlock.list` file by running:
   

```
yum versionlock gcc-*
```

Alternatively, you can edit the filelist, `/etc/yum/pluginconf.d/versionlock.list`, directly.
   
The above configuration will not allow to upgrade the gcc package to version greater than what was installed at the time the locking was performed.
Yum will attempt to update all packages, while excluding the packages listed in the versionlock file.
 
---   
### Install socat

```
sudo yum install -y socat
```

---
### Install logrotate
```
sudo yum install logrotate
```
---
### Install RabbitMq
get latest stavble version at http://www.rabbitmq.com/releases/rabbitmq-server, like I chose `v3.6.10`
	
```
wget http://www.rabbitmq.com/releases/rabbitmq-server/v3.6.10/rabbitmq-server-3.6.10-1.el6.noarch.rpm
sudo rpm -Uvh rabbitmq-server-3.6.10-1.el6.noarch.rpm
```

---
### Enable RabbitMq management

```
sudo rabbitmq-plugins enable rabbitmq_management
```

---
### Set RabbitMQ Server to start automatically on machine-reboot 

The RabbitMQ server does not start as a daemon by default when your system starts. If, however, you want it to start by default, then run the following command as the root user or a user with sudo privileges

```
chkconfig rabbitmq-server on
```

---
### Start/Stop the server

- Start:  `/sbin/service rabbitmq-server start`
- Stop:  `/sbin/service rabbitmq-server stop`
- Status:  `/sbin/service rabbitmq-server status`

---
### Logging-in to the server management from browser

By default, the `guest` user is prohibited from connecting from remote hosts; it can only connect over a loopback interface (i.e. localhost). This applies to connections regardless of the protocol. Any other users will not (by default) be restricted in this way.

It is possible to allow the guest user to connect from a remote host by setting the loopback_users configuration to none

```
# DANGER ZONE!
#
# allowing remote connections for default user is highly discouraged
# as it dramatically decreases the security of the system. Delete the user
# instead and create a new one with generated secure credentials.
loopback_users = none
```
Or, in the classic config file format (rabbitmq.config):

```
%% DANGER ZONE!
%%
%% Allowing remote connections for default user is highly discouraged
%% as it dramatically decreases the security of the system. Delete the user
%% instead and create a new one with generated secure credentials.
[{rabbit, [{loopback_users, []}]}].
```

See more at ["guest" user can only connect from localhost](https://www.rabbitmq.com/access-control.html#loopback-users)

TIP: It is advisable to delete the guest user or at least change its password to reasonably secure generated value that won't be known to the public.


---
### Create new user
 - Add a new/fresh user, say user test and password test:

```
rabbitmqctl add_user guest1 guest1
```

  - Give administrative access to the new user:

```
rabbitmqctl set_user_tags guest1 administrator
```

 - Set permission to newly created user:

```
rabbitmqctl set_permissions -p / guest1 ".*" ".*" ".*"
```
Now try to login via `guest1`/`guest1`