首页 > 数据库 >k8s上部署Redis集群

k8s上部署Redis集群

时间:2023-08-09 23:01:29浏览次数:39  
标签:name no Redis redis cluster 集群 max yes k8s

1.部署sc

apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
  name: nfs-redis
provisioner: kubernetes.io/no-provisioner
volumeBindingMode: WaitForFirstConsumer

2.通过cm创建redis配置文件

apiVersion: v1
kind: ConfigMap
metadata:
  name: redis-cluster
  namespace: redis
data:
  fix-ip.sh: |
    #!/bin/sh
    CLUSTER_CONFIG="/data/nodes.conf"
    if [ -f ${CLUSTER_CONFIG} ]; then
      if [ -z "${POD_IP}" ]; then
        echo "Unable to determine Pod IP address!"
        exit 1
      fi
      echo "Updating my IP to ${POD_IP} in ${CLUSTER_CONFIG}"
      sed -i.bak -e '/myself/ s/[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}/'${POD_IP}'/' ${CLUSTER_CONFIG}
    fi
    exec "$@"
  redis.conf: |
    bind 0.0.0.0
    protected-mode yes
    port 6379
    tcp-backlog 2048
    timeout 0
    tcp-keepalive 300
    daemonize no
    supervised no
    pidfile /var/run/redis.pid
    loglevel notice
    logfile /data/redis.log
    databases 16
    always-show-logo yes
    stop-writes-on-bgsave-error yes
    rdbcompression yes
    rdbchecksum yes
    dbfilename dump.rdb
    dir /data
    masterauth liuchang@2022
    replica-serve-stale-data yes
    replica-read-only no
    repl-diskless-sync no
    repl-diskless-sync-delay 5
    repl-disable-tcp-nodelay no
    replica-priority 100
    requirepass 123456
    maxclients 32768
    #maxmemory 6g
    maxmemory-policy allkeys-lru
    lazyfree-lazy-eviction no
    lazyfree-lazy-expire no
    lazyfree-lazy-server-del no
    replica-lazy-flush no
    appendonly yes
    appendfilename "appendonly.aof"
    appendfsync everysec
    no-appendfsync-on-rewrite no
    auto-aof-rewrite-percentage 100
    auto-aof-rewrite-min-size 64mb
    aof-load-truncated yes
    aof-use-rdb-preamble yes
    lua-time-limit 5000
    cluster-enabled yes
    cluster-config-file /data/nodes.conf
    cluster-node-timeout 15000
    slowlog-log-slower-than 10000
    slowlog-max-len 128
    latency-monitor-threshold 0
    notify-keyspace-events ""
    hash-max-ziplist-entries 512
    hash-max-ziplist-value 64
    list-max-ziplist-size -2
    list-compress-depth 0
    set-max-intset-entries 512
    zset-max-ziplist-entries 128
    zset-max-ziplist-value 64
    hll-sparse-max-bytes 3000
    stream-node-max-bytes 4096
    stream-node-max-entries 100
    activerehashing yes
    client-output-buffer-limit normal 0 0 0
    client-output-buffer-limit replica 256mb 64mb 60
    client-output-buffer-limit pubsub 32mb 8mb 60
    hz 10
    dynamic-hz yes
    aof-rewrite-incremental-fsync yes
    rdb-save-incremental-fsync yes

3.创建sts

apiVersion: apps/v1
kind: StatefulSet
metadata:
  namespace: redis
  name: redis-cluster
spec:
  serviceName: redis-cluster
  replicas: 6
  selector:
    matchLabels:
      app: redis-cluster
  template:
    metadata:
      labels:
        app: redis-cluster
    spec:
      affinity:
        nodeAffinity:                                      # node亲和性
          requiredDuringSchedulingIgnoredDuringExecution:  # 硬策略,调度在app.kubernetes.io/component=zookeeper的节点中
            nodeSelectorTerms:
            - matchExpressions:
              - key: app.kubernetes.io/component
                operator: In
                values:
                  - zookeeper
        podAntiAffinity:                                    # Pod反亲和性
          preferredDuringSchedulingIgnoredDuringExecution:  # 软策略,使Pod分布在不同的节点上
          - weight: 1                                       # 权重,有多个策略通过权重控制调度
            podAffinityTerm:
              topologyKey: app.kubernetes.io/name           # 通过app.kubernetes.io/name作为域调度  
              labelSelector:
                matchExpressions:
                - key: app.kubernetes.io/component
                  operator: In
                  values:
                  - zookeeper
      containers:
      - name: redis
        image: redis:5.0.13
        ports:
        - containerPort: 6379
          name: client
        - containerPort: 16379
          name: gossip
        command: ["/etc/redis/fix-ip.sh", "redis-server", "/etc/redis/redis.conf"]
        env:
        - name: POD_IP
          valueFrom:
            fieldRef:
              fieldPath: status.podIP
        volumeMounts:
        - name: conf
          mountPath: /etc/redis/
          readOnly: false
        - name: redis-data
          mountPath: /data
          readOnly: false
      volumes:
      - name: conf
        configMap:
          name: redis-cluster
          defaultMode: 0755
  volumeClaimTemplates:
  - metadata:
      name: redis-data
    spec:
      storageClassName: infra-nfs-redis
      accessModes:
        - ReadWriteMany
      resources:
        requests:
          storage: 5Gi

4.创建svc

apiVersion: v1
kind: Service
metadata:
  namespace: redis
  name: redis-cluster
spec:
  clusterIP: None
  ports:
  - port: 6379
    targetPort: 6379
    name: client
  - port: 16379
    targetPort: 16379
    name: gossip
  selector:
    app: redis-cluster

5.初始化集群
5.1 查看redis pod ip

 kubectl get po -n redis  -owide

5.2 选择其中一个pod作为主节点,进入pod里初始化集群

redis-cli --cluster create 集群节点ip:端口
  1. 验证集群
cluster info
cluster nodes

标签:name,no,Redis,redis,cluster,集群,max,yes,k8s
From: https://www.cnblogs.com/navysummer/p/17619041.html

相关文章

  • redis for windows 6/7安装包定时弹黑窗口解决办法
    这是冰河之刃渡桥计划的一部分,使用Windows计划任务自动运行redis服务。 博客地址:https://www.cnblogs.com/binghe021 下载地址:码云 https://gitee.com/binghe021/redis-setupgithub  https://github.com/binghe021/redis-setup安装包的实现原理是借助计划任务来自动运行redis......
  • 条条大路通罗马系列—— 使用 Hiredis-cluster 连接 Amazon ElastiCache for Redis 集
    前言AmazonElastiCacheforRedis是速度超快的内存数据存储,能够提供亚毫秒级延迟来支持实时应用程序。适用于Redis的ElastiCache基于开源Redis构建,可与RedisAPI兼容,能够与Redis客户端配合工作,并使用开放的Redis数据格式来存储数据。适用于Redis的ElastiCache......
  • Nginx集群
    Nginx集群Nginx集群 Nginx简介Nginx("enginex")是一个高性能的HTTP和反向代理服务器,也是一个IMAP/POP3/SMTP代理服务器。Nginx是由IgorSysoev为俄罗斯访问量第二的Rambler.ru站点开发的,它已经在该站点运行超过两年半了。Igor将源代码以类BSD许可证的......
  • Redis
    Redis是一个开源的使用ANSI C语言编写、支持网络、可基于内存亦可持久化的日志型、Key-Value数据库,并提供多种语言的API。Redis根本是使用内存存储。第一次取数据,会先去内存取,如果没有再去硬盘上去取,取到数据后会在内存上留一份。第二次来去这些数据的时候直接去内存取了,这样速度......
  • redis 2.8--7.0 常用数据类型及性能测试工具
    redis2.8--7.01.redis-cli2.redisincrpageviewredisincrpageviewredisgetpageview3.Redishash是一个string类型的field(字段)和value(值)的映射表,hash特别适合用于存储对象。Redis中每个hash可以存储232-1键值对(40多亿)hash:hmsetkeyfiled1valuefil......
  • k8s调度
    一、污点和容忍k8s集群中可能管理着非常庞大的服务器,这些服务器可能是各种各样不同类型的,比如机房、地理位置、配置等,有些是计算型节点,有些是存储型节点,此时我们希望能更好的将pod调度到与之需求更匹配的节点上。 此时就需要用到污点(Taint)和容忍(Toleration),这些配置都是key......
  • 基于keepalived+gtid半同步主从复制的MySQL集群
    mysql的安装(二进制安装)[root@my-slv1~]#catmysql_install.sh#!/bin/bash#解决软件的依赖关系yuminstallcmakencurses-develgccgcc-c++vimlsofbzip2openssl-develncurses-compat-libs-y#解压mysql二进制安装包tarxfmysql-5.7.38-linux-glibc2.12-x86_64.ta......
  • redis协议介绍
    ......
  • 数据库-mysql/postgresql/mongo/oracle/redis 物理备份与恢复的执行方式有
    以下是每个数据库的物理备份与恢复的执行方式示例:MySQL:备份:使用mysqldump命令进行备份。示例:mysqldump-uusername-pdatabase_name>backup.sql恢复:使用mysql命令从备份文件中恢复数据。示例:mysql-uusername-pdatabase_name<backup.sqlPostgreSQL:备份:使用pg_d......
  • docker 启动redis 7.0.12
    1.拉取镜像 dockerpullredis:7.0.122.去官网下载对应的包,解压拿到redis.conf,下载地址:https://redis.io/download/bind127.0.0.1#注释掉这部分,使redis可以外部访问daemonizeno#用守护线程的方式启动requirepass你的密码#给redis设置密码appendonlyyes#r......