赞
踩
redis是一款基于BSD协议,开源的非关系型数据库(nosql数据库),作者是意大利开发者Salvatore Sanfilippo在2009年发布,使用C语言编写;redis是基于内存存储,而且是目前比较流行的键值数据库(key-value database),它提供将内存通过网络远程共享的一种服务,提供类似功能的还有memcache,但相比 memcache,redis 还提供了易扩展、高性能、具备数据持久性等功能。主要的应用场景有session共享,常用于web集群中的tomcat或PHP中多web服务器的session共享;消息队列,ELK的日志缓存,部分业务的订阅发布系统;计数器,常用于访问排行榜,商品浏览数等和次数相关的数值统计场景;缓存,常用于数据查询、电商网站商品信息、新闻内容等;相对memcache,redis支持数据的持久化,可以将内存的数据保存在磁盘中,重启redis服务或者服务器之后可以从备份文件中恢复数据到内存继续使用。
由于redis的数据(主要是redis快照)都存放在存储系统中,即便redis pod挂掉,对应数据都不会丢;因为在k8s上部署redis单机,redis pod挂了,k8s会将对应pod重建,重建时会把对应pvc挂载至pod中,加载快照,从而使得redis的数据不被pod的挂掉而丢数据;
- root@k8s-master01:~/k8s-data/dockerfile/web/magedu/redis# ll
- total 1784
- drwxr-xr-x 2 root root 4096 Jun 5 15:22 ./
- drwxr-xr-x 11 root root 4096 Aug 9 2022 ../
- -rw-r--r-- 1 root root 717 Jun 5 15:20 Dockerfile
- -rwxr-xr-x 1 root root 235 Jun 5 15:21 build-command.sh*
- -rw-r--r-- 1 root root 1740967 Jun 22 2021 redis-4.0.14.tar.gz
- -rw-r--r-- 1 root root 58783 Jun 22 2021 redis.conf
- -rwxr-xr-x 1 root root 84 Jun 5 15:21 run_redis.sh*
- root@k8s-master01:~/k8s-data/dockerfile/web/magedu/redis# cat Dockerfile
- #Redis Image
- # 导入自定义centos基础镜像
- FROM harbor.ik8s.cc/baseimages/magedu-centos-base:7.9.2009
- # 添加redis源码包至/usr/local/src
- ADD redis-4.0.14.tar.gz /usr/local/src
- # 编译安装redis
- RUN ln -sv /usr/local/src/redis-4.0.14 /usr/local/redis && cd /usr/local/redis && make && cp src/redis-cli /usr/sbin/ && cp src/redis-server /usr/sbin/ && mkdir -pv /data/redis-data
- # 添加redis配置文件
- ADD redis.conf /usr/local/redis/redis.conf
- # 暴露redis服务端口
- EXPOSE 6379
-
- #ADD run_redis.sh /usr/local/redis/run_redis.sh
- #CMD ["/usr/local/redis/run_redis.sh"]
- # 添加启动脚本
- ADD run_redis.sh /usr/local/redis/entrypoint.sh
- # 启动redis
- ENTRYPOINT ["/usr/local/redis/entrypoint.sh"]
- root@k8s-master01:~/k8s-data/dockerfile/web/magedu/redis# cat build-command.sh
- #!/bin/bash
- TAG=$1
- #docker build -t harbor.ik8s.cc/magedu/redis:${TAG} .
- #sleep 3
- #docker push harbor.ik8s.cc/magedu/redis:${TAG}
-
- nerdctl build -t harbor.ik8s.cc/magedu/redis:${TAG} .
- nerdctl push harbor.ik8s.cc/magedu/redis:${TAG}
- root@k8s-master01:~/k8s-data/dockerfile/web/magedu/redis# cat run_redis.sh
- #!/bin/bash
- # Redis启动命令
- /usr/sbin/redis-server /usr/local/redis/redis.conf
- # 使用tail -f 在pod内部构建守护进程
- tail -f /etc/hosts
- root@k8s-master01:~/k8s-data/dockerfile/web/magedu/redis# grep -v '^#\|^$' redis.conf
- bind 0.0.0.0
- protected-mode yes
- port 6379
- tcp-backlog 511
- timeout 0
- tcp-keepalive 300
- daemonize yes
- supervised no
- pidfile /var/run/redis_6379.pid
- loglevel notice
- logfile ""
- databases 16
- always-show-logo yes
- save 900 1
- save 5 1
- save 300 10
- save 60 10000
- stop-writes-on-bgsave-error no
- rdbcompression yes
- rdbchecksum yes
- dbfilename dump.rdb
- dir /data/redis-data
- slave-serve-stale-data yes
- slave-read-only yes
- repl-diskless-sync no
- repl-diskless-sync-delay 5
- repl-disable-tcp-nodelay no
- slave-priority 100
- requirepass 123456
- lazyfree-lazy-eviction no
- lazyfree-lazy-expire no
- lazyfree-lazy-server-del no
- slave-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 no
- 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
- activerehashing yes
- client-output-buffer-limit normal 0 0 0
- client-output-buffer-limit slave 256mb 64mb 60
- client-output-buffer-limit pubsub 32mb 8mb 60
- hz 10
- aof-rewrite-incremental-fsync yes
- root@k8s-master01:~/k8s-data/dockerfile/web/magedu/redis#
能够将redis镜像运行为容器,并且能够通过远程主机连接至redis进行数据读写,说明我们构建的reids镜像没有问题;
- root@harbor:~# mkdir -pv /data/k8sdata/magedu/redis-datadir-1
- mkdir: created directory '/data/k8sdata/magedu/redis-datadir-1'
- root@harbor:~# cat /etc/exports
- # /etc/exports: the access control list for filesystems which may be exported
- # to NFS clients. See exports(5).
- #
- # Example for NFSv2 and NFSv3:
- # /srv/homes hostname1(rw,sync,no_subtree_check) hostname2(ro,sync,no_subtree_check)
- #
- # Example for NFSv4:
- # /srv/nfs4 gss/krb5i(rw,sync,fsid=0,crossmnt,no_subtree_check)
- # /srv/nfs4/homes gss/krb5i(rw,sync,no_subtree_check)
- #
- /data/k8sdata/kuboard *(rw,no_root_squash)
- /data/volumes *(rw,no_root_squash)
- /pod-vol *(rw,no_root_squash)
- /data/k8sdata/myserver *(rw,no_root_squash)
- /data/k8sdata/mysite *(rw,no_root_squash)
-
- /data/k8sdata/magedu/images *(rw,no_root_squash)
- /data/k8sdata/magedu/static *(rw,no_root_squash)
-
-
- /data/k8sdata/magedu/zookeeper-datadir-1 *(rw,no_root_squash)
- /data/k8sdata/magedu/zookeeper-datadir-2 *(rw,no_root_squash)
- /data/k8sdata/magedu/zookeeper-datadir-3 *(rw,no_root_squash)
-
-
- /data/k8sdata/magedu/redis-datadir-1 *(rw,no_root_squash)
-
- root@harbor:~# exportfs -av
- exportfs: /etc/exports [1]: Neither 'subtree_check' or 'no_subtree_check' specified for export "*:/data/k8sdata/kuboard".
- Assuming default behaviour ('no_subtree_check').
- NOTE: this default has changed since nfs-utils version 1.0.x
-
- exportfs: /etc/exports [2]: Neither 'subtree_check' or 'no_subtree_check' specified for export "*:/data/volumes".
- Assuming default behaviour ('no_subtree_check').
- NOTE: this default has changed since nfs-utils version 1.0.x
-
- exportfs: /etc/exports [3]: Neither 'subtree_check' or 'no_subtree_check' specified for export "*:/pod-vol".
- Assuming default behaviour ('no_subtree_check').
- NOTE: this default has changed since nfs-utils version 1.0.x
-
- exportfs: /etc/exports [4]: Neither 'subtree_check' or 'no_subtree_check' specified for export "*:/data/k8sdata/myserver".
- Assuming default behaviour ('no_subtree_check').
- NOTE: this default has changed since nfs-utils version 1.0.x
-
- exportfs: /etc/exports [5]: Neither 'subtree_check' or 'no_subtree_check' specified for export "*:/data/k8sdata/mysite".
- Assuming default behaviour ('no_subtree_check').
- NOTE: this default has changed since nfs-utils version 1.0.x
-
- exportfs: /etc/exports [7]: Neither 'subtree_check' or 'no_subtree_check' specified for export "*:/data/k8sdata/magedu/images".
- Assuming default behaviour ('no_subtree_check').
- NOTE: this default has changed since nfs-utils version 1.0.x
-
- exportfs: /etc/exports [8]: Neither 'subtree_check' or 'no_subtree_check' specified for export "*:/data/k8sdata/magedu/static".
- Assuming default behaviour ('no_subtree_check').
- NOTE: this default has changed since nfs-utils version 1.0.x
-
- exportfs: /etc/exports [11]: Neither 'subtree_check' or 'no_subtree_check' specified for export "*:/data/k8sdata/magedu/zookeeper-datadir-1".
- Assuming default behaviour ('no_subtree_check').
- NOTE: thi
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。