rabbitmq 端口作用以及修改方法


rabbitmq 端口

參考 https://www.rabbitmq.com/networking.html#ports

Port Access

RabbitMQ nodes bind to ports (open server TCP sockets) in order to accept client and CLI tool connections. Other processes and tools such as SELinux may prevent RabbitMQ from binding to a port. When that happens, the node will fail to start.

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

    4369: epmd, a peer discovery service used by RabbitMQ nodes and CLI tools
    5672, 5671: used by AMQP 0-9-1 and 1.0 clients without and with TLS
    25672: used for inter-node and CLI tools communication (Erlang distribution server port) and is allocated from a dynamic range (limited to a single port by default, computed as AMQP port + 20000). Unless external connections on these ports are really necessary (e.g. the cluster uses federation or CLI tools are used on machines outside the subnet), these ports should not be publicly exposed. See networking guide for details.
    35672-35682: used by CLI tools (Erlang distribution client ports) for communication with nodes and is allocated from a dynamic range (computed as server distribution port + 10000 through server distribution port + 10010). See networking guide for details.
    15672: HTTP API clients, management UI and rabbitmqadmin (only if the management plugin is enabled)
    61613, 61614: STOMP clients without and with TLS (only if the STOMP plugin is enabled)
    1883, 8883: MQTT clients without and with TLS, if the MQTT plugin is enabled
    15674: STOMP-over-WebSockets clients (only if the Web STOMP plugin is enabled)
    15675: MQTT-over-WebSockets clients (only if the Web MQTT plugin is enabled)
    15692: Prometheus metrics (only if the Prometheus plugin is enabled)

默認5672端口號修改

第一種方法:

在/etc/rabbitmq/rabbitmq.conf配置文件中加上如下配置:

listeners.tcp.default = 5678

或者

[
  {rabbit, [
      {tcp_listeners, [5678]}
    ]
  }
]

上面的示例將更改RabbitMQ監聽AMQP0-9-1和AMQP 1.0協議客戶端的連接端口從5672到5678。

參考 https://www.rabbitmq.com/configure.html

A minimalistic example configuration file follows:

# this is a comment
listeners.tcp.default = 5673

The same example in the classic config format:

%% this is a comment
[
  {rabbit, [
      {tcp_listeners, [5673]}
    ]
  }
].

This example will alter the port RabbitMQ listens on for AMQP 0-9-1 and AMQP 1.0 client connections from 5672 to 5673.

RabbitMQ服務器源存儲庫包含一個名為RabbitMQ.conf.example的配置文件示例,它包含你可能想要設置的大多數配置項的示例(省略了一些非常模糊的匹配項)。

第二種方法:

在/etc/rabbitmq/rabbitmq-env.conf配置文件中添加如下配置:

NODE_PORT=5673

1

rabbitmq-env.conf配置文件中的配置優先級高於rabbitmq.conf配置文件中的配置

默認15672端口號更改

參考 https://www.rabbitmq.com/management.html#configuration

listeners.tcp.default = 5672

collect_statistics_interval = 10000

## Note: this uses the core `load_definitions` key over
## now deprecated `management.load_definitions`
# load_definitions = /path/to/exported/definitions.json

management.tcp.port = 15672
management.tcp.ip   = 0.0.0.0

management.ssl.port       = 15671
management.ssl.ip         = 0.0.0.0
management.ssl.cacertfile = /path/to/ca_certificate.pem
management.ssl.certfile   = /path/to/server_certificate.pem
management.ssl.keyfile    = /path/to/server_key.pem

management.http_log_dir = /path/to/rabbit/logs/http

management.rates_mode = basic

# Configure how long aggregated data (such as message rates and queue
# lengths) is retained.
# Your can use 'minute', 'hour' and 'day' keys or integer key (in seconds)
management.sample_retention_policies.global.minute    = 5
management.sample_retention_policies.global.hour  = 60
management.sample_retention_policies.global.day = 1200

management.sample_retention_policies.basic.minute   = 5
management.sample_retention_policies.basic.hour = 60

management.sample_retention_policies.detailed.10 = 5

在/etc/rabbitmq/rabbitmq.conf配置文件中加上如下配置:

management.tcp.port = 15673

默認25672端口號更改

參考 https://www.rabbitmq.com/networking.html

Inter-node Communication Port Range

RabbitMQ nodes will use a port from a certain range known as the inter-node communication port range. The same port is used by CLI tools when they need to contact the node. The range can be modified.

RabbitMQ nodes communicate with CLI tools and other nodes using a port known as the distribution port. It is dynamically allocated from a range of values. For RabbitMQ, the default range is limited to a single value computed as RABBITMQ_NODE_PORT (AMQP 0-9-1 and AMQP 1.0 port) + 20000, which results in using port 25672. This single port can be configured using the RABBITMQ_DIST_PORT environment variable.

25672端口用於節點間和CLI工具通信(Erlang分發服務器端口),並從動態范圍分配(默認情況下僅限於單個端口,計算方式為AMQP 0-9-1和AMQP 1.0端口+20000),默認情況下通過 RABBITMQ_NODE_PORT 計算是25672,也可以通過RABBITMQ_DIST_PORT環境變量配置

rabbitmq-env.conf

在/etc/rabbitmq/rabbitmq-env.conf配置文件中添加如下配置:

通過設置 RABBITMQ_NODE_PORT計算 RABBITMQ_DIST_PORT 端口:

RABBITMQ_NODE_PORT=5674

RABBITMQ_DIST_PORT = Default: RABBITMQ_NODE_PORT + 20000

RABBITMQ_DIST_PORT 這個可以自己設置,也可以根據規則 RABBITMQ_NODE_PORT + 20000 算出來

RABBITMQ_DIST_PORT=25674

上面兩種方案一種是直接設置節點和CLI工具通信的分發端口,另外一種是通過設置RabbitMQ服務器和客戶端之間通信端口並計算得到25674端口號。

默認4369端口號更改

EPMD默認端口號是4369,但是可以使用ERL_EPMD_PORT環境變量更改。

ERL_EPMD_PORT Port used by epmd, a component in inter-node and CLI tool communication.
Default: 4369

列出在當前運行的epmd中綁定注冊的端口號及監聽的分發端口:

[root@mq ~]# epmd -names
epmd: up and running on port 4369 with data:
name rabbit at port 25672
[root@mq ~]# 

修改端口號參考

https://www.rabbitmq.com/networking.html#epmd

EPMD Interface

epmd will listen on all interfaces by default. It can be limited to a number of interfaces using the ERL_EPMD_ADDRESS environment variable:

# makes epmd listen on loopback IPv6 and IPv4 interfaces
export ERL_EPMD_ADDRESS="::1"

When ERL_EPMD_ADDRESS is changed, both RabbitMQ node and epmd on the host must be stopped. For epmd, use

# Stops local epmd process.
# Use after shutting down RabbitMQ.
epmd -kill

to terminate it. The service will be started by the local RabbitMQ node automatically on boot.

The loopback interface will be implicitly added to that list (in other words, epmd will always bind to the loopback interface).
EPMD Port

The default epmd port is 4369, but this can be changed using the ERL_EPMD_PORT environment variable:

# makes epmd bind to port 4369
export ERL_EPMD_PORT="4369"

All hosts in a cluster must use the same port.

When ERL_EPMD_PORT is changed, both RabbitMQ node and epmd on the host must be stopped. For epmd, use

# Stops local epmd process.
# Use after shutting down RabbitMQ.
epmd -kill

to terminate it. The service will be started by the local RabbitMQ node automatically on boot.

修改epmd守護進程綁定的端口號:

export ERL_EPMD_PORT="4369"

殺死epmd守護進程指令:

epmd -kill

當然直接在系統中使用export命令設置環境變量是可以生效的,但是只要系統重啟環境變量就失效;可以在/etc/profile或/root/.bashrc文件配置系統環境變量,然后source 文件名就可以永久生效了。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM