K8S 上部署 Emqx

文章目录

      • 安装方式一:快速部署
      • 安装方式二:定制化部署
        • 1. 使用 Pod 直接部署 EMQX Broker
        • 2. 使用 Deoloyment 部署 Pod
        • 3. 使用 Services 公开 EMQX Broker Pod 服务
        • 4. 通过 kubernetes 自动集群 EMQX MQTT 服务器
        • 5. 修改 EMQX Broker 的配置
        • 6. 赋予 Pod 访问 kubernetes apiserver 的权限
        • 7. 持久化 EMQX Broker 集群
        • 8. StatefulSet
        • 9. StorageClasses、PersistentVolume 和 PersistentVolumeClaim

安装方式一:快速部署

  添加 helm 仓库:

$ helm repo add emqx https://repos.emqx.io/charts

# 查询 EMQX
$ helm search repo emqx

  启动 EMQX 集群,设置 service.type=NodePort

$ helm install my-emqx emqx/emqx --set service.type=NodePort
NAME: my-emqx
LAST DEPLOYED: Thu Jul 11 10:56:16 2024
NAMESPACE: default
STATUS: deployed
REVISION: 1
TEST SUITE: None

  查看 EMQX 集群情况:

$ kubectl get pods -o wide
NAME                       READY   STATUS              RESTARTS       AGE    IP              NODE        NOMINATED NODE   READINESS GATES
my-emqx-0                  0/1     ContainerCreating   0              12s    <none>          master-01   <none>           <none>
my-emqx-1                  0/1     ContainerCreating   0              12s    <none>          worker-02   <none>           <none>
my-emqx-2                  0/1     ContainerCreating   0              12s    <none>          worker-01   <none>           <none>

$ kubectl get pods -o wide
NAME                       READY   STATUS    RESTARTS       AGE    IP              NODE        NOMINATED NODE   READINESS GATES
my-emqx-0                  1/1     Running   0              3m7s   172.20.32.158   master-01   <none>           <none>
my-emqx-1                  1/1     Running   0              3m7s   172.20.58.232   worker-02   <none>           <none>
my-emqx-2                  1/1     Running   0              3m7s   172.20.85.250   worker-01   <none>           <none>

$ kubectl exec -it my-emqx-0 -- emqx_ctl status
Node 'my-emqx@my-emqx-0.my-emqx-headless.default.svc.cluster.local' 5.7.1 is started

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

  查看 EMQX service:

$ kubectl get svc -o wide
NAME                             TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)
service/my-emqx                  NodePort    10.68.183.22    <none>        1883:32596/TCP,8883:31933/TCP,8083:32522/TCP,8084:32535/TCP,18083:32717/TCP   10m     app.kubernetes.io/instance=my-emqx,app.kubernetes.io/name=emqx
service/my-emqx-headless         ClusterIP   None            <none>        1883/TCP,8883/TCP,8083/TCP,8084/TCP,18083/TCP,4370/TCP                        10m     app.kubernetes.io/instance=my-emqx,app.kubernetes.io/name=emqx

# 也可以执行该命令查看全部
$ sudo kubectl get all -o wide
NAME                           READY   STATUS    RESTARTS       AGE    IP              NODE        NOMINATED NODE   READINESS GATES
pod/my-emqx-0                  1/1     Running   0              10m    172.20.32.158   master-01   <none>           <none>
pod/my-emqx-1                  1/1     Running   0              10m    172.20.58.232   worker-02   <none>           <none>
pod/my-emqx-2                  1/1     Running   0              10m    172.20.85.250   worker-01   <none>           <none>

NAME                             TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)
service/my-emqx                  NodePort    10.68.183.22    <none>        1883:32596/TCP,8883:31933/TCP,8083:32522/TCP,8084:32535/TCP,18083:32717/TCP   10m     app.kubernetes.io/instance=my-emqx,app.kubernetes.io/name=emqx
service/my-emqx-headless         ClusterIP   None            <none>        1883/TCP,8883/TCP,8083/TCP,8084/TCP,18083/TCP,4370/TCP                        10m     app.kubernetes.io/instance=my-emqx,app.kubernetes.io/name=emqx

NAME                                      READY   AGE    CONTAINERS   IMAGES
statefulset.apps/my-emqx                  3/3     10m    emqx         emqx/emqx:5.7.1

  可以看到 my-emqx 的 18083 端口对应的宿主机的 32717 端口。(NodePort 在每次部署的时候都会变化,以实际部署时为准。)

  访问 Kubernetes 的任意一台节点 IP 的 32717 端口,输入默认用户名:admin,默认密码:public,登陆 EMQX dashboard。

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述
  删除 EMQX 集群:

$ helm uninstall my-emqx
release "my-emqx" uninstalled

参考:
在K8S上部署EMQX企业版集群

安装方式二:定制化部署

  参考自:从零开始建立 EMQX MQTT 服务器的 K8S 集群

1. 使用 Pod 直接部署 EMQX Broker

  EMQX Broker 在 docker hub 上提供了镜像, 因此可以很方便的在单个的 pod 上部署 EMQX Broker,使用 kubectl run 命令创建一个运行着 EMQX Broker 的 Pod:

$ kubectl run emqx --image=emqx/emqx:v4.1-rc.1  --generator=run-pod/v1
error: unknown flag: --generator
See 'kubectl run --help' for usage.

$ kubectl run emqx --image=emqx/emqx:v4.1-rc.1
pod/emqx created

  查看 EMQX Broker 的状态:

$ kubectl get pods -o wide
NAME                       READY   STATUS              RESTARTS       AGE    IP              NODE        NOMINATED NODE   READINESS GATES
emqx                       0/1     ContainerCreating   0              8s     <none>          master-01   <none>           <none>

$ kubectl get pods -o wide
NAME                       READY   STATUS    RESTARTS       AGE    IP              NODE        NOMINATED NODE   READINESS GATES
emqx                       1/1     Running   0              97s    172.20.32.139   master-01   <none>           <none>

$ kubectl exec emqx -- emqx_ctl status
Node 'emqx@172.20.32.139' is started
emqx 4.1-rc.1 is running

  删除 Pod:

$ kubectl delete pods emqx
pod "emqx" deleted

  Pod 并不是被设计成一个持久化的资源,它不会在调度失败,节点崩溃,或者其他回收中(比如因为资源的缺乏,或者其他的维护中)幸存下来,因此,还需要一个控制器来管理 Pod。

2. 使用 Deoloyment 部署 Pod

  Deployment 为 Pod 和 ReplicaSet 提供了一个声明式定义(declarative)方法,用来替代以前的 ReplicationController 来方便的管理应用。典型的应用场景包括:

  • 定义Deployment来创建Pod和ReplicaSet
  • 滚动升级和回滚应用
  • 扩容和缩容
  • 暂停和继续Deployment

  使用 Deployment 部署一个 EMQX Broker Pod:

$ vim deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: emqx-deployment
  labels:
    app: emqx
spec:
  replicas: 1
  selector:
    matchLabels:
      app: emqx
  template:
    metadata:
      labels:
        app: emqx
    spec:
      containers:
      - name: emqx
        image: emqx/emqx:v4.1-rc.1
        ports:
        - name: mqtt
          containerPort: 1883
        - name: mqttssl
          containerPort: 8883
        - name: mgmt
          containerPort: 8081
        - name: ws
          containerPort: 8083
        - name: wss
          containerPort: 8084
        - name: dashboard
          containerPort: 18083

  部署 Deployment:

$ kubectl apply -f deployment.yaml
deployment.apps/emqx-deployment created

  查看部署情况:

$ kubectl get deployment
NAME              READY   UP-TO-DATE   AVAILABLE   AGE
emqx-deployment   0/1     1            0           49s

$ kubectl get pods
NAME                               READY   STATUS    RESTARTS       AGE
emqx-deployment-75bd4f75b6-wf9sh   1/1     Running   0              73s

$ kubectl exec pod/emqx-deployment-75bd4f75b6-wf9sh -- emqx_ctl status
Node 'emqx-deployment-75bd4f75b6-wf9sh@172.20.58.199' is started
emqx 4.1-rc.1 is running

$ kubectl get pods
NAME                               READY   STATUS    RESTARTS       AGE
emqx-deployment-75bd4f75b6-8njhv   1/1     Running   0              55s

  尝试手动删除 Pod:

$ kubectl delete pods emqx-deployment-75bd4f75b6-8njhv
pod "emqx-deployment-75bd4f75b6-8njhv" deleted

$ kubectl get pods
NAME                              READY   STATUS    RESTARTS   AGE
emqx-deployment-68fcb4bfd6-2nhh6   1/1     Running   0          59s

  输出结果表明成功用 Deployment 部署了 EMQX Broker Pod,即使是此 Pod 被意外终止,Deployment 也会重新创建一个新的 Pod。

3. 使用 Services 公开 EMQX Broker Pod 服务

  Kubernetes Pods 是有生命周期的。他们可以被创建,而且销毁不会再启动。 如果使用 Deployment 来运行应用程序,则它可以动态创建和销毁 Pod。

  每个 Pod 都有自己的 IP 地址,但是在 Deployment 中,在同一时刻运行的 Pod 集合可能与稍后运行该应用程序的 Pod 集合不同。

  这导致了一个问题:如果使用 EMQX Broker Pod 为 MQTT 客户端提供服务,那么客户端应该如何如何找出并跟踪要连接的 IP 地址,以便客户端使用 EMQX Broker 服务呢?

  答案是:Service

  Service 是将运行在一组 Pods 上的应用程序公开为网络服务的抽象方法。

  使用 Service 将 EMQX Broker Pod 公开为网络服务:

vim service.yaml
apiVersion: v1
kind: Service
metadata:
  name: emqx-service
spec:
  selector:
    app: emqx
  ports:
    - name: mqtt
      port: 1883
      protocol: TCP
      targetPort: mqtt
    - name: mqttssl
      port: 8883
      protocol: TCP
      targetPort: mqttssl
    - name: mgmt
      port: 8081
      protocol: TCP
      targetPort: mgmt
    - name: ws
      port: 8083
      protocol: TCP
      targetPort: ws
    - name: wss
      port: 8084
      protocol: TCP
      targetPort: wss
    - name: dashboard
      port: 18083
      protocol: TCP
      targetPort: dashboard

  部署 Service:

$ kubectl apply -f service.yaml
service/emqx-service created

  查看部署情况

$ kubectl get svc
NAME                     TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)                                                  AGE
emqx-service             ClusterIP   10.68.228.164   <none>        1883/TCP,8883/TCP,8081/TCP,8083/TCP,8084/TCP,18083/TCP   16s

  使用 Service 提供的 IP 查看 EMQX Broker 的 API

$ curl 10.68.228.164:8081/status
Node emqx-deployment-75bd4f75b6-8njhv@172.20.32.140 is started
emqx is running

  至此,单个 EMQX Broker 节点在 kubernetes 上部署完毕,通过 Deployment 管理 EMQX Broker Pod,通过 Service 将 EMQX Broker 服务暴露出去。

4. 通过 kubernetes 自动集群 EMQX MQTT 服务器

  上文中通过 Deployment 部署了单个的 EMQX Broker Pod,通过 Deployment 扩展 Pod 的数量是极为方便的,执行 kubectl scale deployment ${deployment_name} --replicas ${numer} 命令即可扩展 Pod 的数量,下面将 EMQX Broker Pod 扩展为 3 个:

$ kubectl scale deployment emqx-deployment --replicas 3
deployment.apps/emqx-deployment scaled

$ kubectl get pods
NAME                               READY   STATUS              RESTARTS       AGE
emqx-deployment-75bd4f75b6-8njhv   1/1     Running             0              8m41s
emqx-deployment-75bd4f75b6-kjv22   0/1     ContainerCreating   0              12s
emqx-deployment-75bd4f75b6-thcbv   1/1     Running             0              12s

$ kubectl exec emqx-deployment-75bd4f75b6-8njhv -- emqx_ctl status
Node 'emqx-deployment-75bd4f75b6-8njhv@172.20.32.140' is started
emqx 4.1-rc.1 is running

$ kubectl exec emqx-deployment-75bd4f75b6-8njhv -- emqx_ctl cluster status
Cluster status: #{running_nodes =>
                      ['emqx-deployment-75bd4f75b6-8njhv@172.20.32.140'],
                  stopped_nodes => []}

  可以看到 EMQX Broker Pod 的数量被扩展为 3 个,但是每个 Pod 都是独立的,并没有集群,接下来尝试通过 kubernetes 自动集群 EMQX Broker Pod。

5. 修改 EMQX Broker 的配置

  查看 EMQX Broker 文档中关于 自动集群 的内容,可以看到需要修改 EMQX Broker 的配置:

cluster.discovery = kubernetes
cluster.kubernetes.apiserver = http://10.110.111.204:8080
cluster.kubernetes.service_name = ekka
cluster.kubernetes.address_type = ip
cluster.kubernetes.app_name = ekka

  其中 cluster.kubernetes.apiserverkubernetes apiserver 的地址,可以通过 kubectl cluster-info 命令获取,cluster.kubernetes.service_name 为上文中 Service 的 name, cluster.kubernetes.app_name 为 EMQX Broker 的 node.name@ 符号之前的部分,所以还需要将集群中 EMQX Broker 设置为统一的 node.name 的前缀。

  EMQX Broker 的 docker 镜像提供了通过环境变量修改配置的功能,具体可以查看 docker hub 或 Github。

$ vim deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: emqx-deployment
  labels:
    app: emqx
spec:
  replicas: 3
  selector:
    matchLabels:
      app: emqx
  template:
    metadata:
      labels:
        app: emqx
    spec:
      containers:
      - name: emqx
        image: emqx/emqx:v4.1-rc.1
        ports:
        - name: mqtt
          containerPort: 1883
        - name: mqttssl
          containerPort: 8883
        - name: mgmt
          containerPort: 8081
        - name: ws
          containerPort: 8083
        - name: wss
          containerPort: 8084
        - name: dashboard
          containerPort: 18083
        env:
        - name: EMQX_NAME
          value: emqx
        - name: EMQX_CLUSTER__DISCOVERY
          value: k8s
        - name: EMQX_CLUSTER__K8S__APP_NAME
          value: emqx
        - name: EMQX_CLUSTER__K8S__SERVICE_NAME
          value: emqx-service
        - name: EMQX_CLUSTER__K8S__APISERVER
          value: "https://kubernetes.default.svc:443"
        - name: EMQX_CLUSTER__K8S__NAMESPACE
          value: default

  因为 kubectl scale deployment ${deployment_name} --replicas ${numer} 命令不会修改 yaml 文件,所以修改 yaml 时需要设置 spec.replicas: 3

  Pod 中内建 kubernetes 的 DNS 规则,所以 https://kubernetes.default.svc:443 会被解析为 kubernetes apiserver 的地址。

  删除之前的 Deployment,重新部署:

$ kubectl delete deployment emqx-deployment
deployment.apps "emqx-deployment" deleted

$ root@k8s-master01:/home/ubuntu/huiq/emqx# kubectl apply -f deployment.yaml
deployment.apps/emqx-deployment created
6. 赋予 Pod 访问 kubernetes apiserver 的权限

  上文部署 Deployment 之后,查看 EMQX Broker 的状态,可以看到 EMQX Broker 虽然成功启动了,但是依然没有集群成功,查看 EMQX Broker Pod 的 log:

$ kubectl get pods
NAME                               READY   STATUS    RESTARTS       AGE
emqx-deployment-64d5cc575c-dsrgj   1/1     Running   0              41s
emqx-deployment-64d5cc575c-k4twn   1/1     Running   0              41s
emqx-deployment-64d5cc575c-ktdqk   1/1     Running   0              41s

$ kubectl exec emqx-deployment-64d5cc575c-dsrgj -- emqx_ctl status
Node 'emqx@172.20.58.200' is started
emqx 4.1-rc.1 is running

$ kubectl exec emqx-deployment-64d5cc575c-dsrgj -- emqx_ctl cluster status
Cluster status: #{running_nodes => ['emqx@172.20.58.200'],stopped_nodes => []}

root@k8s-master01:/home/ubuntu/huiq/emqx# kubectl logs emqx-deployment-64d5cc575c-dsrgj
...
(emqx@172.20.58.200)1> 2024-07-11 08:14:37.525 [error] Ekka(AutoCluster): Discovery error: {403,"{\"kind\":\"Status\",\"apiVersion\":\"v1\",\"metadata\":{},\"status\":\"Failure\",\"message\":\"endpoints \\\"emqx-service\\\" is forbidden: User \\\"system:serviceaccount:default:default\\\" cannot get resource \\\"endpoints\\\" in API group \\\"\\\" in the namespace \\\"default\\\"\",\"reason\":\"Forbidden\",\"details\":{\"name\":\"emqx-service\",\"kind\":\"endpoints\"},\"code\":403}\n"}
...

  Pod 因为权限问题在访问 kubernetes apiserver 的时候被拒绝,返回 HTTP 403,所以集群失败。

  普通 Pod 是无法访问 kubernetes apiserver 的,解决这个问题有两种方法,一种是开放 kubernetes apiserver 的 http 接口,但是这种方法存在一定的安全隐患,另外一种是通过 ServiceAccount、Role 和 RoleBinding 配置 RBAC 鉴权。

$ vim rbac.yaml
apiVersion: v1
kind: ServiceAccount
metadata:
  namespace: default
  name: emqx
---
kind: Role
apiVersion: rbac.authorization.kubernetes.io/v1beta1
metadata:
  namespace: default
  name: emqx
rules:
- apiGroups:
  - ""
  resources:
  - endpoints 
  verbs: 
  - get
  - watch
  - list
---
kind: RoleBinding
apiVersion: rbac.authorization.kubernetes.io/v1beta1
metadata:
  namespace: default
  name: emqx
subjects:
  - kind: ServiceAccount
    name: emqx
    namespace: default
roleRef:
  kind: Role
  name: emqx
  apiGroup: rbac.authorization.kubernetes.io

  部署相应的资源:

$ kubectl apply -f rbac.yaml
serviceaccount/emqx created
resource mapping not found for name: "emqx" namespace: "default" from "rbac.yaml": no matches for kind "Role" in version "rbac.authorization.kubernetes.io/v1beta1"
ensure CRDs are installed first
resource mapping not found for name: "emqx" namespace: "default" from "rbac.yaml": no matches for kind "RoleBinding" in version "rbac.authorization.kubernetes.io/v1beta1"
ensure CRDs are installed first

$ kubectl explain role
GROUP:      rbac.authorization.k8s.io
KIND:       Role
VERSION:    v1

$ kubectl explain RoleBinding
GROUP:      rbac.authorization.k8s.io
KIND:       RoleBinding
VERSION:    v1

  解决上面的问题,重新编辑 rbac.yaml 文件:

apiVersion: v1
kind: ServiceAccount
metadata:
  namespace: default
  name: emqx
---
kind: Role
apiVersion: rbac.authorization.k8s.io/v1
metadata:
  namespace: default
  name: emqx
rules:
- apiGroups:
  - ""
  resources:
  - endpoints
  verbs:
  - get
  - watch
  - list
---
kind: RoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
  namespace: default
  name: emqx
subjects:
  - kind: ServiceAccount
    name: emqx
    namespace: default
roleRef:
  kind: Role
  name: emqx
  apiGroup: rbac.authorization.k8s.io

$ kubectl delete serviceaccount emqx
serviceaccount "emqx" deleted
$ kubectl delete role emqx
role.rbac.authorization.k8s.io "emqx" deleted
$ kubectl delete rolebinding emqx
rolebinding.rbac.authorization.k8s.io "emqx" deleted

$ kubectl apply -f rbac.yaml
serviceaccount/emqx created
role.rbac.authorization.k8s.io/emqx created
rolebinding.rbac.authorization.k8s.io/emqx created

$ kubectl get serviceaccount
NAME                    SECRETS   AGE
emqx                    0         16s

$ kubectl get role
NAME   CREATED AT
emqx   2024-07-11T08:45:48Z

$ kubectl get rolebinding
NAME   ROLE        AGE
emqx   Role/emqx   51s

  修改 Deployment 的 yaml 文件,增加 spec.template.spec.serviceAccountName,并重新部署:

 vim deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: emqx-deployment
  labels:
    app: emqx
spec:
  replicas: 3
  selector:
    matchLabels:
      app: emqx
  template:
    metadata:
      labels:
        app: emqx
    spec:
      serviceAccountName: emqx
      containers:
      - name: emqx
        image: emqx/emqx:v4.1-rc.1
        ports:
        - name: mqtt
          containerPort: 1883
        - name: mqttssl
          containerPort: 8883
        - name: mgmt
          containerPort: 8081
        - name: ws
          containerPort: 8083
        - name: wss
          containerPort: 8084
        - name: dashboard
          containerPort: 18083
        env:
        - name: EMQX_NAME
          value: emqx
        - name: EMQX_CLUSTER__DISCOVERY
          value: kubernetes
        - name: EMQX_CLUSTER__K8S__APP_NAME
          value: emqx
        - name: EMQX_CLUSTER__K8S__SERVICE_NAME
          value: emqx-service
        - name: EMQX_CLUSTER__K8S__APISERVER
          value: "https://kubernetes.default.svc:443"
        - name: EMQX_CLUSTER__K8S__NAMESPACE
          value: default

$ kubectl delete deployment emqx-deployment
deployment.apps "emqx-deployment" deleted
$ kubectl apply -f deployment.yaml
deployment.apps/emqx-deployment created

  查看状态:

$ kubectl get pods
NAME                               READY   STATUS    RESTARTS       AGE
emqx-deployment-7c4675f785-6r6dg   1/1     Running   0              28s
emqx-deployment-7c4675f785-cqbgh   1/1     Running   0              28s
emqx-deployment-7c4675f785-nghf6   1/1     Running   0              28s

$ kubectl exec emqx-deployment-7c4675f785-6r6dg  -- emqx_ctl status
Node 'emqx@127.0.0.1' not responding to pings.
command terminated with exit code 1

  尝试解决:本以为是文章里下划线写多了导致的,虽然 emqx 可以运行了但不是集群模式

$ vim deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: emqx-deployment
  labels:
    app: emqx
spec:
  replicas: 3
  selector:
    matchLabels:
      app: emqx
  template:
    metadata:
      labels:
        app: emqx
    spec:
      serviceAccountName: emqx
      containers:
      - name: emqx
        image: emqx/emqx:v4.1-rc.1
        ports:
        - name: mqtt
          containerPort: 1883
        - name: mqttssl
          containerPort: 8883
        - name: mgmt
          containerPort: 8081
        - name: ws
          containerPort: 8083
        - name: wss
          containerPort: 8084
        - name: dashboard
          containerPort: 18083
        env:
        - name: EMQX_NAME
          value: emqx
        - name: EMQX_CLUSTER_DISCOVERY
          value: kubernetes
        - name: EMQX_CLUSTER_K8S_APP_NAME
          value: emqx
        - name: EMQX_CLUSTER_K8S_SERVICE_NAME
          value: emqx-service
        - name: EMQX_CLUSTER_K8S_APISERVER
          value: "https://kubernetes.default.svc:443"
        - name: EMQX_CLUSTER_K8S_NAMESPACE
          value: default

$ kubectl delete deployment emqx-deployment
deployment.apps "emqx-deployment" deleted
$ kubectl apply -f deployment.yaml
deployment.apps/emqx-deployment created
$ kubectl get pods
NAME                               READY   STATUS    RESTARTS       AGE
emqx-deployment-794478ff56-2rqwp   1/1     Running   0              19s
emqx-deployment-794478ff56-4jnmt   1/1     Running   0              19s
emqx-deployment-794478ff56-m4mk4   1/1     Running   0              19s
$ kubectl exec emqx-deployment-794478ff56-2rqwp -- emqx_ctl status
Node 'emqx@172.20.85.238' is started
emqx 4.1-rc.1 is running
$ kubectl exec emqx-deployment-794478ff56-bzck8 -- emqx_ctl cluster status
Cluster status: #{running_nodes => ['emqx@172.20.85.244'],stopped_nodes => []}

  最终解决:文章里给留了个大坑,需要将 kubernetes 改为 k8s

$ vim deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: emqx-deployment
  labels:
    app: emqx
spec:
  replicas: 3
  selector:
    matchLabels:
      app: emqx
  template:
    metadata:
      labels:
        app: emqx
    spec:
      serviceAccountName: emqx
      containers:
      - name: emqx
        image: emqx/emqx:v4.1-rc.1
        ports:
        - name: mqtt
          containerPort: 1883
        - name: mqttssl
          containerPort: 8883
        - name: mgmt
          containerPort: 8081
        - name: ws
          containerPort: 8083
        - name: wss
          containerPort: 8084
        - name: dashboard
          containerPort: 18083
        env:
        - name: EMQX_NAME
          value: emqx
        - name: EMQX_CLUSTER__DISCOVERY
          value: k8s
        - name: EMQX_CLUSTER__K8S__APP_NAME
          value: emqx
        - name: EMQX_CLUSTER__K8S__SERVICE_NAME
          value: emqx-service
        - name: EMQX_CLUSTER__K8S__APISERVER
          value: "https://kubernetes.default.svc:443"
        - name: EMQX_CLUSTER__K8S__NAMESPACE
          value: default

$ kubectl delete deployment emqx-deployment
deployment.apps "emqx-deployment" deleted
$ kubectl apply -f deployment.yaml
deployment.apps/emqx-deployment created

$ kubectl get pods
NAME                               READY   STATUS    RESTARTS     AGE
emqx-deployment-5884fd896f-b6hz9   1/1     Running   0            3s
emqx-deployment-5884fd896f-hvd6v   1/1     Running   0            3s
emqx-deployment-5884fd896f-jv4ck   1/1     Running   0            3s

$ kubectl exec emqx-deployment-5884fd896f-b6hz9 -- emqx_ctl status
Node 'emqx@172.20.32.168' is started
emqx 4.1-rc.1 is running
$ kubectl exec emqx-deployment-5884fd896f-b6hz9 -- emqx_ctl cluster status
Cluster status: #{running_nodes =>
                      ['emqx@172.20.32.168','emqx@172.20.58.237',
                       'emqx@172.20.85.197'],
                  stopped_nodes => []}

  中止一个 Pod:

$ kubectl delete pods emqx-deployment-5884fd896f-b6hz9 --force
Warning: Immediate deletion does not wait for confirmation that the running resource has been terminated. The resource may continue to run on the cluster indefinitely.
pod "emqx-deployment-5884fd896f-b6hz9" force deleted

$ kubectl get pods
NAME                               READY   STATUS    RESTARTS     AGE
emqx-deployment-5884fd896f-84wxw   1/1     Running   0            34s
emqx-deployment-5884fd896f-hvd6v   1/1     Running   0            5m11s
emqx-deployment-5884fd896f-jv4ck   1/1     Running   0            5m11s

$ kubectl exec emqx-deployment-5884fd896f-84wxw -- emqx_ctl cluster status
Cluster status: #{running_nodes =>
                      ['emqx@172.20.32.169','emqx@172.20.58.237',
                       'emqx@172.20.85.197'],
                  stopped_nodes => ['emqx@172.20.32.168']}

  输出结果表明 EMQX Broker 会正确的显示已经停掉的 Pod,并将 Deployment 新建的 Pod 加入集群。至此,EMQX Broker 在 kubernetes 上成功建立集群。

7. 持久化 EMQX Broker 集群

  上文中使用的 Deployment 来管理 Pod,但是 Pod 的网络是不停变动的,而且当 Pod 被销毁重建时,储存在 EMQX Broker 的数据和配置也就随之消失了,这在生产中是不能接受的,接下来尝试把 EMQX Broker 的集群持久化,即使 Pod 被销毁重建,EMQX Broker 的数据依然可以保存下来。

  ConfigMap 是 configMap 是一种 API 对象,用来将非机密性的数据保存到健值对中。使用时可以用作环境变量、命令行参数或者存储卷中的配置文件。

  ConfigMap 将您的环境配置信息和 容器镜像 解耦,便于应用配置的修改。

  接下来使用 ConfigMap 记录 EMQX Broker 的配置,并将它们以环境变量的方式导入到 Deployment 中。定义 Configmap,并部署:

vim configmap.yaml
apiVersion: v1
kind: ConfigMap
metadata:
  name: emqx-config
data:
  EMQX_CLUSTER__K8S__ADDRESS_TYPE: "hostname"
  EMQX_CLUSTER__K8S__APISERVER: "https://kubernetes.default.svc:443"
  EMQX_CLUSTER__K8S__SUFFIX: "svc.cluster.local"

$ kubectl apply -f configmap.yaml
configmap/emqx-config created

  配置 Deployment 来使用 Configmap

$ vim deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: emqx-deployment
  labels:
    app: emqx
spec:
  replicas: 3
  selector:
    matchLabels:
      app: emqx
  template:
    metadata:
      labels:
        app: emqx
    spec:
      serviceAccountName: emqx
      containers:
      - name: emqx
        image: emqx/emqx:v4.1-rc.1
        ports:
        - name: mqtt
          containerPort: 1883
        - name: mqttssl
          containerPort: 8883
        - name: mgmt
          containerPort: 8081
        - name: ws
          containerPort: 8083
        - name: wss
          containerPort: 8084
        - name: dashboard
          containerPort: 18083
        envFrom:
          - configMapRef:
              name: emqx-config

  重新部署 Deployment,查看状态:

$ kubectl delete deployment emqx-deployment
deployment.apps "emqx-deployment" deleted
$ kubectl apply -f deployment.yaml
deployment.apps/emqx-deployment created

$ kubectl get pods
NAME                               READY   STATUS    RESTARTS     AGE
emqx-deployment-5958799d95-7lfw6   1/1     Running   0            20s
emqx-deployment-5958799d95-hfrvt   1/1     Running   0            20s
emqx-deployment-5958799d95-q6d7p   1/1     Running   0            20s

$ kubectl exec emqx-deployment-5958799d95-7lfw6 -- emqx_ctl status
Node 'emqx-deployment-5958799d95-7lfw6@172.20.58.246' is started
emqx 4.1-rc.1 is running

$ kubectl exec emqx-deployment-5958799d95-7lfw6 -- emqx_ctl cluster status
Cluster status: #{running_nodes =>
                      ['emqx-deployment-5958799d95-7lfw6@172.20.58.246'],
                  stopped_nodes => []}

  解决:

$ vim configmap.yaml
apiVersion: v1
kind: ConfigMap
metadata:
  name: emqx-config
data:
  EMQX_NAME: "emqx"
  EMQX_CLUSTER__DISCOVERY: "k8s"
  EMQX_CLUSTER__K8S__APP_NAME: "emqx"
  EMQX_CLUSTER__K8S__SERVICE_NAME: "emqx-service"
  EMQX_CLUSTER__K8S__APISERVER: "https://kubernetes.default.svc:443"
  EMQX_CLUSTER__K8S__NAMESPACE: "default"

$ kubectl delete configmap emqx-config
configmap "emqx-config" deleted
$ kubectl delete deployment emqx-deployment
deployment.apps "emqx-deployment" deleted

$ kubectl get pods
NAME                               READY   STATUS    RESTARTS       AGE
emqx-deployment-5958799d95-6vkth   1/1     Running   0              76m
emqx-deployment-5958799d95-dtnwf   1/1     Running   0              76m
emqx-deployment-5958799d95-j4vcf   1/1     Running   0              76m
  
$ kubectl exec emqx-deployment-5958799d95-6vkth -- emqx_ctl status
Node 'emqx@172.20.58.245' is started
emqx 4.1-rc.1 is running

$ kubectl exec emqx-deployment-5958799d95-6vkth -- emqx_ctl cluster status
Cluster status: #{running_nodes =>
                      ['emqx@172.20.32.143','emqx@172.20.58.245',
                       'emqx@172.20.85.211'],
                  stopped_nodes => []}

  EMQX Broker 的配置文件已经解耦到 Configmap 中了,如果有需要,可以自由的配置一个或多个 Configmap,并把它们作为环境变量或是文件引入到 Pod 内。

8. StatefulSet

  StatefulSet 是为了解决有状态服务的问题(对应 Deployments 和 ReplicaSets 是为无状态服务而设计),其应用场景包括

  • 稳定的持久化存储,即 Pod 重新调度后还是能访问到相同的持久化数据,基于 PVC 来实现
  • 稳定的网络标志,即 Pod 重新调度后其 PodName 和 HostName 不变,基于 Headless Service(即没有Cluster IP的Service)来实现
  • 稳定的网络标志,即 Pod 重新调度后其 PodName 和 HostName 不变,基于 Headless Service(即没有Cluster IP的Service)来实现
  • 有序收缩,有序删除(即从N-1到0)

  从上面的应用场景可以发现,StatefulSet由以下几个部分组成:

  • 用于定义网络标志(DNS domain)的 Headless Service
  • 用于创建 PersistentVolumes 的 volumeClaimTemplates
  • 定义具体应用的 StatefulSet

  StatefulSet 中每个 Pod 的 DNS 格式为 statefulSetName-{0..N-1}.serviceName.namespace.svc.cluster.local ,其中

  • serviceName 为 Headless Service 的名字
  • 0..N-1 为 Pod 所在的序号,从 0 开始到 N-1
  • statefulSetName 为StatefulSet的名字
  • namespace 为服务所在的 namespace,Headless Servic 和 StatefulSet 必须在相同的 namespace
  • .cluster.local 为 Cluster Domain

  接下来使用 StatefulSet 代替 Deployment 来管理 Pod。删除 Deployment:

$ kubectl delete deployment emqx-deployment
deployment.apps "emqx-deployment" deleted

  定义 StatefulSet:

vim statefulset.yaml
apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: emqx-statefulset
  labels:
    app: emqx
spec:
  serviceName: emqx-headless
  updateStrategy:
    type: RollingUpdate
  replicas: 3
  selector:
    matchLabels:
      app: emqx
  template:
    metadata:
      labels:
        app: emqx
    spec:
      serviceAccountName: emqx
      containers:
      - name: emqx
        image: emqx/emqx:v4.1-rc.1
        ports:
        - name: mqtt
          containerPort: 1883
        - name: mqttssl
          containerPort: 8883
        - name: mgmt
          containerPort: 8081
        - name: ws
          containerPort: 8083
        - name: wss
          containerPort: 8084
        - name: dashboard
          containerPort: 18083
        envFrom:
          - configMapRef:
              name: emqx-config

  注意,StatefulSet 需要 Headless Service 来实现稳定的网络标志,因此需要再定义一个 Service

vim headless.yaml
apiVersion: v1
kind: Service
metadata:
  name: emqx-headless
spec:
  type: ClusterIP
  clusterIP: None
  selector:
    app: emqx
  ports:
  - name: mqtt
    port: 1883
    protocol: TCP
    targetPort: 1883
  - name: mqttssl
    port: 8883
    protocol: TCP
    targetPort: 8883
  - name: mgmt
    port: 8081
    protocol: TCP
    targetPort: 8081
  - name: websocket
    port: 8083
    protocol: TCP
    targetPort: 8083
  - name: wss
    port: 8084
    protocol: TCP
    targetPort: 8084
  - name: dashboard
    port: 18083
    protocol: TCP
    targetPort: 18083

  因为 Headless Service 并不需要 IP,所以配置了 clusterIP: None 。部署相应的资源:

$ kubectl apply -f headless.yaml
service/emqx-headless created

$ kubectl 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                        53s
    emqx-service             ClusterIP   10.68.228.164   <none>        1883/TCP,8883/TCP,8081/TCP,8083/TCP,8084/TCP,18083/TCP                        21h

$ kubectl apply -f statefulset.yaml
statefulset.apps/emqx-statefulset created

$ kubectl get pods
NAME                       READY   STATUS    RESTARTS       AGE
emqx-statefulset-0         1/1     Running   0              2m
emqx-statefulset-1         1/1     Running   0              24s
emqx-statefulset-2         1/1     Running   0              22s

$ kubectl exec emqx-statefulset-0 -- emqx_ctl cluster status
Cluster status: #{running_nodes =>
                      ['emqx@172.20.32.174','emqx@172.20.58.248',
                       'emqx@172.20.85.214'],
                  stopped_nodes => []}

  更新 Configmap:StatefulSet 提供了稳定的网络标志,EMQX Broker 支持使用 hostname 和 dns 规则来代提 IP 实现集群,以 hostname 为例,需要修改 emqx.conf:

cluster.kubernetes.address_type = hostname
cluster.kubernetes.suffix = svc.cluster.local

  kubernetes 集群中 Pod 的 DNS 规则可以由用户自定义,EMQX Broker 提供了 cluster.kubernetes.suffix 方便用户匹配自定的 DNS 规则,本文使用默认的 DNS 规则:statefulSetName-{0..N-1}.serviceName.namespace.svc.cluster.local ,DNS 规则中的 serviceName 为 StatefulSet 使用的 Headless Service,所以还需要将 cluster.kubernetes.service_name 修改为 Headless Service Name。

  将配置项转为环境变量,需要在 Configmap 中配置:

EMQX_CLUSTER__K8S__ADDRESS_TYPE: "hostname"
EMQX_CLUSTER__K8S__SUFFIX: "svc.cluster.local"
EMQX_CLUSTER__K8S__SERVICE_NAME: emqx-headless

  Configmap 提供了热更新功能,执行 $ kubectl edit configmap emqx-config 来热更新 Configmap。

$ kubectl edit configmap emqx-config
# 修改前
# Please edit the object below. Lines beginning with a '#' will be ignored,
# and an empty file will abort the edit. If an error occurs while saving this file will be
# reopened with the relevant failures.
#
apiVersion: v1
data:
  EMQX_CLUSTER__DISCOVERY: k8s
  EMQX_CLUSTER__K8S__APISERVER: https://kubernetes.default.svc:443
  EMQX_CLUSTER__K8S__APP_NAME: emqx
  EMQX_CLUSTER__K8S__NAMESPACE: default
  EMQX_CLUSTER__K8S__SERVICE_NAME: emqx-service
  EMQX_NAME: emqx
kind: ConfigMap
metadata:
  annotations:
    kubectl.kubernetes.io/last-applied-configuration: |
      {"apiVersion":"v1","data":{"EMQX_CLUSTER__DISCOVERY":"k8s","EMQX_CLUSTER__K8S__APISERVER":"https://kubernetes.default.svc:443","EMQX_CLUSTER__K8S__APP_NAME":"emqx","EMQX_CLUSTER__K8S__NAMESPACE":"default","EMQX_CLUSTER__K8S__SERVICE_NAME":"emqx-service","EMQX_NAME":"emqx"},"kind":"ConfigMap","metadata":{"annotations":{},"name":"emqx-config","namespace":"default"}}
  creationTimestamp: "2024-07-12T05:26:16Z"
  name: emqx-config
  namespace: default
  resourceVersion: "1734159"
  uid: 13ccc86a-9ab3-450d-8a91-d73a7745d75b
  
# 修改后
apiVersion: v1
data:
  EMQX_CLUSTER__DISCOVERY: k8s
  EMQX_CLUSTER__K8S__APISERVER: https://kubernetes.default.svc:443
  EMQX_CLUSTER__K8S__APP_NAME: emqx
  EMQX_CLUSTER__K8S__NAMESPACE: default
  EMQX_CLUSTER__K8S__SERVICE_NAME: emqx-headless
  EMQX_NAME: emqx
  EMQX_CLUSTER__K8S__ADDRESS_TYPE: hostname
  EMQX_CLUSTER__K8S__SUFFIX: svc.cluster.local
kind: ConfigMap
metadata:
  annotations:
    kubectl.kubernetes.io/last-applied-configuration: |
      {"apiVersion":"v1","data":{"EMQX_CLUSTER__DISCOVERY":"k8s","EMQX_CLUSTER__K8S__APISERVER":"https://kubernetes.default.svc:443","EMQX_CLUSTER__K8S__APP_NAME":"emqx","EMQX_CLUSTER__K8S__NAMESPACE":"default","EMQX_CLUSTER__K8S__SERVICE_NAME":"emqx-headless","EMQX_NAME":"emqx","EMQX_CLUSTER__K8S__ADDRESS_TYPE":"hostname","EMQX_CLUSTER__K8S__SUFFIX":"svc.cluster.local"},"kind":"ConfigMap","metadata":{"annotations":{},"name":"emqx-config","namespace":"default"}}
  creationTimestamp: "2024-07-12T05:26:16Z"
  name: emqx-config
  namespace: default
  resourceVersion: "1734159"
  uid: 13ccc86a-9ab3-450d-8a91-d73a7745d75b

  重新部署 StatefulSet:Configmap 更新之后 Pod 并不会重启,需要我们手动更新 StatefulSet

$ kubectl delete statefulset emqx-statefulset
statefulset.apps "emqx-statefulset" deleted
$ kubectl apply -f statefulset.yaml
statefulset.apps/emqx-statefulset created

$ kubectl exec emqx-statefulset-0 -- emqx_ctl cluster status
Cluster status: #{running_nodes =>
                      ['emqx@emqx-statefulset-0.emqx-headless.default.svc.cluster.local'],
                  stopped_nodes => []}
                  
$ kubectl exec emqx-statefulset-0 -- emqx_ctl cluster status
Cluster status: #{running_nodes =>
                      ['emqx@emqx-statefulset-0.emqx-headless.default.svc.cluster.local'],
                  stopped_nodes => []}
                  
$ kubectl logs pod/emqx-statefulset-0 -n default
...
(emqx@emqx-statefulset-0.emqx-headless.default.svc.cluster.local)1> 2024-07-12 07:59:16.261 [error] Ekka(AutoCluster): Discover error: {badkey,<<"hostname">>}
[{maps,get,
       [<<"hostname">>,
        #{<<"ip">> => <<"172.20.32.158">>,<<"nodeName">> => <<"master-01">>,
          <<"targetRef">> =>
              #{<<"kind">> => <<"Pod">>,<<"name">> => <<"my-emqx-0">>,
                <<"namespace">> => <<"default">>,
                <<"uid">> => <<"de590aa1-d6da-42e0-9515-fe7f1fa68dfe">>}}],
       []},
 {ekka_cluster_k8s,extract_host,2,
                   [{file,"/emqx_rel/_build/emqx/lib/ekka/src/ekka_cluster_k8s.erl"},
                    {line,114}]},
 {ekka_cluster_k8s,'-extract_addresses/2-lc$^1/1-1-',2,
                   [{file,"/emqx_rel/_build/emqx/lib/ekka/src/ekka_cluster_k8s.erl"},
                    {line,110}]},
 {ekka_cluster_k8s,'-extract_addresses/2-lc$^1/1-1-',2,
                   [{file,"/emqx_rel/_build/emqx/lib/ekka/src/ekka_cluster_k8s.erl"},
                    {line,111}]},
 {ekka_cluster_k8s,'-extract_addresses/2-lc$^0/1-0-',2,
                   [{file,"/emqx_rel/_build/emqx/lib/ekka/src/ekka_cluster_k8s.erl"},
                    {line,111}]},
 {ekka_cluster_k8s,extract_addresses,2,
                   [{file,"/emqx_rel/_build/emqx/lib/ekka/src/ekka_cluster_k8s.erl"},
                    {line,112}]},
 {ekka_cluster_k8s,discover,1,
                   [{file,"/emqx_rel/_build/emqx/lib/ekka/src/ekka_cluster_k8s.erl"},
                    {line,48}]},
 {ekka_autocluster,discover_and_join,2,
                   [{file,"/emqx_rel/_build/emqx/lib/ekka/src/ekka_autocluster.erl"},
                    {line,125}]}]

  原因:我当时是已经存在一套 emqx 集群在 k8s 上且在正常使用,将这套 my-emqx 的删除即可。

$ kubectl get pods
NAME                 READY   STATUS    RESTARTS   AGE
emqx-statefulset-0   1/1     Running   0          115s
emqx-statefulset-1   1/1     Running   0          112s
emqx-statefulset-2   1/1     Running   0          110s

$ kubectl exec emqx-statefulset-2 -- emqx_ctl cluster status
Cluster status: #{running_nodes =>
                      ['emqx@emqx-statefulset-0.emqx-headless.default.svc.cluster.local',
                       'emqx@emqx-statefulset-1.emqx-headless.default.svc.cluster.local',
                       'emqx@emqx-statefulset-2.emqx-headless.default.svc.cluster.local'],
                  stopped_nodes => []}

  注意:当改为版本 5.7.1 版本的时候,修改 statefulset.yaml 相关内容为 image: emqx/emqx:5.7.1;configmap.yaml 文件里的配置参数名称有变化,需要改为

apiVersion: v1
kind: ConfigMap
metadata:
  name: emqx-config
data:
  EMQX_NAME: "emqx"
  EMQX_CLUSTER__DISCOVERY_STRATEGY: "k8s"
  EMQX_CLUSTER__K8S__APISERVER: "https://kubernetes.default.svc:443"
  EMQX_CLUSTER__K8S__SERVICE_NAME: "emqx-headless"
  EMQX_CLUSTER__K8S__NAMESPACE: "default"
  EMQX_CLUSTER__K8S__ADDRESS_TYPE: "hosname"
  EMQX_CLUSTER__K8S__SUFFIX: "svc.cluster.local"

  可以看到新的 EMQX Broker 集群已经成功的建立起来了。中止一个 Pod:StatefulSet 中的 Pod 重新调度后其 PodName 和 HostName 不变,下面来尝试一下:

$ kubectl get pods
kuNAME                 READY   STATUS    RESTARTS   AGE
emqx-statefulset-0   1/1     Running   0          6m20s
emqx-statefulset-1   1/1     Running   0          6m17s
emqx-statefulset-2   1/1     Running   0          6m15s

$ kubectl delete pod emqx-statefulset-0
pod "emqx-statefulset-0" deleted

$ kubectl get pods
NAME                 READY   STATUS    RESTARTS   AGE
emqx-statefulset-0   1/1     Running   0          27s
emqx-statefulset-1   1/1     Running   0          9m45s
emqx-statefulset-2   1/1     Running   0          9m43s

$ kubectl exec emqx-statefulset-2 -- emqx_ctl cluster status
Cluster status: #{running_nodes =>
                      ['emqx@emqx-statefulset-0.emqx-headless.default.svc.cluster.local',
                       'emqx@emqx-statefulset-1.emqx-headless.default.svc.cluster.local',
                       'emqx@emqx-statefulset-2.emqx-headless.default.svc.cluster.local'],
                  stopped_nodes => []}

  跟预期的一样,StatefulSet 重新调度了一个具有相同网络标志的 Pod,Pod 中的 EMQX Broker 也成功的加入了集群。

9. StorageClasses、PersistentVolume 和 PersistentVolumeClaim

  PersistentVolume(PV)是由管理员设置的存储,它是群集的一部分。就像节点是集群中的资源一样,PV 也是集群中的资源。 PV 是 Volume 之类的卷插件,但具有独立于使用 PV 的 Pod 的生命周期。此 API 对象包含存储实现的细节,即 NFS、iSCSI 或特定于云供应商的存储系统。

  PersistentVolumeClaim(PVC)是用户存储的请求。它与 Pod 相似。Pod 消耗节点资源,PVC 消耗 PV 资源。Pod 可以请求特定级别的资源(CPU 和内存)。声明可以请求特定的大小和访问模式(例如,可以以读/写一次或 只读多次模式挂载)。

  StorageClass 为管理员提供了描述存储 “class(类)” 的方法。 不同的 class 可能会映射到不同的服务质量等级或备份策略,或由群集管理员确定的任意策略。 Kubernetes 本身不清楚各种 class 代表的什么。这个概念在其他存储系统中有时被称为“配置文件”。

  在部署 EMQX Broker 的时候,可以预先创建好 PV 或 StorageClass,然后利用 PVC 将 EMQX Broker 的 /opt/emqx/data/mnesia 目录挂载出来,当Pods被重新调度之后,EMQX 会从 /opt/emqx/data/mnesia 目录中获取数据并恢复,从而实现 EMQX Broker 的持久化。

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:/a/803367.html

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

阿里云短信PHP集成api类

无需安装sdk扩展包&#xff0c;直接引入类即可使用 V3版本请求体&签名机制:自研请求体和签名机制 - 阿里云SDK - 阿里云 模版内容&#xff1a; <?phpnamespace common\components;use common\constant\UserConst; use common\models\bee\SmsReferer; use common\mode…

【VScode】安装【ESP-IDF】插件及相关工具链

一、ESP-IDF简介 二、VScode安装ESP-IDF插件 三、安装ESP-IDF、ESP-IDF-Tools以及相关工具链 四、测试例程&编译烧录 一、ESP-IDF简介 二、VScode安装ESP-IDF插件 【VScode】安装配置、插件及远程SSH连接 【VSCode】自定义配置 打开VScode&#xff0c;在插件管理搜索esp…

【程序大侠传】服务发布引发mq消息重复消费

前序 在编程武侠世界中&#xff0c;有一个门派“天机楼”&#xff0c;连接并协调各大门派之间的关系&#xff0c;确保整个江湖的运作流畅无阻。天机楼住要的业务范围主要如下&#xff1a; 信息传递的信使&#xff1a; 天机楼就像是江湖中的飞鸽传书&#xff0c;确保各门派之间…

泛微Ecology8明细表对主表赋值

文章目录 [toc]1.需求及效果1.1 需求1.2 效果2.思路与实现3.结语 1.需求及效果 1.1 需求 在明细表中的项目经理&#xff0c;可以将值赋值给主表中的项目经理来作为审批人员 1.2 效果 在申请人保存或者提交后将明细表中的人名赋值给主表中对应的值2.思路与实现 在通过js测…

【大型实战】企业网络实验(华为核心交换、ESXI7.0vmware虚拟机、DHCP中继、服务端网络及用户端网络配置)

需求 实验 vmware网络配置&#xff08;企业内部一般为ESXI&#xff09; 这样服务器虚拟机使用192.168.200.X网段才能与用户侧互通 vmware虚拟机配置&#xff08;DHCP服务器网络配置&#xff09; 打开网络管理页面 nmtui重置一下网络连接&#xff08;重启网卡&#xff09; …

JAVA @interface自定义注解(自定义注解+环绕通知 记录操作日志)

简介 注解interface是一种在Java代码中添加元数据&#xff08;metadata&#xff09;的方式&#xff0c;它可以用于提供程序的额外信息&#xff0c;但本身并不会直接影响程序的执行。注解可以应用于类、方法、字段和其他程序元素&#xff0c;用于提供关于这些元素的额外信息。 …

计算机组成原理 运算器

运算方法和运算器&#xff08;重点&#xff09; B二进制(binary), D十进制(decimal), H十六进制(hexadecimal) 纯小数和纯整数表示范围 设机器字长n1位&#xff0c;规定最高位&#xff08;第n1位&#xff09;为符号位 纯小数最大范围中的可理解为小数部分全为0的“1”&#…

TCP连接三次握手的过程,为什么是三次,可以是两次或者更多吗?

(1) 三次握手的过程 第一次握手&#xff1a;客户端向服务器发送一个包含SYN &#xff08;同步序列编号&#xff09;和初始序列号&#xff08;ISN&#xff09;的报文&#xff0c;请求建立连接&#xff0c;客户端进入SYN_SENT (同步已发送)状态。第二次握手&#xff1a;服务器收…

Python酷库之旅-第三方库Pandas(027)

目录 ​一、用法精讲 68、pandas.infer_freq函数 68-1、语法 68-2、参数 68-3、功能 68-4、返回值 68-5、说明 68-6、用法 68-6-1、数据准备 68-6-2、代码示例 68-6-3、结果输出 69、pandas.interval_range函数 69-1、语法 69-2、参数 69-3、功能 69-4、返回值…

Open3D Ransac拟合空间直线

目录 一、概述 1.1实现步骤 1.2优势与局限 二、代码实现 2.1关键代码 2.2完整代码 三、实现效果 前期试读&#xff0c;后续会将博客加入该专栏&#xff0c;欢迎订阅 Open3D点云算法与点云深度学习案例汇总&#xff08;长期更新&#xff09;-CSDN博客 一、概述 RANSAC&…

VScode终端和外部终端中文乱码问题

VScode终端和外部终端中文乱码问题 前言VScode终端VScode的第二大特点方法一方法二外部终端&#xff08;命令为ctrlf5&#xff09; 总结实现VScode终端和外部终端都能运行可执行文件 心得 前言 如果只想要看解决方案可直接跳转到总结部分&#xff0c;其余的章节只是用来说明原…

解决C#读取US7ASCII字符集oracle数据库的中文乱码

&#x1f468; 作者简介&#xff1a;大家好&#xff0c;我是Taro&#xff0c;全栈领域创作者 ✒️ 个人主页&#xff1a;唐璜Taro &#x1f680; 支持我&#xff1a;点赞&#x1f44d;&#x1f4dd; 评论 ⭐️收藏 文章目录 前言一、解决方法二、安装System.Data.OleDb连接库三…

第7章 模块(2)

目录 7.3 插入和删除模块 7.3.1 模块的表示 7.3.2 依赖关系和引用 7.3.3 模块的二进制结构 7.3.4 插入模块 7.3.5 移除模块 本专栏文章将有70篇左右&#xff0c;欢迎关注&#xff0c;查看后续文章。 7.3 插入和删除模块 两个系统调用&#xff1a; init_module&#xff1…

考研数学二战,怎么准备才能提升大?

一战70多...二战提升空间那是相当的大 我身边很多一战甚至不到60&#xff0c;二战成绩飙到120的&#xff0c;真的很猛 所以你根本不用担心是自己学数学没天赋&#xff0c;其实知识方法没用对而已 本人属于基础很差相当于是零基础的23考研党&#xff0c;经过一年备考成功上岸…

k8s集群 安装配置 Prometheus+grafana+alertmanager

k8s集群 安装配置 Prometheusgrafanaalertmanager k8s环境如下&#xff1a;机器规划&#xff1a; node-exporter组件安装和配置安装node-exporter通过node-exporter采集数据显示192.168.40.180主机cpu的使用情况显示192.168.40.180主机负载使用情况 Prometheus server安装和配置…

JayChou周杰伦的歌曲网易云音乐怎么听

听Jay自由 网易云导入 专辑介绍 周杰伦&#xff08;Jay Chou&#xff09;是一位著名的台湾流行歌手、词曲创作人和演员。他以其独特的音乐风格和才华横溢的创作能力而闻名于世。以下是对周杰伦所有专辑的简要介绍&#xff1a; 《Jay》&#xff08;2000年&#xff09;&#xf…

独立开发者系列(26)——域名与解析

域名&#xff08;英语&#xff1a;Domain Name&#xff09;&#xff0c;又称网域&#xff0c;是由一串用点分隔的名字组成的互联网上某一台计算机或计算机组的名称&#xff0c;用于在数据传输时对计算机的定位标识&#xff08;有时也指地理位置&#xff09;。 由于IP地址不方便…

Leaflet集成wheelnav在WebGIS中的应用

目录 前言 一、两种错误的实现方式 1、组件不展示 2、意外中的空白 二、不同样式的集成 1、在leaflet中集成wheelnav 2、给marker绑定默认组件 2、面对象绑定组件 3、如何自定义样式 三、总结 前言 在之前的博客中&#xff0c;我们曾经介绍了使用wheelnav.js构建酷炫…

Flink底层原理解析:案例解析(第37天)

系列文章目录 一、flink架构 二、Flink底层原理解析 三、Flink应用场景解析 四、fink入门案例解析 文章目录 系列文章目录前言一、flink架构1. 作业管理器&#xff08;JobManager&#xff09;2. 资源管理器&#xff08;ResourceManager&#xff09;3. 任务管理器&#xff08;Ta…

【八股系列】CSS盒模型:掌握网页布局的核心

&#x1f389; 博客主页&#xff1a;【剑九 六千里-CSDN博客】 &#x1f3a8; 上一篇文章&#xff1a;【Vue中的&#xff1c;keep-alive&#xff1e;组件&#xff1a;深入解析与实践指南】 &#x1f3a0; 系列专栏&#xff1a;【面试题-八股系列】 &#x1f496; 感谢大家点赞&…