ELK学习笔记(一)——使用K8S部署ElasticSearch8.15.0集群

一、下载镜像

#1、下载官方镜像
docker pull elasticsearch:8.15.0
#2、打新tag
docker tag elasticsearch:8.15.0 192.168.9.41:8088/new-erp-common/elasticsearch:8.15.0
#3、推送到私有仓库harbor
docker push 192.168.9.41:8088/new-erp-common/elasticsearch:8.15.0

二、优化宿主机配置

部署elasticsearch集群需要先优化宿主机(所有k8s节点都要优化,不优化会部署失败)

vim /etc/sysctl.conf 

vm.max_map_count=262144 # (用于设置 Linux 系统内核中允许用户态程序的最大内存区域数量。通过设置该参数,可以控制系统中允许映射的内存区域的最大数量,这对于一些需要大量内存映射的应用程序是很有用)

sysctl -p #生效配置

三、创建工作目录

下面是搭建ES的目录一览图
在这里插入图片描述

四、准备yaml配置文件

4.1准备ConfigMap配置

创建ConfigMap配置,里面主要配置了elasticsearch.yml需要的配置

$ cat config-map-es.yaml 
apiVersion: v1
kind: ConfigMap
metadata:
  name: config-map-es
  namespace: renpho-erp-common
data:
  # 下面2行不确定可不可以删除,但因为在elasticsearch.yml中配置了,所以感觉这2行可以删了
  network.host: "0.0.0.0"
  cluster.name: "es-cluster"
  elasticsearch.yml: |
    #设置集群名称
    cluster.name: es-cluster
    #设置网络访问节点【其他节点修改项】
    network.host: "0.0.0.0"
    #设置网络访问端口
    http.port: 9200
    transport.port: 9300
    node.roles: [ingest,master,data]
    #节点发现
    discovery.seed_hosts: ["elasticsearch-0.elasticsearch.renpho-erp-common.svc.cluster.local","elasticsearch-1.elasticsearch.renpho-erp-common.svc.cluster.local","elasticsearch-2.elasticsearch.renpho-erp-common.svc.cluster.local"]
    #初始化集群
    cluster.initial_master_nodes: ["elasticsearch-0","elasticsearch-1","elasticsearch-2"]
    #启用安全
    xpack.security.enabled: true
    xpack.security.enrollment.enabled: true

    #客户端连接加密
    xpack.security.http.ssl:
      enabled: true
      keystore.path: /usr/share/elasticsearch/config/local-certs/http.p12
      truststore.path: /usr/share/elasticsearch/config/local-certs/http.p12
    #集群内节点连接加密
    xpack.security.transport.ssl:
      enabled: true
      verification_mode: certificate
      keystore.path: /usr/share/elasticsearch/config/local-certs/elastic-certificates.p12
      truststore.path: /usr/share/elasticsearch/config/local-certs/elastic-certificates.p12

    #必须set为true,否则kibana报错
    search.allow_expensive_queries: true
    #禁用geoip下载
    ingest.geoip.downloader.enabled: false

4.2准备Service及StatefulSet文件

在 Kubernetes 上搭建 Elasticsearch 集群时,通常会创建两个不同类型的 Service:一个无头服务(Headless Service)和一个普通的有头服务(ClusterIP Service)。这两种服务各有其特定的用途和作用,以下是它们的具体用途和原因:

a. 无头服务(Headless Service)
  • 作用: 无头服务是通过设置 clusterIP: None 创建的,这意味着它不会分配一个单一的集群IP地址。这种服务不会进行负载均衡,而是直接暴露其背后所有的 Pod。
  • 用途: 在 Elasticsearch 集群中,无头服务通常用于节点发现集群的状态维护。通过无头服务,每个 Elasticsearch 节点可以获得集群中其他节点的 IP 地址,从而进行节点间的通信和发现。
  • DNS 记录: 无头服务会为每个 Pod 创建一个独立的 DNS A 记录,这样,Elasticsearch 可以通过这些记录直接访问到其他节点。例如,如果有一个无头服务 elasticsearch-headless,且有三个 Pod(elasticsearch-0, elasticsearch-1, elasticsearch-2),这些 Pod 可以通过 DNS 名称 elasticsearch-0.elasticsearch-headless.namespace.svc.cluster.local 访问彼此。
b. 有头服务(ClusterIP Service)
  • 作用: 有头服务(通常称为 ClusterIP 服务)会分配一个集群内部 IP 地址,并为该地址上的端口提供负载均衡。这意味着,任何请求发送到该服务的 IP 地址时,会被分配到后端的某一个 Pod。
  • 用途: 在 Elasticsearch 集群中,有头服务通常用于外部客户端的连接和访问,例如 Kibana 或其他使用者查询 Elasticsearch 数据的应用程序。它可以提供一个单一的访问点,从而简化外部应用的连接配置。
  • 负载均衡: 通过有头服务,Kubernetes 可以在多个 Elasticsearch 节点之间进行负载均衡,确保请求均匀分布,从而提高查询性能和服务的可用性。
c. 总结
  • 无头服务:用于集群内的节点发现和通信,每个节点可以直接找到其他节点的 IP 地址,便于 Elasticsearch 集群中的主节点选举、数据复制和分片分配。
  • 有头服务:用于提供一个稳定的、负载均衡的外部访问点,让外部应用或用户可以通过一个固定的服务 IP 地址来访问 Elasticsearch 集群,而无需关心背后 Pod 的具体 IP。

通过结合使用无头服务和有头服务,可以既保持集群内部节点间的灵活通信,又提供对外部客户端的统一访问接口,这是在 Kubernetes 上部署 Elasticsearch 集群的常见模式。

$ cat deploy-es2.yaml 
#无头服务
apiVersion: v1
kind: Service
metadata:
  name: elasticsearch
  namespace: renpho-erp-common
  labels:
    app: elasticsearch
spec:
  selector:
    app: elasticsearch
  clusterIP: None
  ports:
    - port: 9200
      name: db
    - port: 9300
      name: inter
---
#有头服务
apiVersion: v1
kind: Service
metadata:
  name: es-nodeport
  namespace: renpho-erp-common
  labels:
    app: elasticsearch
spec:
  selector:
    app: elasticsearch
  type: NodePort
  ports:
    - port: 9200
      name: db
      nodePort: 30092
    - port: 9300
      name: inter
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: elasticsearch
  namespace: renpho-erp-common
  labels:
    app: elasticsearch
spec:
  podManagementPolicy: Parallel 
  serviceName: elasticsearch
  replicas: 3
  selector:
    matchLabels:
      app: elasticsearch
  template:
    metadata:
      labels:
        app: elasticsearch
    spec:
      containers:
      - name: elasticsearch
        image: renpho.harbor.com/new-erp-common/elasticsearch:8.15.0
        imagePullPolicy: IfNotPresent
        securityContext: ##开启特权,因为要调整系统内核
          privileged: true
        resources:
          limits:
            cpu: 1
            memory: 2Gi
          requests:
            cpu: 0.5
            memory: 500Mi
       #command: ["/bin/sh","-c"]
       # args:
       # - |
       #   sleep 3600;
        env:
          - name: network.host
            valueFrom:
              configMapKeyRef:
                name: config-map-es
                key: network.host
          - name: node.name
            valueFrom:
              fieldRef:
                fieldPath: metadata.name
        ports:
        - name: db
          containerPort: 9200
          protocol: TCP
        - name: inter
          containerPort: 9300
          protocol: TCP
        volumeMounts:
        - name: elasticsearch-data
          mountPath: /usr/share/elasticsearch/data
          subPath: es-data
        - name: elasticsearch-data
          mountPath: /usr/share/elasticsearch/logs
          subPath: es-logs
        - name: elasticsearch-data
          mountPath: /usr/share/elasticsearch/.cache
          subPath: es-cache
        - name: elasticsearch-data
          mountPath: /usr/share/elasticsearch/plugins
          subPath: es-plugins
        - name: es-cert-file  #挂载存储目录
          mountPath: /usr/share/elasticsearch/config/local-certs
        - name: es-config  #挂载配置文件
          mountPath: /usr/share/elasticsearch/config/elasticsearch.yml
          subPath: elasticsearch.yml
        - name: host-time  #挂载本地时区
          mountPath: /etc/localtime
          readOnly: true

      volumes:
      - name: es-config
        configMap:
          name: config-map-es
          defaultMode: 493 #文件权限为-rwxr-xr-x
      - name: es-cert-file
        secret:
          secretName: es-certificates
      - name: host-time
        hostPath: #挂载本地时区
          path: /etc/localtime
          type: ""
  volumeClaimTemplates:
  - metadata:
      name: elasticsearch-data
    spec:
      storageClassName: ssd-nfs-storage
      accessModes: [ "ReadWriteMany" ]
      resources:
        requests:
          storage: 50Gi

五、生成elastic集群所需的安全证书

为了方便生成证书,可以借助docker 运行 es 容器,但后进入容器内将证书生成好之后,再拷贝到宿主机备用。

##启动es容器
docker run -it -d --name es 192.168.9.41:8088/new-erp-common/elasticsearch:8.15.0
##进入容器生成证书
docker exec -it es bash

elasticsearch@62d07cf8df10:~$ pwd
/usr/share/elasticsearch
5.1生成CA证书
elasticsearch@62d07cf8df10:~$ ./bin/elasticsearch-certutil ca

这里可以选择添加证书密码,如果添加密码的话,后续使用CA证书去生成其他证书都需要先校验密码
默认会在当前目录下(/usr/share/elasticsearch)生成 elastic-stack-ca.p12 这个证书文件,在实际操作中根据自己的实际情况进行调整

5.2使用CA证书生成 transport证书
elasticsearch@62d07cf8df10:~$ ./bin/elasticsearch-certutil cert --ca /usr/share/elasticsearch/elastic-stack-ca.p12

最终会生成1个elastic-certificates.p12的证书文件

5.3使用CA证书生成http证书
elasticsearch@62d07cf8df10:~$ ./bin/elasticsearch-certutil http

## Elasticsearch HTTP Certificate Utility

The 'http' command guides you through the process of generating certificates
for use on the HTTP (Rest) interface for Elasticsearch.

This tool will ask you a number of questions in order to generate the right
set of files for your needs.

## Do you wish to generate a Certificate Signing Request (CSR)?

A CSR is used when you want your certificate to be created by an existing
Certificate Authority (CA) that you do not control (that is, you don't have
access to the keys for that CA). 

If you are in a corporate environment with a central security team, then you
may have an existing Corporate CA that can generate your certificate for you.
Infrastructure within your organisation may already be configured to trust this
CA, so it may be easier for clients to connect to Elasticsearch if you use a
CSR and send that request to the team that controls your CA.

If you choose not to generate a CSR, this tool will generate a new certificate
for you. That certificate will be signed by a CA under your control. This is a
quick and easy way to secure your cluster with TLS, but you will need to
configure all your clients to trust that custom CA.
#是否需要证书认证请求,选n
Generate a CSR? [y/N]n

## Do you have an existing Certificate Authority (CA) key-pair that you wish to use to sign your certificate?

If you have an existing CA certificate and key, then you can use that CA to
sign your new http certificate. This allows you to use the same CA across
multiple Elasticsearch clusters which can make it easier to configure clients,
and may be easier for you to manage.

If you do not have an existing CA, one will be generated for you.
#是否需要选择已存在得证书,选y
Use an existing CA? [y/N]y

## What is the path to your CA?

Please enter the full pathname to the Certificate Authority that you wish to
use for signing your new http certificate. This can be in PKCS#12 (.p12), JKS
(.jks) or PEM (.crt, .key, .pem) format.
#填入已存在ca证书路径
CA Path: /usr/share/elasticsearch/elastic-stack-ca.p12
Reading a PKCS12 keystore requires a password.
It is possible for the keystore's password to be blank,
in which case you can simply press <ENTER> at the prompt
#输入已存在证书密码,没有的话直接回车
Password for elastic-stack-ca.p12:

## How long should your certificates be valid?

Every certificate has an expiry date. When the expiry date is reached clients
will stop trusting your certificate and TLS connections will fail.

Best practice suggests that you should either:
(a) set this to a short duration (90 - 120 days) and have automatic processes
to generate a new certificate before the old one expires, or
(b) set it to a longer duration (3 - 5 years) and then perform a manual update
a few months before it expires.

You may enter the validity period in years (e.g. 3Y), months (e.g. 18M), or days (e.g. 90D)
#证书有效时间
For how long should your certificate be valid? [5y] 7y

## Do you wish to generate one certificate per node?

If you have multiple nodes in your cluster, then you may choose to generate a
separate certificate for each of these nodes. Each certificate will have its
own private key, and will be issued for a specific hostname or IP address.

Alternatively, you may wish to generate a single certificate that is valid
across all the hostnames or addresses in your cluster.

If all of your nodes will be accessed through a single domain
(e.g. node01.es.example.com, node02.es.example.com, etc) then you may find it
simpler to generate one certificate with a wildcard hostname (*.es.example.com)
and use that across all of your nodes.

However, if you do not have a common domain name, and you expect to add
additional nodes to your cluster in the future, then you should generate a
certificate per node so that you can more easily generate new certificates when
you provision new nodes.
#是否每个节点都需要生成,选n,所有节点共用一个
Generate a certificate per node? [y/N]n

## Which hostnames will be used to connect to your nodes?

These hostnames will be added as "DNS" names in the "Subject Alternative Name"
(SAN) field in your certificate.

You should list every hostname and variant that people will use to connect to
your cluster over http.
Do not list IP addresses here, you will be asked to enter them later.

If you wish to use a wildcard certificate (for example *.es.example.com) you
can enter that here.

Enter all the hostnames that you need, one per line.

When you are done, press <ENTER> once more to move on to the next step.
#输入集群所有节点主机名
#使用 Kubernetes 中 Pod 的 DNS 名称,可以避免 Pod IP 变化带来的问题。
#DNS 名称通常是 <pod-name>.<service-name>.<namespace>.svc.cluster.local 形式的
*.elasticsearch.renpho-erp-common.svc.cluster.local
elasticsearch.renpho-erp-common.svc.cluster.local
elasticsearch.renpho-erp-common
elasticsearch

You entered the following hostnames.

 - *.elasticsearch.renpho-erp-common.svc.cluster.local
 - elasticsearch.renpho-erp-common.svc.cluster.local
 - elasticsearch.renpho-erp-common
 - elasticsearch

#是否正确,选y
Is this correct [Y/n]y

#输入集群所有节点ip地址,由于上面使用的是DNS名称,所以这一步不用再输入固定IP地址,直接回车
## Which IP addresses will be used to connect to your nodes?

If your clients will ever connect to your nodes by numeric IP address, then you
can list these as valid IP "Subject Alternative Name" (SAN) fields in your
certificate.

If you do not have fixed IP addresses, or not wish to support direct IP access
to your cluster then you can just press <ENTER> to skip this step.

Enter all the IP addresses that you need, one per line.
When you are done, press <ENTER> once more to move on to the next step.


You did not enter any IP addresses.

#是否正确,选y
Is this correct [Y/n]y

## Other certificate options

The generated certificate will have the following additional configuration
values. These values have been selected based on a combination of the
information you have provided above and secure defaults. You should not need to
change these values unless you have specific requirements.

Key Name: elasticsearch-0.elasticsearch.renpho-erp-common.svc.cluster.local
Subject DN: CN=elasticsearch-0, DC=elasticsearch, DC=renpho-erp-common, DC=svc, DC=cluster, DC=local
Key Size: 2048
#是否修改证书配置,选n
Do you wish to change any of these options? [y/N]n

#输入密码,不想设置密码直接回车。建议为空,省点麻烦,这么多证书认证已经够够的了
## What password do you want for your private key(s)?

Your private key(s) will be stored in a PKCS#12 keystore file named "http.p12".
This type of keystore is always password protected, but it is possible to use a
blank password.

If you wish to use a blank password, simply press <enter> at the prompt below.
Provide a password for the "http.p12" file:  [<ENTER> for none]

## Where should we save the generated files?

A number of files will be generated including your private key(s),
public certificate(s), and sample configuration options for Elastic Stack products.

These files will be included in a single zip archive.

What filename should be used for the output zip file? [/usr/share/elasticsearch/elasticsearch-ssl-http.zip] 
#证书文件保存位置
Zip file written to /usr/share/elasticsearch/elasticsearch-ssl-http.zip


#解压缩刚生成得证书zip文件
elasticsearch@62d07cf8df10:~$ unzip elasticsearch-ssl-http.zip
Archive:  elasticsearch-ssl-http.zip
   creating: elasticsearch/
  inflating: elasticsearch/README.txt
  inflating: elasticsearch/http.p12
...

以上完成后将在/usr/share/elasticsearch下生成一个zip压缩文件。 解压文件,生成一个文件夹,里面包含两个文件夹:
elasticsearch文件夹包含http.p12及elasticsearch.yml的配置参考;
kibana文件夹包含elasticsearch-ca.pem及kibana.yml的配置参考;

5.4生成kibana使用的安全证书

为了方便起见,顺便将kibana使用的安全证书也一起生成。除了之前生成http证书时生成的 elasticsearch-ca.pem 之外还有3个文件

kibana.crt,kibana.key,kibana.csr
下面先生成 kibana.csr,kibana.key

elasticsearch@62d07cf8df10:~$ /usr/share/elasticsearch/bin/elasticsearch-certutil csr -name kibana -dns *.elasticsearch.renpho-erp-common.svc.cluster.local -dns elasticsearch.renpho-erp-common.svc.cluster.local -dns elasticsearch.renpho-erp-common -dns elasticsearch
#执行后默认会生成 csr-bundle.zip
#解压缩后得到kibana.csr ,kibana.key,用它2生成 kibana.crt
elasticsearch@62d07cf8df10:~$ unzip csr-bundle.zip 
Archive:  csr-bundle.zip
   creating: kibana/
  inflating: kibana/kibana.csr       
  inflating: kibana/kibana.key
# 生成crt文件
elasticsearch@62d07cf8df10:~$ cd kibana/
elasticsearch@62d07cf8df10:~$ openssl x509 -req -in kibana.csr -signkey kibana.key -out kibana.crt
Signature ok
subject=CN = kibana
Getting Private key
elasticsearch@62d07cf8df10:~$ ls -l
total 12
-rw-r--r-- 1 elasticsearch elasticsearch  985 Aug 29 08:32 kibana.crt
-rw-r--r-- 1 elasticsearch elasticsearch 1350 Aug 29 08:30 kibana.csr
-rw-r--r-- 1 elasticsearch elasticsearch 1679 Aug 29 08:30 kibana.key
5.4复制容器内证书到宿主机

在这里插入图片描述
另开一个窗口,使用docker cp将容器内上述生成的证书拷贝到宿主机

#在宿主机执行下列命令
##下面的证书拷贝到es的certs中,供es使用
docker cp es:/usr/share/elasticsearch/elastic-stack-ca.p12 /home/ec2-user/k8s/elk/es/certs/elastic-stack-ca.p12
docker cp es:/usr/share/elasticsearch/elastic-certificates.p12 /home/ec2-user/k8s/elk/es/certs/elastic-certificates.p12
docker cp es:/usr/share/elasticsearch/elasticsearch/http.p12 /home/ec2-user/k8s/elk/es/certs/http.p12

##下面的证书拷贝到kibana的certs中,供kibana使用
docker cp es:/usr/share/elasticsearch/kibana/elasticsearch-ca.pem /home/ec2-user/k8s/elk/kibana/certs/elasticsearch-ca.pem
docker cp es:/usr/share/elasticsearch/kibana/kibana.crt /home/ec2-user/k8s/elk/kibana/certs/kibana.crt
docker cp es:/usr/share/elasticsearch/kibana/kibana.csr /home/ec2-user/k8s/elk/kibana/certs/kibana.csr
docker cp es:/usr/share/elasticsearch/kibana/kibana.key /home/ec2-user/k8s/elk/kibana/certs/kibana.key

复制完后,可以将docker容器停掉。

六、开始用K8S部署ES集群

首先,看下es目录下的文件
在这里插入图片描述

6.1将安全证书添加到Secret中
  • elastic-certificates.p12
    • 这个文件是 Elasticsearch 用于节点间加密通信的证书。
  • http.p12
    • 这是 Elasticsearch 用于 HTTP 客户端连接安全访问的证书。
##创建命名空间
kubectl create namespace renpho-erp-common
##执行下列命令创建Secret
kubectl create secret generic es-certificates \
  --from-file=/home/ec2-user/k8s/elk/es/certs/elastic-certificates.p12 \
  --from-file=/home/ec2-user/k8s/elk/es/certs/http.p12 \
  -n renpho-erp-common
##查看Secret
kubectl get secret -n renpho-erp-common

在这里插入图片描述

6.2运行ES集群

依次执行下列命令

#ES配置文件创建
kubectl apply -f config-map-es.yaml
#ES Service,StatefulSet创建
kubectl apply -f delpoy-es2.yaml
#查看运行状态
kubectl get pod -n renpho-erp-common|grep elastic

在这里插入图片描述

浏览器输入:https://192.168.6.220:30092,检查服务是否部署成功
在这里插入图片描述
浏览器输入:192.168.6.220:30092/_cat/nodes?v,检查elasticsearch集群是否正常
在这里插入图片描述
浏览器输入:https://192.168.6.220:30092/_cluster/state/master_node,nodes?pretty,检查elasticsearch集群详情
在这里插入图片描述
到此,使用K8s部署ElasticSearch成功!

部署过程中遇到很多问题,感谢下面博主给出的参考,参考链接

ElasticSearch 8.12.0 K8S部署实践【超详细】【一站式】

Elasticsearch8.11集群部署

k8s集群部署elk
k8s 部署 elk
【k8s部署elasticsearch】k8s环境下安装elasticsearch集群和kibana

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

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

相关文章

一文理解粒子滤波

0. 粒子滤波流程 之前学习记录的文档&#xff0c;这里也拿出来分享一下~ 基本原理&#xff1a;随机选取预测域的 N NN 个点&#xff0c;称为粒子。以此计算出预测值&#xff0c;并算出在测量域的概率&#xff0c;即权重&#xff0c;加权平均就是最优估计。之后按权重比例&…

英文翻译工具怎么选?这4款值得收藏。

英语作为国际通用语言&#xff0c;在我们的日常生活中一直有着很重要的地位&#xff0c;往大了说可以促进国际交流&#xff0c;实现文化传播&#xff1b;往小了说&#xff0c;可以解决很多生活中的小问题。但是在很多情况下英文仍旧是我们一个语言障碍&#xff0c;所以好的翻译…

网络学习-eNSP配置ACL

AR1路由器配置 <Huawei>system-view Enter system view, return user view with CtrlZ. [Huawei]undo info-center enable Info: Information center is disabled. [Huawei]interface gigabitethernet 0/0/0 [Huawei-GigabitEthernet0/0/0]ip address 192.168.2.254 24 …

MapSet之相关概念

系列文章&#xff1a; 1. 先导片--Map&Set之二叉搜索树 2. Map&Set之相关概念 目录 1.搜索 1.1 概念和场景 1.2 模型 2.Map的使用 2.1 关于Map的说明 2.2 关于Map.Entry的说明 2.3 Map的常用方法说明 3.Set的说明 3.1关于Set说明 3.2 常见方法说明 1.搜…

windows 环境下搭建mysql cluster 集群详细步骤

1、环境准备 下载mysql集群版本&#xff0c;我这里下载的是mysql-cluster-8.0.39-winx64 https://dev.mysql.com/downloads/cluster/ 2、创建配置文件 mysql集群版本下载以后解压后目录如下&#xff0c;创建配置文件 config.ini(集群配置文件&#xff0c;my.ini mysql配置…

【大模型基础】P0 大模型之路 —— 窗外灯火阑珊

目录 前言 —— 本系列博文内容何谓语言语言、图形符号、编码与解码基于规则、基于统计 语言模型&#xff08;Language Model&#xff09;预训练语言模型BERT 与 GPT 大模型范式预训练 微调大模型提示 / 指令 OpenAI 若一个语言模型亮起一盏灯&#xff0c;你会发现&#xff0c…

三维布尔运算对不规范几何数据的兼容处理

1.前言 上一篇文章谈过八叉树布尔运算&#xff0c;对于规范几何数据的情况是没有问题的。 在实际情况中&#xff0c;由于几何数据来源不一&#xff0c;处理和生成方式不一&#xff0c;我们无法保证进行布尔运算的几何数据都是规范的&#xff0c;对于不规范情况有时候也有需求…

vue3写一个无限树形菜单,递归组件

原本使用element plus的el-tree&#xff0c;可是他的UI不匹配&#xff0c;狠难改成自己想要的&#xff0c;所以只能自己去写一个&#xff0c;做法&#xff1a;使用递归组件 效果 组件代码itemDir.vue // itemDir.vue<template><div><ul v-for"node in li…

【AcWing】852. spfa判断负环

#include<iostream> #include<algorithm> #include<cstring> #include<queue> using namespace std;const int N 1e510;int n,m; int h[N],w[N],e[N],ne[N],idx; int dist[N],cnt[N];//cnt存最短路径的边数 bool st[N];void add(int a,int b,int c){e[…

前端:Vue3学习-2

前端:Vue3学习-2 1. vue3 新特性-defineOptions2. vue3 新特性-defineModel3. vue3 Pinia-状态管理工具4. Pinia 持久化插件 -> pinia-plugin-persistedstate 1. vue3 新特性-defineOptions 如果要定义组件的name或其他自定义的属性&#xff0c;还是得回归原始得方法----再…

输送线相机拍照信号触发(博途PLC高速计数器中断立即输出应用)

博途PLC相关中断应用请参考下面文章链接: T法测速功能块 T法测速功能块(博途PLC上升沿中断应用)-CSDN博客文章浏览阅读165次。本文介绍了博途PLC中T法测速的原理和应用,包括如何开启上升沿中断、配置中断以及T法测速功能块的使用。重点讲述了在中断事件发生后执行的功能块处…

有希带你深入理解指针(4)

目录 前言&#x1f970;1.回调函数&#x1f63a;1.1回调函数的概念&#x1f60b; 2.qsort使用&#x1f92f;2.1什么是qsort&#x1f47b;2.2 qsort函数的使用&#x1f9d0; 3.模拟实现qsort&#x1f60e; 前言&#x1f970; 本篇文章是对指针知识的进一步讲解&#xff0c;如果…

【leetcode】二分查找专题

文章目录 1.基本的二分查找2.使用二分 查找左右端点2.1 左右端点2.2 二分模板 3.搜索插入位置4.x的平方根5.山脉数组的顶峰6.寻找峰值7.寻找旋转排序数组中的最小值 对于二分查找&#xff0c;相信大家都再熟悉不过了。一旦数据是有序的&#xff0c;我们大概率会想到二分&#x…

上海小学生古诗文大会2024年备考:吃透历年真题和知识点(持续)

一、小学生古诗文大会真题精选&#xff08;答案和解析见文末&#xff09; *1. 孟浩然的《宿建德江》是一首&#xff08;&#xff09;。 A.五言绝句 B.七言绝句 C.五言律诗 D.七言律诗 *2. 茕茕子立&#xff0c;形影相吊出自&#xff08;&#xff09; A.《出师表》 B.《…

常见Python GUI库分析

引言 在Python环境下进行桌面编程时&#xff0c;选择合适的GUI&#xff08;图形用户界面&#xff09;库至关重要。在Python环境下进行桌面编程GUI开发时&#xff0c;有多个优秀的库可供选择。以下是一些推荐的GUI库&#xff0c;包括它们的推荐理由、优劣势以及简单的demo示例。…

Deepspeed框架学习笔记

DeepSpeed 是由 Microsoft 开发的深度学习优化库,与PyTorch/TensorFlow等这种通用的深度学习框架不同的是,它是一个专门用于优化和加速大规模深度学习训练的工具,尤其是在处理大模型和分布式训练时表现出色。它不是一个独立的深度学习框架,而是依赖 PyTorch 等框架,扩展了…

C++20中lambda表达式新增加支持的features

1.弃用通过[]隐式捕获this&#xff0c;应使用[,this]或[,*this]显示捕获&#xff1a; namespace { struct Foo {int x{ 1 };void print(){//auto change1 [] { // badauto change1 [, this] { // good, this: referencethis->x 11;};change1();std::cout << "…

麒麟系统安装GPU驱动

1.nvidia 1.1显卡驱动 本机显卡型号:nvidia rtx 3090 1.1.1下载驱动 打开 https://www.nvidia.cn/geforce/drivers/ 也可以直接使用下面这个地址下载 https://www.nvidia.com/download/driverResults.aspx/205464/en-us/ 1.1.3安装驱动 右击&#xff0c;为run文件添加可…

【YOLO 系列】基于YOLOV8的智能花卉分类检测系统【python源码+Pyqt5界面+数据集+训练代码】

前言&#xff1a; 花朵作为自然界中的重要组成部分&#xff0c;不仅在生态学上具有重要意义&#xff0c;也在园艺、农业以及艺术领域中占有一席之地。随着图像识别技术的发展&#xff0c;自动化的花朵分类对于植物研究、生物多样性保护以及园艺爱好者来说变得越发重要。为了提…

接口自动化三大经典难题

目录 一、接口项目不生成token怎么解决关联问题 1. Session机制 2. 基于IP或设备ID的绑定 3. 使用OAuth或第三方认证 4. 利用隐式传递的参数 5. 基于时间戳的签名验证 二、接口测试中网络问题导致无法通过怎么办 1. 重试机制 2. 设置超时时间 3. 使用模拟数据 4. 网…