关于运维:使用-Helm-安装-MQTT-服务器EMQX

38次阅读

共计 4513 个字符,预计需要花费 12 分钟才能阅读完成。

EMQX

ℹ️ Info:

应用 EMQX

通过 Helm3 在 Kubernetes 上部署 EMQX 4.0 集群 | EMQ

emqx/deploy/charts/emqx at main-v4.4 · emqx/emqx (github.com)

emqx/values.yaml at main-v4.4 · emqx/emqx (github.com)

emqx/emqx-operator: A Kubernetes Operator for EMQ X Broker (github.com)

配置项 | EMQX 文档

EMQX 装置

ℹ️ Info:

即 EMQX 服务器端。

> helm repo add emqx https://repos.emqx.io/charts
"emqx" has been added to your repositories
> helm repo update
Hang tight while we grab the latest from your chart repositories...
...Successfully got an update from the "emqx" chart repository
Update Complete. ⎈Happy Helming!⎈
> helm search repo emqx
NAME                    CHART VERSION   APP VERSION     DESCRIPTION                              
emqx/emqx               4.4.0           4.4.0           A Helm chart for EMQ X                   
emqx/emqx-ee            4.4.1           4.4.1           A Helm chart for EMQ X                   
emqx/emqx-operator      1.0.1           1.1.2           A Helm chart for EMQX Operator Controller
emqx/kuiper             0.9.0           0.9.0           A lightweight IoT edge analytic software

装置:

vi values.yaml:

replicaCount: 1
image:
  repository: emqx/emqx
  pullPolicy: IfNotPresent

recreatePods: false

podManagementPolicy: Parallel

extraEnv: []

extraEnvFrom: []

extraArgs: []

extraVolumes: []

extraVolumeMounts: []

persistence:
  enabled: true
  size: 8Gi
  storageClass: "local-path"
  accessMode: ReadWriteOnce

resources: {}
  # limits:
  #   cpu: 500m
  #   memory: 512Mi
  # requests:
  #   cpu: 500m
  #   memory: 512Mi

# Containers that run before the creation of EMQ X containers. They can contain utilities or setup scripts.
initContainers: {}
  # - name: mysql-probe
  #   image: alpine
  #   command: ["sh", "-c", "for i in $(seq 1 300); do nc -zvw1 mysql 3306 && exit 0 || sleep 3; done; exit 1"]

## EMQ X configuration item, see the documentation (https://hub.docker.com/r/emqx/emqx)
emqxConfig:
  EMQX_NAME:  "{{.Release.Name}}"
  ## Cluster discovery by k8s
  EMQX_CLUSTER__DISCOVERY: "k8s"
  EMQX_CLUSTER__K8S__APP_NAME: "{{.Release.Name}}"
  EMQX_CLUSTER__K8S__APISERVER: "https://kubernetes.default.svc:443"
  EMQX_CLUSTER__K8S__SERVICE_NAME: "{{.Release.Name}}-headless"
  EMQX_CLUSTER__K8S__NAMESPACE: "{{.Release.Namespace}}"
  EMQX_CLUSTER__K8S__ADDRESS_TYPE: "hostname"
  EMQX_CLUSTER__K8S__SUFFIX: "svc.cluster.local"

emqxAclConfig: >
  {allow, {user, "dashboard"}, subscribe, ["$SYS/#"]}.
  {allow, {ipaddr, "127.0.0.1"}, pubsub, ["$SYS/#", "#"]}.
  {deny, all, subscribe, ["$SYS/#", {eq, "#"}]}.
  {allow, all}.

emqxLoadedPlugins: >
  {emqx_management, true}.
  {emqx_recon, true}.
  {emqx_retainer, true}.
  {emqx_dashboard, true}.
  {emqx_telemetry, true}.
  {emqx_rule_engine, true}.
  {emqx_bridge_mqtt, false}.

emqxLoadedModules: >
  {emqx_mod_acl_internal, true}.
  {emqx_mod_presence, true}.
  {emqx_mod_trace, false}.
  {emqx_mod_st_statistics, false}.
  {emqx_mod_delayed, false}.
  {emqx_mod_rewrite, false}.
  {emqx_mod_subscription, false}.
  {emqx_mod_topic_metrics, false}.

service:
  type: LoadBalancer
  mqtt: 1883
  mqttssl: 8883
  mgmt: 8081
  ws: 8083
  wss: 8084
  dashboard: 18083

podSecurityContext:
  enabled: true
  fsGroup: 1000
  fsGroupChangePolicy: Always
  runAsUser: 1000
  supplementalGroups:
    - 1000

containerSecurityContext:
  enabled: true
  runAsNonRoot: true
  runAsUser: 1000
helm install emqx emqx/emqx --namespace emqx --create-namespace -f ./values.yaml --wait

装置输入:

NAME: emqx
LAST DEPLOYED: Sat Feb 19 20:48:49 2022
NAMESPACE: emqx
STATUS: deployed
REVISION: 1
TEST SUITE: None

EMQX 验证

装置后查看 EMQX 集群状况:

# kubectl -n emqx get pods
NAME               READY   STATUS    RESTARTS   AGE
svclb-emqx-kbl22   6/6     Running   0          41s
emqx-0             1/1     Running   0          41s

# kubectl -n emqx  exec -it emqx-0 -- emqx_ctl cluster status
Cluster status: #{running_nodes =>
                      ['emqx@emqx-0.emqx-headless.emqx.svc.cluster.local'],
                  stopped_nodes => []}

# kubectl -n emqx get svc
NAME            TYPE           CLUSTER-IP      EXTERNAL-IP      PORT(S)                                                                                      AGE
emqx-headless   ClusterIP      None            <none>           1883/TCP,8883/TCP,8081/TCP,8083/TCP,8084/TCP,18083/TCP,4370/TCP                              86s
emqx            LoadBalancer   10.43.193.192   10.<none> .245   1883:31558/TCP,8883:31122/TCP,8081:31592/TCP,8083:30322/TCP,8084:31095/TCP,18083:32427/TCP   86s

拜访控制台:

拜访 URL:18083,输出默认用户名:admin,默认明码:public,登陆 EMQX dashboard。

MQTT 音讯验证:

能够通过 MQTT X: Cross-platform MQTT 5.0 Desktop Client 连贯并进行收发验证。

🎉至此,EMQX(即 MQTT 服务器端)装置实现。

EMQX 卸载

首先通过 Helm 卸载 EMQX 除存储外的所有资源:

helm uninstall emqx --namespace emqx

之后再通过 Rancher UI 或 kubectl 命令删除存储:

kubectl delete -n emqx pvc emqx-data-emqx-0

EMQX Edge

ℹ️ Info:

即 EMQX Edge 端版本

Edge 端资源较小,存储空间等能够适当设置低一点。如:size: 5Gi

部署 EMQX Edge 集群指定 image.repository=emqx/emqx-edge,其余设置与部署 EMQX 集群保持一致

...
image:
  repository: emqx/emqx-edge
...
persistence:
...
  size: 8Gi
...

🎉至此,EMQX Edge(即 MQTT Edge 端 Server) 装置实现。

EMQX Edge 离线装置

通过操作机(能够联网或能够通过代理上网)pull EMQX 的容器镜像到对应的镜像仓库:

ctr -n k8s.io images push --plain-http --platform=linux/arm64/v8 <local-registry>:5000/emqx/emqx-edge:4.4.0

而后失常装置即可:

🔥 Tip:

前提是本地已装置镜像仓库,且本地 docker 或其余容器运行时曾经配置本地镜像仓库地址为 <docker.io> 的 mirror

helm install emqx emqx/emqx --namespace emqx --create-namespace -f ./values.yaml --wait

🎉至此,EMQX Edge(即 MQTT Edge 端 Server) 离线形式装置实现。

总结

MQTT

  1. MQTT Server 通过 Helm Chart EMQX 装置,装置于:服务器 /Edge 端 K3S 的 emqx namespace;

    1. 装置模式:单节点
    2. EMQX 版本:4.4.0
    3. EMQX 实例:1 个
    4. EMQX 数据已长久化,容器数据位于:/opt/emqx/data/mnesia, 长久化后的数据位于:/data/rancher/k3s/storage
  2. EMQX UI 为:<locabalaner-ip>:18083, 账号密码默认为:adminpublic
  3. MQTT 地址为:<locabalaner-ip>:1883

三人行, 必有我师; 常识共享, 天下为公. 本文由东风微鸣技术博客 EWhisper.cn 编写.

正文完
 0