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 安裝
ℹ️ 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
- MQTT Server 透過 Helm Chart EMQX 安裝,安裝於:伺服器/Edge 端 K3S 的
emqx
namespace;- 安裝模式:單節點
- EMQX 版本:4.4.0
- EMQX 例項:1 個
- EMQX 資料已持久化,容器資料位於:
/opt/emqx/data/mnesia
, 持久化後的資料位於:/data/rancher/k3s/storage
- EMQX UI 為:
<locabalaner-ip>:18083
, 賬號密碼預設為:admin
和public
- MQTT 地址為:
<locabalaner-ip>:1883
三人行, 必有我師; 知識共享, 天下為公. 本文由東風微鳴技術部落格 EWhisper.cn 編寫.