kubernetes中使用Helm搭建Redis集群

1. 环境要求

  1. 首先需要有kubernetes集群环境,搭建kubernetes集群可以使用kubeSphere、kubespray等工具安装集群。
  2. 其次要安装helm,并且添加了可用的Chart仓库

2. 确认合适的Chart包

helm官网上搜索redis
找到Star数多的Chart包,一类是redis包,一类是redis-cluster,顾名思义,redis-cluster是笔者所需的集群模式的redis的Chart包,而另外一个是单机模式或者主从模式的Chart包。点击右侧的INSTALL,即可得到添加相应仓库的命令,机器上运行命令。

//添加仓库
helm repo add bitnami https://charts.bitnami.com/bitnami
//安装
helm install my-redis-cluster bitnami/redis-cluster --version 9.8.1

在这里插入图片描述
在这里插入图片描述

]# helm install my-redis-cluster bitnami/redis-cluster --version 9.8.1
WARNING: This chart is deprecated
NAME: my-redis
LAST DEPLOYED: Tue Mar 12 17:56:38 2024
NAMESPACE: my-namespace
STATUS: deployed
REVISION: 1
TEST SUITE: None
NOTES:
This Helm chart is deprecatedGiven the `stable` deprecation timeline (https://github.com/helm/charts#deprecation-timeline), the Bitnami maintained Redis Helm chart is now located at bitnami/charts (https://github.com/bitnami/charts/).The Bitnami repository is already included in the Hubs and we will continue providing the same cadence of updates, support, etc that we've been keeping here these years. Installation instructions are very similar, just adding the _bitnami_ repo and using it during the installation (`bitnami/<chart>` instead of `stable/<chart>`)$ helm repo add bitnami https://charts.bitnami.com/bitnami
$ helm install my-release bitnami/<chart>           # Helm 3
$ helm install --name my-release bitnami/<chart>    # Helm 2To update an exisiting _stable_ deployment with a chart hosted in the bitnami repository you can execute$ helmrepo add bitnami https://charts.bitnami.com/bitnami$ helm upgrade my-release bitnami/<chart>Issues and PRs related to the chart itself will be redirected to `bitnami/charts` GitHub repository. In the same way, we'll be happy to answer questions related to this migration process in this issue (https://github.com/helm/charts/issues/20969) created as a common place for discussion.** Please be patient while the chart is being deployed **
Redis can be accessed via port 6379 on the following DNS names from within your cluster:my-redis-master.my-namespace.svc.cluster.local for read/write operations
my-redis-slave.my-namespace.svc.cluster.local for read-only operations//执行此命令,生成一个REDIS_PASSWORD,此为redis的10位随机密码。
To get your password run:export REDIS_PASSWORD=$(kubectl get secret --namespace my-namespace my-redis -o jsonpath="{.data.redis-password}" | base64 --decode)To connect to your Redis server:1. Run a Redis pod that you can use as a client:kubectl run --namespace my-namespace my-redis-client --rm --tty -i --restart='Never' \--env REDIS_PASSWORD=$REDIS_PASSWORD \--image docker.io/bitnami/redis:5.0.7-debian-10-r32 -- bash2. Connect using the Redis CLI:redis-cli -h my-redis-master -a $REDIS_PASSWORDredis-cli -h my-redis-slave -a $REDIS_PASSWORDTo connect to your database from outside the cluster execute the following commands:kubectl port-forward --namespace my-namespace svc/my-redis-master 6379:6379 &redis-cli -h 127.0.0.1 -p 6379 -a $REDIS_PASSWORD

以上两条命令可以正常安装redis集群,并且根据安装后的命令提示的信息,可以设置10位随机密码访问redis。但是为了更好的配置使用redis集群,可进行如下操作。

3. 下载Chart包

  1. 建立名为my-namespace的命名空间
kubectl create namespace my-namespace
  1. 添加仓库
//添加仓库
]# helm repo add bitnami https://charts.bitnami.com/bitnami
//查看仓库
]# helm repo list
  1. 搜索Chart
//查找redis
]# helm search repo redis//执行结果
NAME                    CHART VERSION   APP VERSION     DESCRIPTION                                       
bitnami/redis           17.1.8          7.0.5           Redis(R) is an open source, advanced key-value ...
bitnami/redis-cluster   8.2.4           7.0.5           Redis(R) is an open source, scalable, distribut...
  1. 下载Chart
    下载Chart包相比于直接安装的好处,是可以根据需要,修改配置文件,进行个性化安装。
]# helm pull bitnami/redis-cluster]# ll redis-cluster-8.2.4.tgz 
-rw-r--r-- 1 root root 106744 922 16:15 redis-cluster-8.2.4.tgz# 解压压缩包并进入
[root@master ~]# tar -zxf redis-cluster-8.2.4.tgz && cd redis-cluster
[root@master redis-cluster]# #查看目录结构
[root@master redis-cluster]# tree .
.
├── Chart.lock
├── charts
│   └── common
│       ├── Chart.yaml
│       ├── README.md
│       ├── templates
│       │   ├── _affinities.tpl
│       │   ├── _capabilities.tpl
│       │   ├── _errors.tpl
│       │   ├── _images.tpl
│       │   ├── _ingress.tpl
│       │   ├── _labels.tpl
│       │   ├── _names.tpl
│       │   ├── _secrets.tpl
│       │   ├── _storage.tpl
│       │   ├── _tplvalues.tpl
│       │   ├── _utils.tpl
│       │   ├── validations
│       │   │   ├── _cassandra.tpl
│       │   │   ├── _mariadb.tpl
│       │   │   ├── _mongodb.tpl
│       │   │   ├── _mysql.tpl
│       │   │   ├── _postgresql.tpl
│       │   │   ├── _redis.tpl
│       │   │   └── _validations.tpl
│       │   └── _warnings.tpl
│       └── values.yaml
├── Chart.yaml
├── img
│   ├── redis-cluster-topology.png
│   └── redis-topology.png
├── README.md
├── templates
│   ├── configmap.yaml
│   ├── extra-list.yaml
│   ├── headless-svc.yaml
│   ├── _helpers.tpl
│   ├── metrics-prometheus.yaml
│   ├── metrics-svc.yaml
│   ├── networkpolicy.yaml
│   ├── NOTES.txt
│   ├── poddisruptionbudget.yaml
│   ├── prometheusrule.yaml
│   ├── psp.yaml
│   ├── redis-rolebinding.yaml
│   ├── redis-role.yaml
│   ├── redis-serviceaccount.yaml
│   ├── redis-statefulset.yaml
│   ├── redis-svc.yaml
│   ├── scripts-configmap.yaml
│   ├── secret.yaml
│   ├── svc-cluster-external-access.yaml
│   ├── tls-secret.yaml
│   └── update-cluster.yaml
└── values.yaml6 directories, 49 files

常见问题:

步骤 3. 下载Chart包的常见问题是,选择错了Chart包,如果是安装集群模式的redis,一定要bitnami/redis-cluster。如果选择bitnami/redis包,则安装出来的不一定是集群模式的,此时如果发现了安装的不是集群模式,直接安装到kubernetes的redis,可以修改redis.conf文件的配置cluster-enabled yes,然后重启解决。但是此处却不行,只能修改helm的values.yaml配置文件进行升级,或者直接卸载重新安装。

helm upgrade my-redis bitnami/redis-cluster  -f values.yaml -n my-namespace --set password=USX6SZmvla

4. 修改配置文件

修改values.yaml的一些配置,可以进行自定义个性化安装。下面只展示需要修改的。这个配置文件的注释很重要,如果遇到问题一定要仔细看这些注释!
配置文件中每个字段的含义都可以从官方包解释中查看,链接如下:

https://artifacthub.io/packages/helm/bitnami/redis-cluster

4.1 修改点1:修改密码为redis123

## @param global.imageRegistry Global Docker image registry
## @param global.imagePullSecrets Global Docker registry secret names as an array
## @param global.storageClass Global StorageClass for Persistent Volume(s)
## @param global.redis.password Redis&reg; password (overrides `password`)
##
global:imageRegistry: ""## E.g.## imagePullSecrets:##   - myRegistryKeySecretName##imagePullSecrets: []storageClass: ""redis://修改点1:修改密码为redis123password: "redis123"## Compatibility adaptations for Kubernetes platforms

4.2 修改点2-3-4:修改SVC的External-IP

  1. 修改点2:默认为公网IP,此处修改为内部负载均衡IP
    此处如果不修改,则安装后的redis集群的SVC是External-IP是公网IP,但是笔者搭建的redis集群是信息系统内部使用,只需开放内部负载均衡IP,可以查看上方注释中的链接,此链接中根据不同的云环境,对修改方法进行了指导。
https://kubernetes.io/docs/concepts/services-networking/service/#internal-load-balancer

在这里插入图片描述
也可以去对应的云服务商的教程文档中查看。
在这里插入图片描述

!!如果不修改此注解,不会生成内部负载均衡器,安装后查询SVC信息时,EXTERNAL-IP为公网IP

//查看server
]# kubectl get svc -n redis-namespace
NAME                                TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)              AGE
my-release-redis-cluster            LoadBalancer   40.20.161.245   40.20.162.245        6379/TCP             11m
my-release-redis-cluster-headless   ClusterIP   None            <none>        6379/TCP,16379/TCP   11m
  1. 修改点3:默认为ClusterIP,修改为LoadBalance

默认为ClusterIP,安装后查询SVC信息时,TYPE列为ClusterIP,无法提供访问redis集群的IP

//查看server
]# kubectl get svc -n redis-namespace
NAME                                TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)              AGE
my-release-redis-cluster            ClusterIP   10.20.161.245   <none>        6379/TCP             11m
my-release-redis-cluster-headless   ClusterIP   None            <none>        6379/TCP,16379/TCP   11m

修改为LoadBalance

//查看server
]# kubectl get svc -n redis-namespace
NAME                                TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)              AGE
my-release-redis-cluster            LoadBalancer   10.20.161.245   172.16.0.8        6379/TCP             11m
my-release-redis-cluster-headless   ClusterIP   None            <none>        6379/TCP,16379/TCP   11m
  1. //修改点4:可以指定IP,不指定则系统自动分配
## Redis&reg; Service properties for standalone mode.
##
service:## @param service.ports.redis Kubernetes Redis service port##ports:redis: 6379## Node ports to expose## ref: https://kubernetes.io/docs/concepts/services-networking/service/#type-nodeport## @param service.nodePorts.redis Node port for Redis##nodePorts:redis: ""## @param service.extraPorts Extra ports to expose in the service (normally used with the `sidecar` value)##extraPorts: []## @param service.annotations Provide any additional annotations which may be required.## This can be used to set the LoadBalancer service type to internal only.## ref: https://kubernetes.io/docs/concepts/services-networking/service/#internal-load-balancer##//修改点2:默认为公网IP,此处修改为内部负载均衡IPannotations: {service.beta.kubernetes.io/alibaba-cloud-loadbalancer-address-type: "intranet"}## @param service.labels Additional labels for redis service##labels: {}## @param service.type Service type for default redis service## Setting this to LoadBalancer may require corresponding service annotations for loadbalancer creation to succeed.## Currently supported types are ClusterIP (default) and LoadBalancer##//修改点3:默认为ClusterIP,修改为LoadBalancetype: LoadBalance## @param service.clusterIP Service Cluster IP## e.g.:## clusterIP: None##clusterIP: ""## @param service.loadBalancerIP Load balancer IP if `service.type` is `LoadBalancer`## If service.type is LoadBalancer, request a specific static IP address if supported by the cloud provider, otherwise leave blank##//修改点4:可以指定IP,不指定则系统自动分配loadBalancerIP: "172.16.0.8"## @param service.loadBalancerSourceRanges Service Load Balancer sources## ref: https://kubernetes.io/docs/tasks/access-application-cluster/configure-cloud-provider-firewall/#restrict-access-for-loadbalancer-service## e.g:## loadBalancerSourceRanges:##   - 10.10.10.0/24##loadBalancerSourceRanges: []## @param service.externalTrafficPolicy Service external traffic policy## ref https://kubernetes.io/docs/tasks/access-application-cluster/create-external-load-balancer/#preserving-the-client-source-ip##externalTrafficPolicy: Cluster## @param service.sessionAffinity Session Affinity for Kubernetes service, can be "None" or "ClientIP"## If "ClientIP", consecutive client requests will be directed to the same Pod## ref: https://kubernetes.io/docs/concepts/services-networking/service/#virtual-ips-and-service-proxies##sessionAffinity: None## @param service.sessionAffinityConfig Additional settings for the sessionAffinity## sessionAffinityConfig:##   clientIP:##     timeoutSeconds: 300##sessionAffinityConfig: {}## Headless service properties##headless:## @param service.headless.annotations Annotations for the headless service.##annotations: {}
## Enable persistence using Persistent Volume Claims
## ref: https://kubernetes.io/docs/concepts/storage/persistent-volumes/
##

4.3 无需修改

此部分是各个cluster节点的配置,无需修改

## Redis&reg; Cluster settings
##
cluster:## @param cluster.init Enable the initialization of the Redis&reg; Cluster##init: true## Number of Redis&reg; nodes to be deployed#### Note:## This is total number of nodes including the replicas. Meaning there will be 3 master and 3 replica## nodes (as replica count is set to 1 by default, there will be 1 replica per master node).## Hence, nodes = numberOfMasterNodes + numberOfMasterNodes * replicas#### @param cluster.nodes The number of master nodes should always be >= 3, otherwise cluster creation will fail##nodes: 6## @param cluster.replicas Number of replicas for every master in the cluster## Parameter to be passed as --cluster-replicas to the redis-cli --cluster create## 1 means that we want a replica for every master created##replicas: 1## Configuration to access the Redis&reg; Cluster from outside the Kubernetes cluster##externalAccess:## @param cluster.externalAccess.enabled Enable access to the Redis##enabled: false## @param cluster.externalAccess.hostMode Set cluster preferred endpoint type as hostname## ref: https://github.com/redis/redis/pull/9530##hostMode: falseservice:## @param cluster.externalAccess.service.disableLoadBalancerIP Disable use of `Service.spec.loadBalancerIP`##disableLoadBalancerIP: false## @param cluster.externalAccess.service.loadBalancerIPAnnotaion Name of annotation to specify fixed IP for service in. Disables `Service.spec.loadBalancerIP` if not empty##loadBalancerIPAnnotaion: ""## @param cluster.externalAccess.service.type Type for the services used to expose every Pod## At this moment only LoadBalancer is supported##type: LoadBalancer## @param cluster.externalAccess.service.port Port for the services used to expose every Pod##port: 6379## @param cluster.externalAccess.service.loadBalancerIP Array of load balancer IPs for each Redis&reg; node. Length must be the same as cluster.nodes##loadBalancerIP: []## @param cluster.externalAccess.service.loadBalancerSourceRanges Service Load Balancer sources## ref: https://kubernetes.io/docs/tasks/access-application-cluster/configure-cloud-provider-firewall/#restrict-access-for-loadbalancer-service## e.g:## loadBalancerSourceRanges:##   - 10.10.10.0/24##loadBalancerSourceRanges: []## @param cluster.externalAccess.service.annotations Annotations to add to the services used to expose every Pod of the Redis&reg; Cluster##annotations: {}## This section allows to update the Redis&reg; cluster nodes.

5. 安装部署

5.1 安装redis 集群

# 安装 redis 集群
helm -n my-namespace install my-redis-cluster bitnami/redis-cluster -f values.yaml

得到如下安装信息,如果安装报错,此处也会展示日志

]# helm -n my-namespace install my-redis-cluster -f values.yaml .NAME: my-redis-cluster
LAST DEPLOYED: Fri Mar 15 09:30:09 2024
NAMESPACE: my-namespace
STATUS: deployed
REVISION: 1
TEST SUITE: None
NOTES:
CHART NAME: redis-cluster
CHART VERSION: 9.8.1
APP VERSION: 7.2.4** Please be patient while the chart is being deployed **To get your password run:export REDIS_PASSWORD=$(kubectl get secret --namespace "my-namespace" my-redis-cluster-redis-cluster -o jsonpath="{.data.redis-password}" | base64 -d)You have deployed a Redis&reg; Cluster accessible only from within you Kubernetes Cluster.INFO: The Job to create the cluster will be created.To connect to your Redis&reg; cluster:1. Run a Redis&reg; pod that you can use as a client:
kubectl run --namespace my-namespace my-redis-cluster-redis-cluster-client --rm --tty -i --restart='Never' \--env REDIS_PASSWORD=$REDIS_PASSWORD \
--image docker.io/bitnami/redis-cluster:7.2.4-debian-12-r9 -- bash2. Connect using the Redis&reg; CLI:redis-cli -c -h my-redis-cluster-redis-cluster -a $REDIS_PASSWORD

5.2 查看部署的 redis 集群

]# helm ls -n my-namespace
NAME            NAMESPACE       REVISION        UPDATED                                 STATUS          CHART                   APP VERSION
my-redis-cluster   redis           2               2022-09-22 16:38:46.018087963 +0800 CST deployed        redis-cluster-8.2.4     7.0.5   

查看安装历史

]# helm history my-redis-cluster -n redis
REVISION        UPDATED                         STATUS          CHART                   APP VERSION     DESCRIPTION     
1               Thu Sep 22 16:25:49 2022        superseded      redis-cluster-8.2.4     7.0.5           Install complete
2               Thu Sep 22 16:38:46 2022        deployed        redis-cluster-8.2.4     7.0.5           Upgrade complete

5.2 查看部署的 POD

]# kubectl get pod -n my-namespace
NAME              READY   STATUS    RESTARTS      AGE
my-redis-cluster-0   1/1     Running   1 (22s ago)   83s
my-redis-cluster-1   1/1     Running   1 (50s ago)   83s
my-redis-cluster-2   1/1     Running   1 (22s ago)   83s
my-redis-cluster-3   1/1     Running   1 (21s ago)   83s
my-redis-cluster-4   1/1     Running   1 (21s ago)   83s
my-redis-cluster-5   1/1     Running   1 (19s ago)   83s

5.3 查看部署的SVC

//查看server
]# kubectl get svc -n redis-namespace
NAME                                TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)              AGE
my-redis-cluster            LoadBalancer   10.20.161.245   172.16.0.8        6379/TCP             11m
my-redis-cluster-headless   ClusterIP   None            <none>        6379/TCP,16379/TCP   11m

6. 验证 redis 集群

]# kubectl exec -it my-redis-cluster-0 -n my-namespace bash
I have no name!@my-redis-cluster-0:/$ redis-cli
127.0.0.1:6379> auth redis123
OK
127.0.0.1:6379>keys *
//验证是否集群模式
127.0.0.1:6379>cluster nodes
//执行结果
a18a5aa0a16f2fd9d389fe83a39e1bcf28611d3d 10.10.2.4:6379@16379 master - 0 1665371671970 1 connected 0-5460
de4021c3c1611382270a90cad0bb43025d24e7b2 10.10.2.6:6379@16379 slave a18a5aa0a16f2fd9d389fe83a39e1bcf28611d3d 0 1665371670000 1 connected
b54b8cb69585febff3d46420e6b99a1a2c244232 10.10.1.5:6379@16379 master - 0 1665371672000 2 connected 5461-10922
8de10b6d34d3afcebc39120bcd28a07306140eef 10.10.1.6:6379@16379 slave b54b8cb69585febff3d46420e6b99a1a2c244232 0 1665371671000 2 connected
8b72dfdaac832d01c3669e9086c0272909eb256b 10.10.2.5:6379@16379 myself,master - 0 1665371669000 3 connected 10923-16383
bc55361f4715ed0ecaeab2b455d722e0f871b732 10.10.1.7:6379@16379 slave 8b72dfdaac832d01c3669e9086c0272909eb256b 0 1665371672980 3 connected

除此之外,可以再在redis客户端连接验证,如果验证无问题,SVC信息中的EXTERNAL-IP即可配置在软件服务中访问redis集群使用,密码是上文修改点1中修改的密码。

7. 常见问题

  1. 启动redis没有成功
]# kubectl get pod -n my-namespace
NAME              READY   STATUS    RESTARTS      AGE
my-redis-cluster-0   0/1     Running   1 (22s ago)   83s
my-redis-cluster-1   0/1     Running   1 (50s ago)   83s
my-redis-cluster-2   0/1     Running   1 (22s ago)   83s
my-redis-cluster-3   0/1     Running   1 (21s ago)   83s
my-redis-cluster-4   0/1     Running   1 (21s ago)   83s
my-redis-cluster-5   0/1     Running   1 (19s ago)   83s
//查看server
]# kubectl get svc -n my-namespace
NAME                                TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)              AGE
my-redis-cluster            LoadBalancer   10.20.161.245   172.16.0.8        6379/TCP             11m
my-redis-cluster-headless   ClusterIP   None            <none>        6379/TCP,16379/TCP   11m

此时使用EXTERNAL-IP是连接不上的,因为POD没有启动成功,STATUS 0/1,可以执行如下命令查看启动报错的原因:

]# kubectl logs -f my-redis-cluster-0 -n my-namespace
redis-cluster 03:11:24.95 INFO  ==> ** Redis setup finished! **
1:C 15 Mar 2024 03:11:24.997 # WARNING: Changing databases number from 16 to 1 since we are in cluster mode
1:C 15 Mar 2024 03:11:24.997 * oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
1:C 15 Mar 2024 03:11:24.997 * Redis version=7.2.4, bits=64, commit=00000000, modified=0, pid=1, just started
1:C 15 Mar 2024 03:11:24.997 * Configuration loaded
1:M 15 Mar 2024 03:11:24.997 * monotonic clock: POSIX clock_gettime_.__.-``__ ''-.__.-``    `.  `_.  ''-._           Redis 7.2.4 (00000000/0) 64 bit.-`` .-```.  ```\/    _.,_ ''-._(    '      ,       .-`  | `,    )     Running in cluster mode|`-._`-...-` __...-.``-._|'` _.-'|     Port: 6379|    `-._   `._    /     _.-'    |     PID: 1`-._    `-._  `-./  _.-'    _.-'|`-._`-._    `-.__.-'    _.-'_.-'||    `-._`-._        _.-'_.-'    |           https://redis.io`-._    `-._`-.__.-'_.-'    _.-'|`-._`-._    `-.__.-'    _.-'_.-'||    `-._`-._        _.-'_.-'    |`-._    `-._`-.__.-'_.-'    _.-'`-._    `-.__.-'    _.-'`-._        _.-'`-.__.-'1:M 15 Mar 2024 03:11:24.998 * No cluster configuration found, I'm aaaaaaaaaaaaaaa
......
1:S 15 Mar 2024 03:11:36.886 # Error condition on socket for SYNC: Connection refused
1:S 15 Mar 2024 03:11:37.100 * Connecting to MASTER *******:6379
1:S 15 Mar 2024 03:11:37.100 * MASTER <-> REPLICA sync started
1:S 15 Mar 2024 03:11:37.101 # Error condition on socket for SYNC: Connection refused
  1. Service Mesh - Kubernetes LoadBalancer Service External IP 一直处于 pending 状态
    如果你使用自建的 Kubernetes 集群(minikube、kubeadm 等)。在这种情况下,没有集成 LoadBalancer(与 AWS、Google Cloud、阿里云等云厂商不同)。使用此默认设置,你只能使用 NodePort 或 Ingress Controller。这时,如果你部署 LoadBalancer 则会出现 External-IP 一直处于 pending 的问题。

参考
https://www.orchome.com/16821(与本篇博客无关)
https://www.cnblogs.com/devopsyyds/p/16719945.html
https://www.cnblogs.com/maiblogs/p/16771609.html
https://www.cnblogs.com/evescn/p/16342899.html
https://artifacthub.io/packages/helm/bitnami/redis-cluster
https://kubernetes.io/docs/tasks/access-application-cluster/create-external-load-balancer/#preserving-the-client-source-ip

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

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

乐鑫 Matter 技术体验日|快速落地 Matter 产品,引领智能家居生态新发展

随着 Matter 协议的推广和普及&#xff0c;智能家居行业正迎来新的发展机遇&#xff0c;众多厂商纷纷投身于 Matter 产品的研发与验证。然而&#xff0c;开发者普遍面临技术门槛高、认证流程繁琐、生产管理复杂等诸多挑战。 乐鑫信息科技 (688018.SH) 凭借深厚的研发实力与行…

Gin框架基础

1、一个简单的Gin示例 下载并安装Gin: go get -u github.com/gin-gonic/gin1.1 一个简单的例子 package mainimport ("net/http""github.com/gin-gonic/gin" )func main() {// 创建一个默认的路由引擎r : gin.Default()// 当客户端以GET方式访问 /hello…

常见Web认证方式对比

认证是一个在用户或者设备在访问一个受限的系统时&#xff0c;鉴定用户凭据的过程&#xff0c;即确认“你是谁”的问题。最常见的认证用户的方式是通过用户名和密码的形式进行校验&#xff0c;目前存在多种校验方式&#xff0c;本文将对其进行一个简单的对比&#xff0c;使得大…

160相交链表

解法1&#xff1a; public class Solution {public ListNode getIntersectionNode(ListNode headA, ListNode headB) {// 定义两个指针。// 获得两个链表的长度&#xff0c;将较长的链表先用指针移动到和短链表一样的长度。// 再一个个比较ListNode l1 headA, l2 headB;int …

在我们的大数据平台(XSailbaot)上进行企业级数据建模的思路

1. 背景 笔者所在的公司是差不多二十年前搞CIM&#xff08;公共信息模型的&#xff09;起家的。当时公司的前辈搞了基于CIS协议的模型服务器、数据服务器、模式编辑器等&#xff0c;形成了一套基于公共信息模型建模的平台系统。其中可视化建模&#xff0c;建好了模式类以后&am…

Kotlin中对空的很多处理

代码图片直观效果 逐行解释Kotlin中对空的各种情况的使用 private fun testNull() {val flag 1var name: String? nullvar user: User? // 有警告, 因为下面的赋值可以和这一行定义合并var zhangUser: User? User()var wangUser: User User() // 提示Explicitly given t…

AttGAN实验复现 2024

AttnGAN 代码复现 2024 文章目录 AttnGAN 代码复现 2024简介环境python 依赖数据集TrainingPre-train DAMSMTrain AttnGAN SamplingB_VALIDATION 为 False (默认)B_VALIDATION 为 True 参考博客 简介 论文地址&#xff1a; https://arxiv.org/pdf/1711.10485.pdf 代码 python…

C++: 如何用C语言实现C++的虚函数机制?

前言 在 googletest的源码中&#xff0c;看到gtest-matchers.h 中实现的MatcherBase 类自定义了一个 VTable&#xff0c;这种设计实现了一种类似于C虚函数的机制。C中的虚函数机制实质上就是通过这种方式实现的&#xff0c;本文用c语言自定义虚函数表VTable实现了一下virtual的…

Workerman在线客服系统源码,附搭建教程

源码介绍&#xff1a; Workerman在线客服系统源码。 workerman是一个高性能的PHP socket 服务器框架&#xff0c;workerman基于PHP多进程以及libevent事件轮询库&#xff0c;PHP开发者只要实现一两个接口&#xff0c;便可以开发出自己的网络应用&#xff0c;例如Rpc服务、聊天…

240630_昇思学习打卡-Day12-Transformer中的Multiple-Head Attention

240630_昇思学习打卡-Day12-Transformer中的Multiple-Head Attention 以下为观看大佬课程及查阅资料总结所得&#xff0c;附大佬视频链接&#xff1a;Transformer中Self-Attention以及Multi-Head Attention详解_哔哩哔哩_bilibili&#xff0c;强烈建议先去看大佬视频&#xff…

python解锁图片相似度的神奇力量

在这个信息爆炸的时代,图片成为了我们传递信息、表达情感和记录生活的重要方式。然而,面对海量的图片资源,如何快速准确地找到相似的图片,成为了一个亟待解决的问题。现在,让我们为您揭开图片相似度的神秘面纱,带您领略这一创新技术的魅力! 图片相似度技术,就像是一位…

docker harbor仓库搭建,主从库复制

背景&#xff1a;需要主机安装docker-ce和docer-compose #1.安装相关依赖. yum install -y yum-utils device-mapper-persistent-data lvm2 #2.下载官方的docker yum源文件 yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo …

10款好用不火的PC软件,真的超好用!

AI视频生成&#xff1a;小说文案智能分镜智能识别角色和场景批量Ai绘图自动配音添加音乐一键合成视频https://aitools.jurilu.com/市场上有很多软件&#xff0c;除了那些常见的大众化软件&#xff0c;还有很多不为人知的小众软件&#xff0c;它们的作用非常强大&#xff0c;简洁…

cJSON源码解析之add_item_to_object函数

文章目录 前言add_item_to_object函数是干什么的add_item_to_object代码解析函数实现函数原理解析开头的代码constant_key参数的作用最后的if判断 add_item_to_array函数 总结 前言 在我们的日常编程中&#xff0c;JSON已经成为了一种非常常见的数据交换格式。在C语言中&#…

UI Toolkit系统学习

UI Toolkit 此文章用于学习UnityUI系统&#xff0c;手头的项目做完会来完善 官方文档 Unity上方菜单栏点击Window->UI Toolkit->Samples可以看UI Toolkit中的很多样例 使用 UI Toolkit 和 UI Builder 制作物品编辑器 在文件夹中右键->Create->UI Toolkit->Edi…

leetCode-hot100-动态规划专题

动态规划 动态规划定义动态规划的核心思想动态规划的基本特征动态规划的基本思路例题322.零钱兑换53.最大子数组和72.编辑距离139.单词拆分62.不同路径63.不同路径Ⅱ64.最小路径和70.爬楼梯121.买卖股票的最佳时机152.乘积最大子数组 动态规划定义 动态规划&#xff08;Dynami…

【训练篇】MLU370-M8 完成 qwen1.5-7b-chat-lora训练及推理

文章目录 前言一、平台环境配置二、环境 or 模型准备1.模型下载2.环境准备2.1 modelscope2.2 transformers2.3 accelerate2.4 deepspeed2.5 peft2.6 环境代码修改 3训练代码准备4 代码修改 三&#xff0c;训练后推理验证四.推理效果展示1.微调前2.微调后 前言 本期我们采用魔塔…

distance delayed sound

distance delayed sound 在本章中&#xff0c;我们将讨论在游戏音频中使用距离延迟的重要性。我们将首先通过一个常见的例子——闪电和雷鸣&#xff0c;来展示这种重要性并解释距离延迟音频的基础知识。我们将讨论计算速度、距离和时间的数学和方程式&#xff0c;以确定距离延迟…

数据倾斜优化:Hive性能提升的核心

文章目录 1. 定义2. 数据倾斜2.1 Map2.2 Join2.3 Reduce 3. 写在最后 1. 定义 数据倾斜&#xff0c;也称为Data Skew&#xff0c;是在分布式计算环境中&#xff0c;由于数据分布不均匀导致某些任务处理的数据量远大于其他任务&#xff0c;从而形成性能瓶颈的现象。这种情况在H…

PotPlayer安装及高分辨率设置

第1步&#xff1a; 下载安装PotPlayer软件 PotPlayer链接&#xff1a;https://pan.baidu.com/s/1hW168dJrLBonUnpLI6F3qQ 提取码&#xff1a;z8xd 第2步&#xff1a; 下载插件&#xff0c;选择系统对应的位数进行运行&#xff0c;该文件不能删除&#xff0c;删除后将失效。 …