1. 概述
本文是总结给予k8s的rabbitmq3.11.11集群的mqtt搭建
rabbitmq集群搭建详见前一篇文章:kubernetes 集群部署rabbimq3.11.11
2. 自动创建mqtt账号密码
wrapper-entrypoint.sh
#!/usr/bin/env bash
(sleep 20; \
admin_user=bbbbbb;\
admin_passwd=111111;\
rabbitmqctl add_user $admin_user $admin_passwd; \
rabbitmqctl set_user_tags mqtt_admin administrator; \
rabbitmqctl set_permissions -p / mqtt_admin ".*" ".*" ".*"; \
rabbitmqadmin -u $admin_user -p $admin_passwd declare exchange --vhost='/' name=exchange_mqtt_topic type=topic auto_delete=false durable=true;\
) &
# Call original entrypoint
exec docker-entrypoint.sh rabbitmq-server $@
这个脚本是准备在服务器起来以后的处理流程:
先等待20s
设置管理员bbbbbb的密码为111111,
创建exchange:exchange_mqtt_topic
Dockerfile
FROM rabbitmq:3.11.11-management-alpine
COPY wrapper-entrypoint.sh /
# 开启插件 + 设置mqtt登录用户和权限
RUN chmod a+x /wrapper-entrypoint.sh
EXPOSE 1883 8883 15675
ENTRYPOINT ["/wrapper-entrypoint.sh"]
重新基于wrapper-entrypoint.sh编译一个镜像,这样每个容器在起来20s以后就可以创建bbbbbb的账号了
3. ConfigMap配置文件修改
apiVersion: v1
kind: ConfigMap
metadata:
name: rabbitmq-config
namespace: rabbitmq
data:
enabled_plugins: |
[rabbitmq_management,rabbitmq_mqtt,rabbitmq_web_mqtt,rabbitmq_peer_discovery_k8s].
rabbitmq.conf: |
## Cluster formation. See https://www.rabbitmq.com/cluster-formation.html to learn more.
cluster_formation.peer_discovery_backend = k8s
cluster_formation.k8s.host = kubernetes.default.svc.cluster.local
## Service name is rabbitmq by default but can be overridden using the cluster_formation.k8s.service_name key if needed
cluster_formation.k8s.service_name = rabbitmq-internal
## It is possible to append a suffix to peer hostnames returned by Kubernetes using cluster_formation.k8s.hostname_suffix
cluster_formation.k8s.hostname_suffix = .rabbitmq-internal.rabbitmq.svc.cluster.local
## Should RabbitMQ node name be computed from the pod's hostname or IP address?
## IP addresses are not stable, so using [stable] hostnames is recommended when possible.
## Set to "hostname" to use pod hostnames.
## When this value is changed, so should the variable used to set the RABBITMQ_NODENAME
## environment variable.
cluster_formation.k8s.address_type = hostname
## How often should node cleanup checks run?
cluster_formation.node_cleanup.interval = 30
## Set to false if automatic removal of unknown/absent nodes
## is desired. This can be dangerous, see
## * https://www.rabbitmq.com/cluster-formation.html#node-health-checks-and-cleanup
## * https://groups.google.com/forum/#!msg/rabbitmq-users/wuOfzEywHXo/k8z_HWIkBgAJ
cluster_formation.node_cleanup.only_log_warning = true
cluster_partition_handling = autoheal
## See https://www.rabbitmq.com/ha.html#master-migration-data-locality
queue_master_locator=min-masters
## This is just an example.
## This enables remote access for the default user with well known credentials.
## Consider deleting the default user and creating a separate user with a set of generated
## credentials instead.
## Learn more at https://www.rabbitmq.com/access-control.html#loopback-users
loopback_users.guest = false
## https://www.rabbitmq.com/memory.html#configuring-threshold
vm_memory_high_watermark.relative = 0.6
## On first start RabbitMQ will create a vhost and a user. These
## config items control what gets created.
## Relevant doc guide: https://rabbitmq.com/access-control.html
##
default_vhost = /
default_user = aaaaa
default_pass = 11111
# =======================================
# MQTT section
# =======================================
## TCP listener settings.
##
# mqtt.listeners.tcp.1 = 127.0.0.1:61613
# mqtt.listeners.tcp.2 = ::1:61613
mqtt.listeners.tcp.default = 1883
## Set the default user name and password used for anonymous connections (when client
## provides no credentials). Anonymous connections are highly discouraged!
##
mqtt.default_user = bbbbbb
mqtt.default_pass = 111111
## Enable anonymous connections. If this is set to false, clients MUST provide
## credentials in order to connect. See also the mqtt.default_user/mqtt.default_pass
## keys. Anonymous connections are highly discouraged!
##
mqtt.allow_anonymous = false
## If you have multiple vhosts, specify the one to which the
## adapter connects.
##
mqtt.vhost = /
## Specify the exchange to which messages from MQTT clients are published.
##
mqtt.exchange = exchange_mqtt_topic
## Specify TTL (time to live) to control the lifetime of non-clean sessions.
##
mqtt.subscription_ttl = 1800000
## Set the prefetch count (governing the maximum number of unacknowledged
## messages that will be delivered).
##
mqtt.prefetch = 10
以上设置了:
-
enabled_plugins添加rabbitmq_mqtt,rabbitmq_web_mqtt插件
- mqtt端口设置为1883
- mqtt的默认用户为bbbbbb,密码为111111,这里是使用用户
- mqtt不允许匿名登陆,allow_anonymous=false
- mqtt消息转成amqp的exchange:exchange_mqtt_topic
这样起来以后就支持mqtt了。
标签:11,default,插件,rabbimq3.11,##,rabbitmq,cluster,mqtt,user From: https://www.cnblogs.com/zhanchenjin/p/17283099.html