redis on docker

redis介绍

# redis简介
1 基于key-value键值对的持久化的数据库存储系统
2 支持更多数据类型 字符串列表 集合 有序集合等,支持排序
3周期性把内存数据写入硬盘,持久化
4 支持主从同步

# 优点:
 性能高,100K/s
 丰富的数据类型
 原子性操作,原子性执行
 丰富的特性,支持publish/subscribe ,通知,key多起
 支持异机主从复制
 持久化存储数据

# 数据类型:
 符串 列表 集合 有序集合 hash

# 应用场景:
  1传统mysql+memcached遇到的问题
    需要mysql数据库不断的拆库拆表,memcached不断扩容
    mysql和memcached数据一致性问题
    memcached 命中率低,大量访问涌入mysql,压力大问题
    跨机房cache同步的一致性问题

  2redis场景
    redis最佳使用场景是全部数据进内存
    替代memcached
    支持数据类型
    支持数据持久化
 使   用bitmap进化成活跃用户统计
 需要负载均衡的场景(主从同步,一主多重)

容器上部署redis 单实例

一、安装docker

# 安装yum-config-manager配置工具
yum -y install yum-utils
# 建议使用阿里云yum源:(推荐)
#yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
# 安装docker-ce版本
yum install -y docker-ce
# 启动并开机启动
systemctl enable --now docker
docker --version

二、安装docker-compose

# 下载二进制文件
curl -SL \
https://github.com/docker/compose/releases/download/v2.16.0/docker-compose-linux-x86_64 \
-o /usr/local/bin/docker-compose
# 执行权限
chmod +x /usr/local/bin/docker-compose
# 测试版本
docker-compose --version

三、创建网络 与目录

# 创建,注意不能使用hadoop_network,要不然启动hs2服务的时候会有问题!!!
docker network create redis-network
# 查看
docker network ls

# 创建配置文件 数据目录
mkdir -p /data/redis_server/{data.conf}

四、创建单实例的redis配置文件

cat >/data/redis/conf/redis.conf<<EOF
protected-mode no
port 6379
tcp-backlog 511
timeout 0
tcp-keepalive 300
daemonize no
supervised no
pidfile "redis_6379.pid"
loglevel notice
logfile "redis_6379.log"
databases 16
always-show-logo yes
save 900 1
save 300 10
save 60 10000
rdbcompression yes
rdbchecksum yes
dbfilename "redis_dump_6379.rdb"
dir /data
slave-serve-stale-data yes
slave-read-only yes
repl-diskless-sync yes
repl-diskless-sync-delay 5
repl-ping-slave-period 10
repl-disable-tcp-nodelay no
repl-backlog-size 5mb
repl-timeout 60
slave-priority 100
maxclients 100000
lazyfree-lazy-eviction no
lazyfree-lazy-expire no
lazyfree-lazy-server-del no
slave-lazy-flush no
appendonly 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 "gxE"
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
stop-writes-on-bgsave-error no
requirepass Kc@123456
EOF

五、创建 redis.yaml

version: '3'
services:
  redis:
    image: redis:6.2.6
    container_name: redis
    restart: always
    ports:
      - 6379:6379
    volumes:
      - /data/redis/redis.conf:/usr/local/etc/redis/redis.conf:rw
      - /data/redis/data:/data:rw
    command:
      /bin/bash -c "redis-server /usr/local/etc/redis/redis.conf"

六、启动redis容器

docker-compose -f redis.yaml up -d

 

posted on 2024-12-25 14:53  luokeli  阅读(11)  评论(0)    收藏  举报

导航