当前位置: 首页 > article >正文

Rocky Linux 9安装RabbitMQ

环境准备

Rocky Linux 9

安装步骤

安装Signing Keys(签名密钥)

rpm --import https://github.com/rabbitmq/signing-keys/releases/download/2.0/rabbitmq-release-signing-key.asc
rpm --import https://dl.cloudsmith.io/public/rabbitmq/rabbitmq-erlang/gpg.E495BB49CC4BBE5B.key
rpm --import https://dl.cloudsmith.io/public/rabbitmq/rabbitmq-server/gpg.9F4587F226208342.key

创建repo文件

在/etc/yum.repos.d/目录下创建一个名为rabbitmq.repo的文件,并添加以下内容:

# In /etc/yum.repos.d/rabbitmq.repo

##
## Zero dependency Erlang RPM
##

[modern-erlang]
name=modern-erlang-el9
# uses a Cloudsmith mirror @ yum1.novemberain.com.
# Unlike Cloudsmith, it does not have traffic quotas
baseurl=https://yum1.novemberain.com/erlang/el/9/$basearch
repo_gpgcheck=1
enabled=1
gpgkey=https://dl.cloudsmith.io/public/rabbitmq/rabbitmq-erlang/gpg.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-el9-noarch
# uses a Cloudsmith mirror @ yum1.novemberain.com.
# Unlike Cloudsmith, it does not have traffic quotas
baseurl=https://yum1.novemberain.com/erlang/el/9/noarch
repo_gpgcheck=1
enabled=1
gpgkey=https://dl.cloudsmith.io/public/rabbitmq/rabbitmq-erlang/gpg.E495BB49CC4BBE5B.key
       https://github.com/rabbitmq/signing-keys/releases/download/2.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-el9-source
# uses a Cloudsmith mirror @ yum1.novemberain.com.
# Unlike Cloudsmith, it does not have traffic quotas
baseurl=https://yum1.novemberain.com/erlang/el/9/SRPMS
repo_gpgcheck=1
enabled=1
gpgkey=https://dl.cloudsmith.io/public/rabbitmq/rabbitmq-erlang/gpg.E495BB49CC4BBE5B.key
       https://github.com/rabbitmq/signing-keys/releases/download/2.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-el9]
name=rabbitmq-el9
baseurl=https://yum1.novemberain.com/rabbitmq/el/9/$basearch
repo_gpgcheck=1
enabled=1
# Cloudsmith's repository key and RabbitMQ package signing key
gpgkey=https://dl.cloudsmith.io/public/rabbitmq/rabbitmq-server/gpg.9F4587F226208342.key
       https://github.com/rabbitmq/signing-keys/releases/download/2.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-el9-noarch]
name=rabbitmq-el9-noarch
baseurl=https://yum1.novemberain.com/rabbitmq/el/9/noarch
repo_gpgcheck=1
enabled=1
# Cloudsmith's repository key and RabbitMQ package signing key
gpgkey=https://dl.cloudsmith.io/public/rabbitmq/rabbitmq-server/gpg.9F4587F226208342.key
       https://github.com/rabbitmq/signing-keys/releases/download/2.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-el9-source]
name=rabbitmq-el9-source
baseurl=https://yum1.novemberain.com/rabbitmq/el/9/SRPMS
repo_gpgcheck=1
enabled=1
gpgkey=https://dl.cloudsmith.io/public/rabbitmq/rabbitmq-server/gpg.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

安装依赖

dnf update -y
sudo dnf install -y socat logrotate
sudo dnf install -y erlang

校验Erlang

erl
Erlang/OTP 27 [erts-15.2] [source] [64-bit] [smp:2:2] [ds:2:2:10] [async-threads:1] [jit:ns]

Eshell V15.2 (press Ctrl+G to abort, type help(). for help)
1>

安装RabbitMQ

dnf install rabbitmq-server

启动RabbitMQ, 设置开机自启动

systemctl start rabbitmq-server
systemctl enable rabbitmq-server

配置RabbitMQ

启动admin页面插件

rabbitmq-plugins enable rabbitmq_management

添加管理员admin

RabbitMQ自带一个guest用户,默认用户名和密码都是guest。 出于安全考虑,建议创建新的管理员账户并删除或禁用guest账户。

rabbitmqctl delete_user guest
rabbitmqctl add_user admin your_admin_password
rabbitmqctl set_user_tags admin administrator
rabbitmqctl set_permissions -p / admin ".*" ".*" ".*"

其中, your_admin_password是你为管理员账户设置的密码,/是默认的虚拟主机名称。 操作完成后查看用户列表:

sudo rabbitmqctl list_users
Listing users ...
user    tags
admin   [administrator]

访问管理页面

http://<your_ip_address>:15672/

示例: 使用python的pika库操作rabbitmq

pip3 install pika

send.py

import pika

credentials = pika.PlainCredentials("admin", "your_password")
connection = pika.BlockingConnection(pika.ConnectionParameters('localhost', credentials=credentials))
channel = connection.channel()
channel.queue_declare(queue='hello')
channel.basic_publish(exchange='',
                      routing_key='hello',
                      body='Hello World!')
print(" [x] Sent 'Hello World!'")
connection.close()

receive.py

#!/usr/bin/env python
import pika

credentials = pika.PlainCredentials("admin", "your_password@xdr")
connection = pika.BlockingConnection(pika.ConnectionParameters('localhost', credentials=credentials))

channel = connection.channel()

channel.queue_declare(queue='hello')

def callback(ch, method, properties, body):
    print(" [x] Received %r" % body)

channel.basic_consume(queue="hello", on_message_callback=callback, auto_ack=True)

print(' [*] Waiting for messages. To exit press CTRL+C')
channel.start_consuming()

参考

【1】 RockyLinux 安装RabbitMQ
【2】 使用python的pika库来操作rabbitmq


http://www.kler.cn/a/448276.html

相关文章:

  • 【学习记录】浏览器指纹相关学习记录(指纹介绍、获取指纹、修改指纹、随机指纹保护隐私等)
  • 内核执行时动态的vmlinux的反汇编解析方法及static_branch_likely机制
  • 代码加入SFTP JAVA ---(小白篇3)
  • node express服务器配置orm框架sequilize
  • Redis常见阻塞原因总结
  • 5G 模组 RG500Q常用AT命令
  • 设计模式之结构型
  • 【ArcGIS Pro微课1000例】0064:栅格目录、栅格数据集、镶嵌数据集
  • 怎样在html中异步加载js文件,以避免js文件太大而影响页面打开速度?
  • 【Tomcat运行startup.bat闪退】
  • Connecting to Oracle 11g Database in Python
  • 1.gitlab 服务器搭建流程
  • 在 Django 中使用 SMTP 发送邮件是一个常见的需求
  • Python——turtle库(海龟绘图)介绍与使用
  • javaEE-多线程编程-3
  • EdgeX Core Service 核心服务之 Core Command 命令
  • Redis梳理
  • 计算机视觉目标检测——DETR(End-to-End Object Detection with Transformers)
  • 自然语言处理学什么
  • 前端开放性技术面试—面试题
  • 虚拟世界中的社交互动:Facebook在元宇宙中的发展路径
  • CNN分类-卷积神经网络(Convolutional Neural Network)
  • 【C语言】倒序输出
  • uniapp input的触发事件
  • robots协议
  • 使用Python和OpenCV进行双目摄像头测距的详细教程及源代码