使用 Helm 安装 MQTT 服务器-EMQX

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。

使用 Helm 安装 MQTT 服务器-EMQX

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 编写.

发表评论

相关文章