安装RabbitMQ

安装方式


安装RabbitMQ,官方提供很多种方式,具体参考地址如下

https://www.rabbitmq.com/docs/download#installation-guides

  1. RPM安装
  2. 二进制下载安装
  3. 源码构建安装
  4. Docker
  5. Kubernetes
  6. VMware
  7. 云厂商平台

RPM安装

There are two ways of installing these RPMs:

  1. Installing the package using Yum repositories (this option is highly recommended) from a Cloudsmith.io mirror
  2. Downloading the package and installing it with rpm. This option will require manual installation of all package dependencies and makes upgrades more difficult.

安装RabbitMQ时,需要注意的是软件依赖关系

  1. erlang
  2. socat
  3. logrotate

但是使用YUM安装可以规避这些依赖关系,Redhat系统YUM安装

  1. impost Singing Keys
    ## primary RabbitMQ signing key
    rpm --import 'https://github.com/rabbitmq/signing-keys/releases/download/3.0/rabbitmq-release-signing-key.asc'
    ## modern Erlang repository
    rpm --import 'https://github.com/rabbitmq/signing-keys/releases/download/3.0/cloudsmith.rabbitmq-erlang.E495BB49CC4BBE5B.key'
    ## RabbitMQ server repository
    rpm --import 'https://github.com/rabbitmq/signing-keys/releases/download/3.0/cloudsmith.rabbitmq-server.9F4587F226208342.key'
  2. 添加RabbitMQ 与 Modern Erlang 仓库(以下是CentOS8)
    # In /etc/yum.repos.d/rabbitmq.repo
    
    ##
    ## Zero dependency Erlang RPM
    ##
    
    [modern-erlang]
    name=modern-erlang-el8
    # uses a Cloudsmith mirror @ yum.novemberain.com in addition to its Cloudsmith upstream.
    # Unlike Cloudsmith, the mirror does not have any traffic quotas
    baseurl=https://yum1.novemberain.com/erlang/el/8/$basearch
            https://yum2.novemberain.com/erlang/el/8/$basearch
            https://dl.cloudsmith.io/public/rabbitmq/rabbitmq-erlang/rpm/el/8/$basearch
    repo_gpgcheck=1
    enabled=1
    gpgkey=https://github.com/rabbitmq/signing-keys/releases/download/3.0/cloudsmith.rabbitmq-erlang.E495BB49CC4BBE5B.key
    gpgcheck=1
    sslverify=1
    sslcacert=/etc/pki/tls/certs/ca-bundle.crt
    metadata_expire=300
    pkg_gpgcheck=1
    autorefresh=1
    type=rpm-md
    
    [modern-erlang-noarch]
    name=modern-erlang-el8-noarch
    # uses a Cloudsmith mirror @ yum.novemberain.com.
    # Unlike Cloudsmith, it does not have any traffic quotas
    baseurl=https://yum1.novemberain.com/erlang/el/8/noarch
            https://yum2.novemberain.com/erlang/el/8/noarch
            https://dl.cloudsmith.io/public/rabbitmq/rabbitmq-erlang/rpm/el/8/noarch
    repo_gpgcheck=1
    enabled=1
    gpgkey=https://github.com/rabbitmq/signing-keys/releases/download/3.0/cloudsmith.rabbitmq-erlang.E495BB49CC4BBE5B.key
           https://github.com/rabbitmq/signing-keys/releases/download/3.0/rabbitmq-release-signing-key.asc
    gpgcheck=1
    sslverify=1
    sslcacert=/etc/pki/tls/certs/ca-bundle.crt
    metadata_expire=300
    pkg_gpgcheck=1
    autorefresh=1
    type=rpm-md
    
    [modern-erlang-source]
    name=modern-erlang-el8-source
    # uses a Cloudsmith mirror @ yum.novemberain.com.
    # Unlike Cloudsmith, it does not have any traffic quotas
    baseurl=https://yum1.novemberain.com/erlang/el/8/SRPMS
            https://yum2.novemberain.com/erlang/el/8/SRPMS
            https://dl.cloudsmith.io/public/rabbitmq/rabbitmq-erlang/rpm/el/8/SRPMS
    repo_gpgcheck=1
    enabled=1
    gpgkey=https://github.com/rabbitmq/signing-keys/releases/download/3.0/cloudsmith.rabbitmq-erlang.E495BB49CC4BBE5B.key
           https://github.com/rabbitmq/signing-keys/releases/download/3.0/rabbitmq-release-signing-key.asc
    gpgcheck=1
    sslverify=1
    sslcacert=/etc/pki/tls/certs/ca-bundle.crt
    metadata_expire=300
    pkg_gpgcheck=1
    autorefresh=1
    
    
    ##
    ## RabbitMQ Server
    ##
    
    [rabbitmq-el8]
    name=rabbitmq-el8
    baseurl=https://yum2.novemberain.com/rabbitmq/el/8/$basearch
            https://yum1.novemberain.com/rabbitmq/el/8/$basearch
            https://dl.cloudsmith.io/public/rabbitmq/rabbitmq-server/rpm/el/8/$basearch
    repo_gpgcheck=1
    enabled=1
    # Cloudsmith's repository key and RabbitMQ package signing key
    gpgkey=https://github.com/rabbitmq/signing-keys/releases/download/3.0/cloudsmith.rabbitmq-server.9F4587F226208342.key
           https://github.com/rabbitmq/signing-keys/releases/download/3.0/rabbitmq-release-signing-key.asc
    gpgcheck=1
    sslverify=1
    sslcacert=/etc/pki/tls/certs/ca-bundle.crt
    metadata_expire=300
    pkg_gpgcheck=1
    autorefresh=1
    type=rpm-md
    
    [rabbitmq-el8-noarch]
    name=rabbitmq-el8-noarch
    baseurl=https://yum2.novemberain.com/rabbitmq/el/8/noarch
            https://yum1.novemberain.com/rabbitmq/el/8/noarch
            https://dl.cloudsmith.io/public/rabbitmq/rabbitmq-server/rpm/el/8/noarch
    repo_gpgcheck=1
    enabled=1
    # Cloudsmith's repository key and RabbitMQ package signing key
    gpgkey=https://github.com/rabbitmq/signing-keys/releases/download/3.0/cloudsmith.rabbitmq-server.9F4587F226208342.key
           https://github.com/rabbitmq/signing-keys/releases/download/3.0/rabbitmq-release-signing-key.asc
    gpgcheck=1
    sslverify=1
    sslcacert=/etc/pki/tls/certs/ca-bundle.crt
    metadata_expire=300
    pkg_gpgcheck=1
    autorefresh=1
    type=rpm-md
    
    [rabbitmq-el8-source]
    name=rabbitmq-el8-source
    baseurl=https://yum2.novemberain.com/rabbitmq/el/8/SRPMS
            https://yum1.novemberain.com/rabbitmq/el/8/SRPMS
            https://dl.cloudsmith.io/public/rabbitmq/rabbitmq-server/rpm/el/8/SRPMS
    repo_gpgcheck=1
    enabled=1
    gpgkey=https://github.com/rabbitmq/signing-keys/releases/download/3.0/cloudsmith.rabbitmq-server.9F4587F226208342.key
    gpgcheck=0
    sslverify=1
    sslcacert=/etc/pki/tls/certs/ca-bundle.crt
    metadata_expire=300
    pkg_gpgcheck=1
    autorefresh=1
    type=rpm-md
  3. 使用dnf安装RabbitMQ
    [12:05:54] root@sxjjd-edu-stages:~ # dnf update -y
    modern-erlang-el8-noarch                                                                                                                                                             211  B/s | 291  B     00:01
    modern-erlang-el8-source                                                                                                                                                             687  B/s | 659  B     00:00
    modern-erlang-el8-source                                                                                                                                                             804  B/s | 1.3 kB     00:01
    Importing GPG key 0xCC4BBE5B:
     Userid     : "Cloudsmith Package (rabbitmq/rabbitmq-erlang) <support@cloudsmith.io>"
     Fingerprint: A16A 4251 6F6A 691B C1FF 5621 E495 BB49 CC4B BE5B
     From       : https://github.com/rabbitmq/signing-keys/releases/download/3.0/cloudsmith.rabbitmq-erlang.E495BB49CC4BBE5B.key
    modern-erlang-el8-source                                                                                                                                                             2.7 kB/s | 3.1 kB     00:01
    Importing GPG key 0x6026DFCA:
     Userid     : "RabbitMQ Release Signing Key <info@rabbitmq.com>"
     Fingerprint: 0A9A F211 5F46 87BD 2980 3A20 6B73 A36E 6026 DFCA
     From       : https://github.com/rabbitmq/signing-keys/releases/download/3.0/rabbitmq-release-signing-key.asc
    modern-erlang-el8-source                                                                                                                                                             178  B/s | 291  B     00:01
    rabbitmq-el8                                                                                                                                                                         758  B/s | 659  B     00:00
    rabbitmq-el8                                                                                                                                                                         815  B/s | 1.3 kB     00:01
    Importing GPG key 0x26208342:
     Userid     : "Cloudsmith Package (rabbitmq/rabbitmq-server) <support@cloudsmith.io>"
     Fingerprint: C072 C960 4725 BAA2 18E1 F247 9F45 87F2 2620 8342
     From       : https://github.com/rabbitmq/signing-keys/releases/download/3.0/cloudsmith.rabbitmq-server.9F4587F226208342.key
    rabbitmq-el8                                                                                                                                                                         2.7 kB/s | 3.1 kB     00:01
    Importing GPG key 0x6026DFCA:
     Userid     : "RabbitMQ Release Signing Key <info@rabbitmq.com>"
     Fingerprint: 0A9A F211 5F46 87BD 2980 3A20 6B73 A36E 6026 DFCA
     From       : https://github.com/rabbitmq/signing-keys/releases/download/3.0/rabbitmq-release-signing-key.asc
    rabbitmq-el8                                                                                                                                                                         214  B/s | 291  B     00:01
    rabbitmq-el8-noarch                                                                                                                                                                  768  B/s | 659  B     00:00
    rabbitmq-el8-noarch                                                                                                                                                                  984  B/s | 1.3 kB     00:01
    Importing GPG key 0x26208342:
     Userid     : "Cloudsmith Package (rabbitmq/rabbitmq-server) <support@cloudsmith.io>"
     Fingerprint: C072 C960 4725 BAA2 18E1 F247 9F45 87F2 2620 8342
     From       : https://github.com/rabbitmq/signing-keys/releases/download/3.0/cloudsmith.rabbitmq-server.9F4587F226208342.key
    rabbitmq-el8-noarch                                                                                                                                                                  2.3 kB/s | 3.1 kB     00:01
    Importing GPG key 0x6026DFCA:
     Userid     : "RabbitMQ Release Signing Key <info@rabbitmq.com>"
     Fingerprint: 0A9A F211 5F46 87BD 2980 3A20 6B73 A36E 6026 DFCA
     From       : https://github.com/rabbitmq/signing-keys/releases/download/3.0/rabbitmq-release-signing-key.asc
    rabbitmq-el8-noarch                                                                                                                                                                  291 kB/s | 1.5 MB     00:05
    rabbitmq-el8-source                                                                                                                                                                  751  B/s | 659  B     00:00
    rabbitmq-el8-source                                                                                                                                                                  917  B/s | 1.3 kB     00:01
    Importing GPG key 0x26208342:
     Userid     : "Cloudsmith Package (rabbitmq/rabbitmq-server) <support@cloudsmith.io>"
     Fingerprint: C072 C960 4725 BAA2 18E1 F247 9F45 87F2 2620 8342
     From       : https://github.com/rabbitmq/signing-keys/releases/download/3.0/cloudsmith.rabbitmq-server.9F4587F226208342.key
    rabbitmq-el8-source                                                                                                                                                                  215  B/s | 291  B     00:01
    Dependencies resolved.
    Nothing to do.
    Complete!
    [12:06:23] root@sxjjd-edu-stages:~ # dnf install socat logrotate -y
    Last metadata expiration check: 0:00:32 ago on Sun 31 Mar 2024 12:06:22 PM CST.
    Package socat-1.7.4.1-1.0.1.al8.x86_64 is already installed.
    Package logrotate-3.14.0-6.0.1.al8.x86_64 is already installed.
    Dependencies resolved.
    Nothing to do.
    Complete!
    [12:06:54] root@sxjjd-edu-stages:~ # dnf install -y erlang rabbitmq-server
    Last metadata expiration check: 0:00:39 ago on Sun 31 Mar 2024 12:06:22 PM CST.
    Dependencies resolved.
    =====================================================================================================================================================================================================================
     Package                                              Architecture                                Version                                             Repository                                                Size
    =====================================================================================================================================================================================================================
    Installing:
     erlang                                               x86_64                                      26.2.3-1.el8                                        modern-erlang                                             21 M
     rabbitmq-server                                      noarch                                      3.13.1-1.el8                                        rabbitmq-el8-noarch                                       18 M
    
    Transaction Summary
    =====================================================================================================================================================================================================================
    Install  2 Packages
    
    Total download size: 39 M
    Installed size: 61 M
    Downloading Packages:
    (1/2): rabbitmq-server-3.13.1-1.el8.noarch.rpm                                                                                                                                       8.1 MB/s |  18 MB     00:02
    (2/2): erlang-26.2.3-1.el8.x86_64.rpm                                                                                                                                                5.7 MB/s |  21 MB     00:03
    ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    Total                                                                                                                                                                                 11 MB/s |  39 MB     00:03
    Running transaction check
    Transaction check succeeded.
    Running transaction test
    Transaction test succeeded.
    Running transaction
      Preparing        :                                                                                                                                                                                             1/1
      Installing       : erlang-26.2.3-1.el8.x86_64                                                                                                                                                                  1/2
      Running scriptlet: rabbitmq-server-3.13.1-1.el8.noarch                                                                                                                                                         2/2
      Installing       : rabbitmq-server-3.13.1-1.el8.noarch                                                                                                                                                         2/2
      Running scriptlet: rabbitmq-server-3.13.1-1.el8.noarch                                                                                                                                                         2/2
    [/usr/lib/tmpfiles.d/rabbitmq-server.conf:1] Line references path below legacy directory /var/run/, updating /var/run/rabbitmq → /run/rabbitmq; please update the tmpfiles.d/ drop-in file accordingly.
    
      Verifying        : erlang-26.2.3-1.el8.x86_64                                                                                                                                                                  1/2
      Verifying        : rabbitmq-server-3.13.1-1.el8.noarch                                                                                                                                                         2/2
    
    Installed:
      erlang-26.2.3-1.el8.x86_64                                                                           rabbitmq-server-3.13.1-1.el8.noarch
    
    Complete!

二进制安装

  参考官方文档

  https://www.rabbitmq.com/docs/install-rpm#with-rpm

修改系统limits

  大部分系统都已经做过了,如果没有优化参考如下官方文档

  https://www.rabbitmq.com/docs/install-rpm#with-rpm

配置文件

RabbitMQ默认安装完成后,没有配置文件,及不开启management功能

设置RabbitMQ配置文件

  RabbitMQ默认安装好,配置文件位于/etc/rabbitmq/rabbitmq.conf

  To override the main RabbitMQ config file location, use the RABBITMQ_CONFIG_FILE (or RABBITMQ_CONFIG_FILES to use a conf.d-style directory of sorted files) environment variables. Use .conf as file extension for the new style config format, e.g. /etc/rabbitmq/rabbitmq.conf or /data/configuration/rabbitmq/rabbitmq.conf

  官方解释:修改默认位置可以使用环境变量RABBITMQ_CONFIG_FILE指定新的位置

  官方样本配置文件,每个版本都有对应的example配置文件 https://github.com/rabbitmq/rabbitmq-server/blob/v3.13.x/deps/rabbit/docs/advanced.config.example

  https://www.rabbitmq.com/docs/configure#example-config

修改.erlang.cookie

  1. 依次修改三台机器的/var/lib/rabbitmq/.erlang.cookie,cookie的值必须一致
    echo "KQWEXYBPNTZGQJCUCHYS" > /var/lib/rabbitmq/.erlang.cookie 

使用Config File Peer Discovery

  1. 修改配置文件/etc/rabbitmq/rabbitmq.conf
    # cluster_formation.peer_discovery_backend     = rabbit_peer_discovery_classic_config
    #
    cluster_formation.classic_config.nodes.1 = rabbit@xf-001-prodServer
    cluster_formation.classic_config.nodes.2 = rabbit@xf-002-prodServer
    cluster_formation.classic_config.nodes.3 = rabbit@xf-003-prodServer
    # cluster_formation.classic_config.nodes.4 = rabbit4@hostname
  2.  修改/etc/hosts
    [19:34:41] root@xf-002-prodServer:/etc/rabbitmq # cat /etc/hosts
    ::1     localhost       localhost.localdomain   localhost6      localhost6.localdomain6
    127.0.0.1       localhost       localhost.localdomain   localhost4      localhost4.localdomain4
    
    172.16.0.147    iZuf6af5l7nxpgas4hgtv8Z iZuf6af5l7nxpgas4hgtv8Z
    
    
    172.16.0.148    xf-001-prodServer                                                                                                                                                                           
    172.16.0.147    xf-002-prodServer                                                                                                                                                                           
    172.16.0.149    xf-003-prodServer

加入集群

  参考官方文档 https://www.rabbitmq.com/docs/clustering#creating

开启management-plugin

  激活RabbitMQ的插件有多种方法,如下

  1. 查看当前激活的plugin,如下
    [13:03:38] root@sxjjd-edu-stages:/etc/rabbitmq # rabbitmq-plugins list
    Listing plugins with pattern ".*" ...
     Configured: E = explicitly enabled; e = implicitly enabled
     | Status: * = running on rabbit@sxjjd-edu-stages
     |/
    [  ] rabbitmq_amqp1_0                   (pending upgrade to 3.13.1)
    [  ] rabbitmq_auth_backend_cache        (pending upgrade to 3.13.1)
    [  ] rabbitmq_auth_backend_http         (pending upgrade to 3.13.1)
    [  ] rabbitmq_auth_backend_ldap         (pending upgrade to 3.13.1)
    [  ] rabbitmq_auth_backend_oauth2       (pending upgrade to 3.13.1)
    [  ] rabbitmq_auth_mechanism_ssl        (pending upgrade to 3.13.1)
    [  ] rabbitmq_consistent_hash_exchange  (pending upgrade to 3.13.1)
    [  ] rabbitmq_event_exchange            (pending upgrade to 3.13.1)
    [  ] rabbitmq_federation                (pending upgrade to 3.13.1)
    [  ] rabbitmq_federation_management     (pending upgrade to 3.13.1)
    [  ] rabbitmq_jms_topic_exchange        (pending upgrade to 3.13.1)
    [  ] rabbitmq_management                (pending upgrade to 3.13.1)
    [  ] rabbitmq_management_agent          (pending upgrade to 3.13.1)
    [  ] rabbitmq_mqtt                      (pending upgrade to 3.13.1)
    [  ] rabbitmq_peer_discovery_aws        (pending upgrade to 3.13.1)
    [  ] rabbitmq_peer_discovery_common     (pending upgrade to 3.13.1)
    [  ] rabbitmq_peer_discovery_consul     (pending upgrade to 3.13.1)
    [  ] rabbitmq_peer_discovery_etcd       (pending upgrade to 3.13.1)
    [  ] rabbitmq_peer_discovery_k8s        (pending upgrade to 3.13.1)
    [  ] rabbitmq_prometheus                (pending upgrade to 3.13.1)
    [  ] rabbitmq_random_exchange           (pending upgrade to 3.13.1)
    [  ] rabbitmq_recent_history_exchange   (pending upgrade to 3.13.1)
    [  ] rabbitmq_sharding                  (pending upgrade to 3.13.1)
    [  ] rabbitmq_shovel                    (pending upgrade to 3.13.1)
    [  ] rabbitmq_shovel_management         (pending upgrade to 3.13.1)
    [  ] rabbitmq_stomp                     (pending upgrade to 3.13.1)
    [  ] rabbitmq_stream                    (pending upgrade to 3.13.1)
    [  ] rabbitmq_stream_management         (pending upgrade to 3.13.1)
    [  ] rabbitmq_top                       (pending upgrade to 3.13.1)
    [  ] rabbitmq_tracing                   (pending upgrade to 3.13.1)
    [  ] rabbitmq_trust_store               (pending upgrade to 3.13.1)
    [  ] rabbitmq_web_dispatch              (pending upgrade to 3.13.1)
    [  ] rabbitmq_web_mqtt                  (pending upgrade to 3.13.1)
    [  ] rabbitmq_web_mqtt_examples         (pending upgrade to 3.13.1)
    [  ] rabbitmq_web_stomp                 (pending upgrade to 3.13.1)
    [  ] rabbitmq_web_stomp_examples        (pending upgrade to 3.13.1)
  2. 使用rabbitmq-plugins enable/disable
    [13:43:20] root@sxjjd-edu-stages:/etc/rabbitmq # rabbitmq-plugins enable rabbitmq_management
    Enabling plugins on node rabbit@sxjjd-edu-stages:
    rabbitmq_management
    The following plugins have been configured:
      rabbitmq_management
      rabbitmq_management_agent
      rabbitmq_shovel
      rabbitmq_web_dispatch
    Applying plugin configuration to rabbit@sxjjd-edu-stages...
    The following plugins have been enabled:
      rabbitmq_management
    
    started 1 plugins.
  3. 使用配置文件的形式激活插件 /etc/rabbitmq/enabled_plugins
    如果使用RABBITMQ_ENABLED_PLUGINS_FILE 可以覆盖默认的enabled_plugins文件位置
    [13:44:37] root@sxjjd-edu-stages:/etc/rabbitmq # cat enabled_plugins
    [rabbitmq_management,rabbitmq_management_agent,rabbitmq_shovel].
  4. 默认情况下RabbitMQ安装完成后,没有管理用户,需要自建

    https://www.rabbitmq.com/docs/access-control#granting-permissions-to-a-user

    ## 创建admin用户,密码admin
    [14:59:20] root@sxjjd-edu-stages:/etc/rabbitmq # rabbitmqctl add_user admin admin
    Adding user "admin" ...
    
    ## 对admin用户赋予adminstrator标签
    [15:16:32] root@sxjjd-edu-stages:/etc/rabbitmq # rabbitmqctl set_user_tags admin administrator
    Setting tags for user "admin" to [administrator] ...
    
    ## 加权限,默认情况下创建的用户是没有任何权限
    [15:18:00] root@sxjjd-edu-stages:/etc/rabbitmq # rabbitmqctl set_permissions -p / admin  ".*" ".*" ".*"
    Setting permissions for user "admin" in vhost "/" ...

    

enable feature

  默认情况下,在安装新版本以及升级后,需要手动enable新版本的功能,当然可以打开所有的feature

  1. 列出当前的feature
    [15:19:33] root@sxjjd-edu-stages:/etc/rabbitmq # rabbitmqctl list_feature_flags | column -t
    Listing                               feature   flags  ...
    name                                  state
    classic_mirrored_queue_version        enabled
    classic_queue_type_delivery_support   enabled
    detailed_queues_endpoint              enabled
    direct_exchange_routing_v2            enabled
    drop_unroutable_metric                enabled
    empty_basic_get_metric                enabled
    feature_flags_v2                      enabled
    implicit_default_bindings             enabled
    khepri_db                             disabled
    listener_records_in_ets               enabled
    maintenance_mode_status               enabled
    message_containers                    enabled
    quorum_queue                          enabled
    quorum_queue_non_voters               enabled
    restart_streams                       enabled
    stream_filtering                      enabled
    stream_queue                          enabled
    stream_sac_coordinator_unblock_group  enabled
    stream_single_active_consumer         enabled
    stream_update_config_command          enabled
    tracking_records_in_ets               enabled
    user_limits                           enabled
    virtual_host_metadata                 enabled
  2. 打开feature
    [15:19:25] root@sxjjd-edu-stages:/etc/rabbitmq # rabbitmqctl enable_feature_flag all
    Enabling all feature flags ...

     

posted @ 2024-03-31 11:37  MacoPlus  阅读(101)  评论(0编辑  收藏  举报