Detailed tutorial on installing and configuring rabbitMQ under linux

Detailed tutorial on installing and configuring rabbitMQ under linux

 

 
  

Install Erlang

Since RabbitMQ depends on Erlang, Erlang needs to be installed first.

There are roughly two ways to install Erlang:

  1. Install from Erlang Solution (recommended)

     # 添加erlang solutions源
     $ wget https://packages.erlang-solutions.com/erlang-solutions-1.0-1.noarch.rpm
     $ sudo rpm -Uvh erlang-solutions-1.0-1.noarch.rpm
     
     $ sudo yum install erlang
    
  2. Install from EPEL source (the Erlang version installed in this way may not be the latest and sometimes does not meet the minimum version required by RabbitMQ)

     # 启动EPEL源
     $ sudo yum install epel-release 
     # 安装erlang
     $ sudo yum install erlang  

 

 

Install RabbitMQ when done:

First download the rpm:

wget http://www.rabbitmq.com/releases/rabbitmq-server/v3.6.6/rabbitmq-server-3.6.6-1.el7.noarch.rpm

After the download is complete, install:

yum install rabbitmq-server-3.6.6-1.el7.noarch.rpm

 

 
  

If you encounter the following dependency error during installation

Error: Package: socat-1.7.2.3-1.el6.x86_64 (epel)
       Requires: libreadline.so.5()(64bit)

You can try to execute first

$ sudo yum install socat

Some basic operations on RabbitMQ

$ sudo chkconfig rabbitmq-server on  # 添加开机启动RabbitMQ服务
$ sudo /sbin/service rabbitmq-server start # 启动服务
$ sudo /sbin/service rabbitmq-server status  # 查看服务状态
$ sudo /sbin/service rabbitmq-server stop   # 停止服务

# 查看当前所有用户
$ sudo rabbitmqctl list_users

# 查看默认guest用户的权限
$ sudo rabbitmqctl list_user_permissions guest

# 由于RabbitMQ默认的账号用户名和密码都是guest。为了安全起见, 先删掉默认用户
$ sudo rabbitmqctl delete_user guest

# 添加新用户
$ sudo rabbitmqctl add_user username password

# 设置用户tag
$ sudo rabbitmqctl set_user_tags username administrator

# 赋予用户默认vhost的全部操作权限
$ sudo rabbitmqctl set_permissions -p / username ".*" ".*" ".*"

# 查看用户的权限
$ sudo rabbitmqctl list_user_permissions username

For more information on rabbitmqctlthe usage, please refer to the help manual .

Open the web management interface

It is somewhat inconvenient to operate RabbitMQ only from the command line. Fortunately, RabbitMQ comes with a web management interface, which can be used only by starting the plug-in.

$ sudo rabbitmq-plugins enable rabbitmq_management

then access via browser

http://localhost:15672

Enter your username and password to access the web management interface.

Configure RabbitMQ

Regarding the configuration of RabbitMQ, you can download the configuration file template of RabbitMQ to /etc/rabbitmq/rabbitmq.config, and then change it according to your needs.
For the specific role of each configuration item, you can refer to the official documentation .
After updating the configuration, don't forget to restart the service!

Enable user remote access

By default, the default guestuser of RabbitMQ only allows local access. If you want guestthe user to have remote access, you only need to loopback_usersset the list in the configuration file to be empty, as follows:

{loopback_users, []}

In addition, the newly added user can be accessed directly from the remote. If you want the newly added user to only have local access, you can add the user name to the above list, for example, only allow the adminuser to access locally.

{loopback_users, ["admin"]}

After updating the configuration, don't forget to restart the service!



 

 sudo /sbin/service rabbitmq-server status  # 查看服务状态

 

Here you can see the location of the log file, go to the file location, and open the file:

This shows that the configuration file was not found, we can create this file ourselves

cd /etc/rabbitmq/
vi rabbitmq.config

Edited as follows:

[{rabbit, [{loopback_users, []}]}].

The meaning here is open to use. The user guest created by rabbitmq by default has a password of guest. This user can only be accessed locally by default, localhost or 127.0.0.1. For external access, the above configuration needs to be added.

Restart the service after saving the configuration:

service rabbitmq-server stop
service rabbitmq-server start

At this point, it can be accessed from the outside, but when I look at the log file again, I find that the content is still the same, and it still shows that the configuration file is not found. You can manually delete this file and restart the service, but this does not affect the use.

rm rabbit\@mythsky.log
service rabbitmq-server stop
service rabbitmq-server start

Note: Remember to open ports 5672 and 15672

[java]  view plain copy  
 
  1. /sbin/iptables -I INPUT -p tcp --dport 5672 -j ACCEPT  
  2. /sbin/iptables -I INPUT -p tcp --dport 15672 -j ACCEPT  


 

 

 

 

 

 

Copyright statement: This article is an original article by the blogger and may not be reproduced without the blogger's permission. https://blog.csdn.net/qq_22075041/article/detai

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325290776&siteId=291194637