Centos7 install RabbitMQ and configuration

  • 1. Install the dependent environment Erlang

Some people say not to install directly like this:

yum install erlang

Because the erlang version is not necessarily new,

I tried it, and the result version is as follows:

 

  • 2. Install rabbitmq

https://www.rabbitmq.com/install-rpm.html

RabbitMQ has certain requirements for the Erlang version (the official version requirement correspondence table ).

Erlang R16B03-1 (erts-5.10.4) does not support the 3.6 versions of rabbitmq.

I saw someone build it before: RabbitMQ 3.3.5, Erlang R16B03-1

yum list rabbitmq-server

See also version 3.3.5

Perform the installation directly:

yum install rabbitmq-server.noarch

 

Find the installation directory

# which rabbitmq-server
/usr/sbin/rabbitmq-server


ls /usr/sbin/rabbitmq*
rabbitmqctl  rabbitmq-plugins  rabbitmq-server

 

Service operation/configuration reference: https://www.rabbitmq.com/install-rpm.html#running-rpm

#将服务器作为守护程序启动,在系统引导时默认启动守护程序,以管理员身份运行
chkconfig rabbitmq-server on

#启动
/sbin/service rabbitmq-server start

#停止
/sbin/service rabbitmq-server stop

An error was reported during startup:

# systemctl status rabbitmq-server.service -l
● rabbitmq-server.service - RabbitMQ broker
   Loaded: loaded (/usr/lib/systemd/system/rabbitmq-server.service; enabled; vendor preset: disabled)
   Active: failed (Result: exit-code) since Sun 2021-02-28 17:02:05 CST; 45s ago
  Process: 17283 ExecStart=/usr/lib/rabbitmq/bin/rabbitmq-server (code=exited, status=1/FAILURE)
 Main PID: 17283 (code=exited, status=1/FAILURE)

Feb 28 17:02:05 hecs-x-medium-2-linux-20210131110450 systemd[1]: Starting RabbitMQ broker...
Feb 28 17:02:05 hecs-x-medium-2-linux-20210131110450 rabbitmq-server[17283]: ERROR: node with name "rabbit" already running on "hecs-x-medium-2-linux-20210131110450"
Feb 28 17:02:05 hecs-x-medium-2-linux-20210131110450 systemd[1]: rabbitmq-server.service: main process exited, code=exited, status=1/FAILURE
Feb 28 17:02:05 hecs-x-medium-2-linux-20210131110450 systemd[1]: Failed to start RabbitMQ broker.
Feb 28 17:02:05 hecs-x-medium-2-linux-20210131110450 systemd[1]: Unit rabbitmq-server.service entered failed state.
Feb 28 17:02:05 hecs-x-medium-2-linux-20210131110450 systemd[1]: rabbitmq-server.service failed.

Find the relevant process and end it:

ps -ef|grep rabbitmq

kill -9 进程id


#启动
/sbin/service rabbitmq-server start


Check the plug-in situation:

# rabbitmq-plugins list
[ ] amqp_client                       3.3.5
[ ] cowboy                            0.5.0-rmq3.3.5-git4b93c2d
[ ] eldap                             3.3.5-gite309de4
[ ] mochiweb                          2.7.0-rmq3.3.5-git680dba8
[ ] rabbitmq_amqp1_0                  3.3.5
[ ] rabbitmq_auth_backend_ldap        3.3.5
[ ] rabbitmq_auth_mechanism_ssl       3.3.5
[ ] rabbitmq_consistent_hash_exchange 3.3.5
[ ] rabbitmq_federation               3.3.5
[ ] rabbitmq_federation_management    3.3.5
[ ] rabbitmq_management               3.3.5
[ ] rabbitmq_management_agent         3.3.5
[ ] rabbitmq_management_visualiser    3.3.5
[ ] rabbitmq_mqtt                     3.3.5
[ ] rabbitmq_shovel                   3.3.5
[ ] rabbitmq_shovel_management        3.3.5
[ ] rabbitmq_stomp                    3.3.5
[ ] rabbitmq_test                     3.3.5
[ ] rabbitmq_tracing                  3.3.5
[ ] rabbitmq_web_dispatch             3.3.5
[ ] rabbitmq_web_stomp                3.3.5
[ ] rabbitmq_web_stomp_examples       3.3.5
[ ] sockjs                            0.3.4-rmq3.3.5-git3132eb9
[ ] webmachine                        1.10.3-rmq3.3.5-gite9359c7

Open the web plugin:

# rabbitmq-plugins enable rabbitmq_management
The following plugins have been enabled:
  mochiweb
  webmachine
  rabbitmq_web_dispatch
  amqp_client
  rabbitmq_management_agent
  rabbitmq_management
Plugin configuration has changed. Restart RabbitMQ for changes to take effect.

# rabbitmq-plugins list
[e] amqp_client                       3.3.5
[ ] cowboy                            0.5.0-rmq3.3.5-git4b93c2d
[ ] eldap                             3.3.5-gite309de4
[e] mochiweb                          2.7.0-rmq3.3.5-git680dba8
[ ] rabbitmq_amqp1_0                  3.3.5
[ ] rabbitmq_auth_backend_ldap        3.3.5
[ ] rabbitmq_auth_mechanism_ssl       3.3.5
[ ] rabbitmq_consistent_hash_exchange 3.3.5
[ ] rabbitmq_federation               3.3.5
[ ] rabbitmq_federation_management    3.3.5
[E] rabbitmq_management               3.3.5
[e] rabbitmq_management_agent         3.3.5
[ ] rabbitmq_management_visualiser    3.3.5
[ ] rabbitmq_mqtt                     3.3.5
[ ] rabbitmq_shovel                   3.3.5
[ ] rabbitmq_shovel_management        3.3.5
[ ] rabbitmq_stomp                    3.3.5
[ ] rabbitmq_test                     3.3.5
[ ] rabbitmq_tracing                  3.3.5
[e] rabbitmq_web_dispatch             3.3.5
[ ] rabbitmq_web_stomp                3.3.5
[ ] rabbitmq_web_stomp_examples       3.3.5
[ ] sockjs                            0.3.4-rmq3.3.5-git3132eb9
[e] webmachine                        1.10.3-rmq3.3.5-gite9359c7

Check whether the port is normal:

# netstat -an|grep 5672
tcp        0      0 0.0.0.0:25672           0.0.0.0:*               LISTEN
tcp6       0      0 :::5672                 :::*                    LISTEN

It is found that port 15672 is not started, and the web management terminal cannot be accessed. Just restart it:

/sbin/service rabbitmq-server restart

The RabbitMQ node is bound to a port (open server TCP socket) in order to accept connections from clients and CLI tools. Other processes and tools, such as SELinux, may prevent RabbitMQ from binding to the port. When this happens, the node will fail to start.

CLI tools, client libraries and RabbitMQ nodes can also open connections (client TCP sockets). The firewall can prevent nodes and CLI tools from communicating with each other. Make sure you can access the following ports:

  • 4369: epmd , a peer-to-peer discovery service used by RabbitMQ nodes and CLI tools
  • 5672, 5671: Used by AMQP 0-9-1 and 1.0 clients without TLS and with TLS
  • 25672: Used for inter-node and CLI tool communication (Erlang distribution server port), and allocated from the dynamic range (limited to a single port by default, calculated as AMQP port + 20000). Unless external connections on these ports are really required (for example, the cluster uses federated authentication or CLI tools are used on computers outside the subnet), these ports should not be exposed. For details, see Network Guide .
  • 35672-35682: Used by the CLI tool (Erlang distribution client port) to communicate with the node, and is allocated from the dynamic range (calculated by the server distribution port + 10010 as the server distribution port + 10000). For details, see Network Guide .
  • 15672: HTTP API client, management UI and Rabbitmqadmin  (only when the management plugin is enabled )
  • 61613, 61614: STOMP client without TLS and with TLS (only when the STOMP plug- in is enabled )
  • 1883, 8883: MQTT clients that do not enable and enable TLS (if the MQTT plug-in is enabled )
  • 15674: STOMP-over-WebSockets client (only when the Web STOMP plug- in is enabled )
  • 15675: MQTT-over-WebSockets client (only when the Web MQTT plug- in is enabled )
  • 15692: Prometheus metrics (only when the Prometheus plugin is enabled )

RabbitMQ can be configured  to use different ports and specific network interfaces .

 

View all users

rabbitmqctl list_users

默认账号密码:guest guest(这个账号只允许本机访问)

Add a user

rabbitmqctl add_user fuckrabbit 123456

Configure permissions

rabbitmqctl set_permissions -p "/" fuckrabbit ".*" ".*" ".*"

View user permissions

rabbitmqctl list_user_permissions fuckrabbit

Set tag

# 赋予用户管理员角色
rabbitmqctl set_user_tags fuckrabbit administrator



或者普通管理:
rabbitmqctl set_user_tags fuckrabbit management

Delete user (for safety, delete the default user)

rabbitmqctl delete_user guest

change Password:

rabbimqctl change_password username newpassword

 

The service provider’s security group and the server’s firewall open ports: 5672, 15672

# firewall-cmd --zone=public --add-port=5672/tcp --add-port=15672/tcp --permanent

# firewall-cmd --reload
success

# firewall-cmd --list-all
public (active)
  target: default
  icmp-block-inversion: no
  interfaces: eth0
  sources:
  services: dhcpv6-client ssh
  ports: 20/tcp 21/tcp 22/tcp 80/tcp 8888/tcp 39000-40000/tcp 81/tcp 889/tcp 5672/tcp 15672/tcp
  protocols:
  masquerade: no
  forward-ports:
  source-ports:
  icmp-blocks:
  rich rules:

Web access: http://server IP:15672/

Enter the new account to log in successfully:

 

Excerpt: When we create a user, we will specify that the user can access a virtual machine, and the user can only access the queues and switches under the virtual machine. If not specified, the default is "/"; it can run on a rabbitmq server Multiple vhosts are suitable for different business needs. This can not only meet the requirements of permission configuration, but also avoid the problem of naming conflicts between queues and switches between different services, because different vhosts are isolated.
Original link: https://blog.csdn.net/leisure_life/article/details/78707338

Add/remove virtual machine

#添加
rabbitmqctl add_vhost /aaaaa

#给用户分配虚拟机
rabbitmqctl set_permissions -p /aaaaa fuckrabbit ".*" ".*" ".*"

#删除虚拟机
rabbitmqctl delete_vhost /aaaaa

#查看虚拟机列表
rabbitmqctl list_vhosts

Add a switch:

rabbitmqctl eval 'rabbit_exchange:declare({resource, <<"/aaaaa">>, exchange, <<"to_server">>}, fanout, true, false, false, []).'

rabbitmqctl eval 'rabbit_exchange:declare({resource, <<"/aaaaa">>, exchange, <<"from_server">>}, fanout, true, false, false, []).'


#查看
rabbitmqctl list_exchanges

 

 

 

  • reference:

Centos7 install the latest RabbitMQ and configuration

Install RabbitMQ on CentOS7

Requires: erlang >= 20.3 Available: erlang-R16B-03.18.el7.x86_64

rabbitmq startup error

启动rabbitmq,提示ERROR: node with name "rabbit" already running on "U57..."

Rabbitmq's vhost and user management

rabbitmq management commands

 

Guess you like

Origin blog.csdn.net/yyws2039725/article/details/114217155