K8S如何部署ZooKeeper(续)-- Too many connections报错解决

本文讲述了在将服务从传统服务器迁移到Kubernetes时,由于服务器资源规划导致的ZooKeeper连接数问题。通过分析,提出修改配置文件以增加`maxClientCnxns`值,确保服务的正常运行。
摘要由CSDN通过智能技术生成

背景

在上一篇文章中(K8S如何部署ZooKeeper以及如何进行ZooKeeper的平滑替换)我们已经成功部署了ZooKeeper,但是真正切换时,报错如下

Too many connections from /xx.xx.xx.xx - max is 60

问题分析

在相关服务未迁移K8S时,各个服务都是散落在不同的服务器上的。而当迁移到K8S时,为了方便管理,对服务器进行了重新规划,同一个项目组使用相同的服务器资源,当副本数量较多时,从而出现了该问题。

解决方案

确定了问题出现的原因,那么就可以针对性的进行解决,我们可以按照下面的方式来修改上一篇中的部署脚本:

apiVersion: v1
kind: ConfigMap
metadata:
  name: zookeeper-config
  namespace: your-namespace
data:
  zoo.cfg: |
    clientPort=2181
    dataDir=/data
    dataLogDir=/data
    tickTime=2000
    initLimit=10
    syncLimit=5
    maxClientCnxns=6000
---
apiVersion: v1
kind: Service
metadata:
  name: zookeeper
  namespace: your-namespace
spec:
  selector:
    app: zookeeper
  type: NodePort
  ports:
    - name: client
      port: 2181
      targetPort: 2181
      nodePort: 30000
    - name: follower
      port: 2888
      targetPort: 2888
      nodePort: 30001
    - name: leader
      port: 3888
      targetPort: 3888
      nodePort: 30002
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: zookeeper
  namespace: your-namespace
spec:
  replicas: 1
  selector:
    matchLabels:
      app: zookeeper
  template:
    metadata:
      labels:
        app: zookeeper
    spec:
      affinity:
        nodeAffinity:
          requiredDuringSchedulingIgnoredDuringExecution:
            nodeSelectorTerms:
              - matchExpressions:
                  - key: project.node
                    operator: In
                    values:
                      - your-project-node
      containers:
        - name: zookeeper
          image: zookeeper:3.4.9
          imagePullPolicy: IfNotPresent
          terminationMessagePath: /dev/termination-log
          terminationMessagePolicy: File
          ports:
            - containerPort: 2181
            - containerPort: 2888
            - containerPort: 3888
          volumeMounts:
            - name: config-zookeeper
              mountPath: /conf/zoo.cfg
              subPath: zoo.cfg
            - name: data
              mountPath: /data
      volumes:
        - name: data
          hostPath:
            path: /var/lib/docker/zookeeper
        - name: config-zookeeper
          configMap:
            name: zookeeper-config
        - name: timezone
          hostPath:
            path: /usr/share/zoneinfo/Asia/Shanghai

附录:

ZooKeeper关于maxClientCnxns参数的官方解释:

单个客户端与单台服务器之间的连接数的限制,是ip级别的,默认是60,如果设置为0,那么表明不作任何限制。请注意这个限制的使用范围,仅仅是单台客户端机器与单台ZK服务器之间的连接数限制,不是针对指定客户端IP,也不是ZK集群的连接数限制,也不是单台ZK对所有客户端的连接数限制。

maxClientCnxns

Limits the number of concurrent connections (at the socket level) that a single client, identified by IP address, may make to a single member of the ZooKeeper ensemble. This is used to prevent certain classes of DoS attacks, including file descriptor exhaustion. The default is 60. Setting this to 0 entirely removes the limit on concurrent connections.

  • 8
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值