当前位置:网站首页>docker安装redis?如何配置持久化策略?
docker安装redis?如何配置持久化策略?
2022-07-26 16:08:00 【爱睡觉的小张】
一、拉取redis镜像
1.docker仓库找到想要的镜像版本
2.拉取镜像
docker pull redis:7.0.4二、安装docker并配置持久化策略
为什么要配置持久化?对持久化文件进行挂载?
如不配置持久化,当docker容器重启后,数据都会丢失。如果只是简单的在容器内部进行持久化配置,那当容器异常或不小心被删除后,所有的持久化也会丢失。
1.创建挂载文件目录
mkdir -p /home/redis/conf #挂载redis的配置文件
mkdir -p /home/redis/data #挂载aof及rdb文件2.获取redis.conf
(redis.conf建议与所拉取的镜像版本一致,不然启动可能会报错)
3.创建容器并启动
docker run --name redis -p 6379:6379 \
-v /home/redis/data:/data \
-v /home/redis/conf/redis.conf:/etc/redis/redis.conf --privileged=true -d redis:7.0.4 \
redis-server /etc/redis/redis.conf--privileged=true 给容器赋予root权限,否则无法appendonly
redis-server 使用后面的配置文件启动redis
docker容器启动时,会将宿主机/home/redis/conf/redis.conf 同步到容器 /etc/redis 内,随后容器以/etc/redis/redis.conf 这个路径的配置文件启动。
容器启动后,生成的持久化文件会映射到宿主机/home/redis/data下
(docker对容器的停止、重启也会触发快照的生成)
4.配置文件
只需要修改宿主机的配置文件,既/home/redis/conf/redis.conf 后重启容器就可生效。
RDB配置:
vi /home/redis/conf/redis.conf
输入
/SNAP回车找到RDB配置
配置rdb文件的存放路径,与上述映射路径一直,方便同步。
save的规则满足的情况下,会自动触发rdb规则
备份会自动在/home/redis/data生成一个dump.rdb文件
AOF配置:
输入 /appendonly 找到AOF配置
将appendonly 改为yes
备份会自动在/home/redis/data生成一个appendonly.aof文件
开启远程连接:
输入 /NETWORK 找到远程连接配置
边栏推荐
- Jointly discuss the opening of public data, and the "digital document scheme" appeared at the digital China Construction Summit
- 6种方法帮你搞定SimpleDateFormat类不是线程安全的问题
- 微信小程序---网络数据请求
- 【ARM学习(9) arm 编译器了解学习(armcc/armclang)】
- 修改mysql数据库root用户的密码
- [RCTF2015]EasySQL
- A firefox/chrome plug-in that visualizes browser history
- Paper: all models are wrong, but many are useful: all models are wrong, but many are useful: understand the importance of variables by studying a whole class of prediction models at the same time
- Re8: reading papers Hier spcnet: a legal stat hierarchy based heterogeneous network for computing legal case
- “核弹级” Log4j 漏洞仍普遍存在,并造成持续影响
猜你喜欢

DTS搭载全新自研内核,突破两地三中心架构的关键技术|腾讯云数据库

2022 latest Tibet Construction scaffolder (construction special operation) simulation exam questions and answers

spark-streaming状态流之mapWithState

ACL-IJCAI-SIGIR顶级会议论文报告会(AIS 2022)笔记3:对话和生成

Collection of open source expert opinions on trusted privacy computing framework "argot"

Bugku login1
![[ten thousand words long text] Based on LSM tree thought Net 6.0 C # realize kV database (case version)](/img/84/640de0bf779cd45498204909be56d1.png)
[ten thousand words long text] Based on LSM tree thought Net 6.0 C # realize kV database (case version)

TDengine 落地协鑫能科,数百亿数据压缩至 600GB

Google Earth engine - merra-2 m2t1nxlv: 1980 present global pressure, temperature, wind and other data sets

PAT甲级 1046 Shortest Distance
随机推荐
Pat grade a 1044 shopping in Mars
什么是GPIO,它有什么用
RE9: read the paper deal inductive link prediction for nodes having only attribute information
Collection of open source expert opinions on trusted privacy computing framework "argot"
Modify the password of the root user of MySQL database
【万字长文】使用 LSM-Tree 思想基于.Net 6.0 C# 实现 KV 数据库(案例版)
First knowledge of OpenGL (4) link shader
TDengine 落地协鑫能科,数百亿数据压缩至 600GB
ZABBIX 6.2.0 deployment
Activity之onCreate、onRestoreInstanceState恢复数据的区别
[physical simulation] the principle and practice of the simplest shape matching
PAT甲级 1046 Shortest Distance
[RCTF2015]EasySQL
Mapwithstate of spark streaming state flow
2022年全国最新消防设施操作员(高级消防设施操作员)考试试题及答案
Bugku login2
Reflections on the mystery of Silicon Valley
Clojure Web Development -- ring user guide
TKE集群节点max-pod是如何配置的
《硅谷之谜》读后感



