重庆分公司,新征程启航

为企业提供网站建设、域名注册、服务器等服务

k8s使用YAML创建redis5.0-创新互联

yaml部署redis的一个巨坑配置文件里面的daemonize no一定不能用daemonize yes,因为这个问题我搞了一个星期,

创新互联专注于乾安企业网站建设,响应式网站,商城网站制作。乾安网站建设公司,为乾安等地区提供建站服务。全流程按需网站设计,专业设计,全程项目跟踪,创新互联专业和态度为您提供的服务

yaml文件的标签是关联各个服务的重要说明
labels  下面的name参数和后面的值各服务之间要全部一致才能正确关联,
metadata:
name: redis-yx-t-config
labels:
  name: gem-yx-t-redis

apiVersion: v1 
kind: ConfigMap 
metadata: 
  name: gem-yx-t-redis
  labels: 
    app: gem-yx-t-redis 
data: 
  redis.conf: |- 
    dir /data 
    port 6379 
    bind 0.0.0.0 
    appendonly yes 
    daemonize no       #这个是重点,不能yes,否则永远无法启动
    #protected-mode no 
    requirepass test 
---
apiVersion: apps/v1 
kind: StatefulSet 
metadata: 
  name: gem-yx-t-redis 
  labels: 
    app: gem-yx-t-redis 
spec:
  serviceName: gem-yx-t-redis 
  replicas: 1 
  selector: 
    matchLabels: 
      app: gem-yx-t-redis 
  template: 
    metadata: 
      labels: 
        app: gem-yx-t-redis 
    spec: 
      containers: 
      - name: redis 
        image: redis:5.0.7 
        command: 
          - "sh" 
          - "-c" 
          - "redis-server /usr/local/redis/redis.conf" 
        ports: 
        - containerPort: 6379 
        resources: 
          limits: 
            cpu: 1000m 
            memory: 1024Mi 
          requests: 
            cpu: 1000m 
            memory: 1024Mi 
        livenessProbe: 
          tcpSocket: 
            port: 6379 
          initialDelaySeconds: 300 
          timeoutSeconds: 1 
          periodSeconds: 10 
          successThreshold: 1 
          failureThreshold: 3 
        readinessProbe: 
          tcpSocket: 
            port: 6379 
          initialDelaySeconds: 5 
          timeoutSeconds: 1 
          periodSeconds: 10 
          successThreshold: 1 
          failureThreshold: 3 
        volumeMounts:
        - name: data
          mountPath: /data
        # 时区设置
        - name: timezone
          mountPath: /etc/localtime
        - name: config 
          mountPath:  /usr/local/redis/redis.conf 
          subPath: redis.conf 		  
      volumes:
      - name: config 
        configMap: 
          name: redis-yx-t-config 
      - name: timezone                             
        hostPath:
          path: /usr/share/zoneinfo/Asia/Shanghai
      - name: data
        hostPath:
          type: DirectoryOrCreate 
          path: /data/redis/gem-yx-t-redis
      nodeName: gem-yxyw-t-c02
--- 
 
apiVersion: v1 
kind: Service 
metadata: 
  name: gem-yx-t-redis
  labels: 
    app: gem-yx-t-redis  
spec: 
  ports: 
    - port: 6379 
      protocol: TCP 
      targetPort: 6379 
      nodePort: 30009 
  selector: 
    app: gem-yx-t-redis 
  type: NodePort

redis5.0镜像制作

FROM centos:centos7
#安装编译必备组件
RUN yum -y install epel*
RUN yum -y install iftop htop unzip net-tools
RUN yum -y install openssh-clients  
RUN yum -y install gcc gcc-c++ ncurses-devel pcre* openssl* zlib zlib-devel wget net-snmp-devel curl-devel perl-DBI
# 复制并解压缩
ADD redis-5.0.5.tar.gz /usr/local
#编译安装
RUN cd /usr/local/redis-5.0.5 && make && make PREFIX=/usr/local/redis install
RUN mkdir /usr/local/redis/etc
RUN cd /usr/local/redis/bin/
RUN cp /usr/local/redis/bin/redis-server /usr/bin/
#复制redis配置文件
ADD redis.conf /usr/local/redis/etc/
# 暴露端口
EXPOSE 6379
# 容器运行时默认启动redis服务
CMD ["redis-server","/usr/local/redis/etc/redis.conf"]

redis配置文件

protected-mode no
tcp-backlog 511
timeout 0
tcp-keepalive 300
daemonize yes   #k8s里面一定要改成no
supervised no
pidfile /var/run/redis_6379.pid
loglevel notice
logfile "/usr/local/redis/logs/redis.log"
databases 16
always-show-logo yes
save 900 1
save 300 10
save 60 10000
stop-writes-on-bgsave-error yes
rdbcompression yes
rdbchecksum yes
dbfilename dump.rdb
dir ./
replica-serve-stale-data yes
replica-read-only yes
repl-diskless-sync no
repl-diskless-sync-delay 5
repl-disable-tcp-nodelay no
replica-priority 100
requirepass rP9yf2M1jGwNNjAT
lazyfree-lazy-eviction no
lazyfree-lazy-expire no
lazyfree-lazy-server-del no
replica-lazy-flush no
appendonly no
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
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
bind 0.0.0.0
port 6379
daemonize no
supervised no
# redis服务pid进程文件名
pidfile "/var/run/redis.pid"
# 关闭保护模式,并配置使用密码访问
protected-mode no
requirepass 123456
# 数据文件保存路径,rdb/AOF文件也保存在这里
dir "/data"
# 大客户端连接数
maxclients 10000

# 客户端连接空闲多久后断开连接,单位秒,0表示禁用
timeout 300
tcp-keepalive 60 
# 内存初始化
maxmemory 1gb
maxmemory-policy volatile-lru
slowlog-max-len 128
lua-time-limit 5000

# Redis 数据持久化(rdb/aof)配置
# 数据自动保存脚本条件例如300s中有10key发生变化
save 300 100
save 60 10000
# RDB 文件名
dbfilename "dump.rdb"
# 对RDB文件进行压缩,建议以(磁盘)空间换(CPU)时间。
rdbcompression yes
# 版本5的RDB有一个CRC64算法的校验和放在了文件的最后。这将使文件格式更加可靠。
rdbchecksum yes
# RDB自动触发策略是否启用,默认为yes
rdb-save-incremental-fsync yes

# AOF开启
appendonly yes
# AOF文件名
appendfilename "appendonly.aof"
# 可选值 always, everysec,no,建议设置为everysec
appendfsync everysec

# Redis风险命令重命名
# rename-command CONFIG b840fc02d524045429941cc15f59e41cb7be6c52
rename-command FLUSHDB b840fc02d524045429941cc15f59e41cb7be6c53
rename-command FLUSHALL b840fc02d524045429941cc15f59e41cb7be6c54
rename-command EVAL b840fc02d524045429941cc15f59e41cb7be6c55
rename-command DEBUG b840fc02d524045429941cc15f59e41cb7be6c56
# rename-command SHUTDOWN SHUTDOWN

你是否还在寻找稳定的海外服务器提供商?创新互联www.cdcxhl.cn海外机房具备T级流量清洗系统配攻击溯源,准确流量调度确保服务器高可用性,企业级服务器适合批量采购,新人活动首月15元起,快前往官网查看详情吧


当前标题:k8s使用YAML创建redis5.0-创新互联
网页网址:http://cqcxhl.cn/article/dhiood.html

其他资讯

在线咨询
服务热线
服务热线:028-86922220
TOP