docker-compose安装redis

news2024/9/23 23:24:17

基于docker-compose快速安装redis

目录

一、目录结构

1、docker-compose.yml

2、redis.conf

二、连接使用


一、目录结构

1、docker-compose.yml

version: '3'
services:
  redis:
    image: registry.cn-hangzhou.aliyuncs.com/zhengqing/redis:6.0.8                    # 镜像'redis:6.0.8'
    container_name: redis                                                             # 容器名为'redis'
    restart: unless-stopped                                                                   # 指定容器退出后的重启策略为始终重启,但是不考虑在Docker守护进程启动时就已经停止了的容器
    command: redis-server /etc/redis/redis.conf --requirepass hcses.com --appendonly no # 启动redis服务并添加密码为:123456,默认不开启redis-aof方式持久化配置
#    command: redis-server --requirepass 123456 --appendonly yes # 启动redis服务并添加密码为:123456,并开启redis持久化配置
    environment:                        # 设置环境变量,相当于docker run命令中的-e
      TZ: Asia/Shanghai
      LANG: en_US.UTF-8
    volumes:                            # 数据卷挂载路径设置,将本机目录映射到容器目录
      - "./redis/data:/data"
      - "./redis/config/redis.conf:/etc/redis/redis.conf"  # `redis.conf`文件内容`http://download.redis.io/redis-stable/redis.conf`
    ports:                              # 映射端口
      - "6379:6379"

2、redis.conf

# Redis configuration file example.
#
# Note that in order to read the configuration file, Redis must be
# started with the file path as first argument:
#
# ./redis-server /path/to/redis.conf

# Note on units: when memory size is needed, it is possible to specify
# it in the usual form of 1k 5GB 4M and so forth:
#
# 1k => 1000 bytes
# 1kb => 1024 bytes
# 1m => 1000000 bytes
# 1mb => 1024*1024 bytes
# 1g => 1000000000 bytes
# 1gb => 1024*1024*1024 bytes
#
# units are case insensitive so 1GB 1Gb 1gB are all the same.

################################## INCLUDES ###################################

# Include one or more other config files here.  This is useful if you
# have a standard template that goes to all Redis servers but also need
# to customize a few per-server settings.  Include files can include
# other files, so use this wisely.
#
# Notice option "include" won't be rewritten by command "CONFIG REWRITE"
# from admin or Redis Sentinel. Since Redis always uses the last processed
# line as value of a configuration directive, you'd better put includes
# at the beginning of this file to avoid overwriting config change at runtime.
#
# If instead you are interested in using includes to override configuration
# options, it is better to use include as the last line.
#
# include /path/to/local.conf
# include /path/to/other.conf

################################## MODULES #####################################

# Load modules at startup. If the server is not able to load modules
# it will abort. It is possible to use multiple loadmodule directives.
#
# loadmodule /path/to/my_module.so
# loadmodule /path/to/other_module.so

################################## NETWORK #####################################

# By default, if no "bind" configuration directive is specified, Redis listens
# for connections from all the network interfaces available on the server.
# It is possible to listen to just one or multiple selected interfaces using
# the "bind" configuration directive, followed by one or more IP addresses.
#
# Examples:
#
# bind 192.168.1.100 10.0.0.1
# bind 127.0.0.1 ::1
#
# ~~~ WARNING ~~~ If the computer running Redis is directly exposed to the
# internet, binding to all the interfaces is dangerous and will expose the
# instance to everybody on the internet. So by default we uncomment the
# following bind directive, that will force Redis to listen only into
# the IPv4 loopback interface address (this means Redis will be able to
# accept connections only from clients running into the same computer it
# is running).
#
# IF YOU ARE SURE YOU WANT YOUR INSTANCE TO LISTEN TO ALL THE INTERFACES
# JUST COMMENT THE FOLLOWING LINE.
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 注释允许外部访问redis
# bind 127.0.0.1

# Protected mode is a layer of security protection, in order to avoid that
# Redis instances left open on the internet are accessed and exploited.
#
# When protected mode is on and if:
#
# 1) The server is not binding explicitly to a set of addresses using the
#    "bind" directive.
# 2) No password is configured.
#
# The server only accepts connections from clients connecting from the
# IPv4 and IPv6 loopback addresses 127.0.0.1 and ::1, and from Unix domain
# sockets.
#
# By default protected mode is enabled. You should disable it only if
# you are sure you want clients from other hosts to connect to Redis
# even if no authentication is configured, nor a specific set of interfaces
# are explicitly listed using the "bind" directive.
# 开启保护模式后,需要 bind ip 或 设置密码
protected-mode yes

# Accept connections on the specified port, default is 6379 (IANA #815344).
# If port 0 is specified Redis will not listen on a TCP socket.
port 6379

# TCP listen() backlog.
#
# In high requests-per-second environments you need an high backlog in order
# to avoid slow clients connections issues. Note that the Linux kernel
# will silently truncate it to the value of /proc/sys/net/core/somaxconn so
# make sure to raise both the value of somaxconn and tcp_max_syn_backlog
# in order to get the desired effect.
tcp-backlog 511

# Unix socket.
#
# Specify the path for the Unix socket that will be used to listen for
# incoming connections. There is no default, so Redis will not listen
# on a unix socket when not specified.
#
# unixsocket /tmp/redis.sock
# unixsocketperm 700

# Close the connection after a client is idle for N seconds (0 to disable)
timeout 0

# TCP keepalive.
#
# If non-zero, use SO_KEEPALIVE to send TCP ACKs to clients in absence
# of communication. This is useful for two reasons:
#
# 1) Detect dead peers.
# 2) Take the connection alive from the point of view of network
#    equipment in the middle.
#
# On Linux, the specified value (in seconds) is the period used to send ACKs.
# Note that to close the connection the double of the time is needed.
# On other kernels the period depends on the kernel configuration.
#
# A reasonable value for this option is 300 seconds, which is the new
# Redis default starting with Redis 3.2.1.
tcp-keepalive 300
daemonize no

supervised no

pidfile /var/run/redis_6379.pid

loglevel notice

logfile ""

databases 16

always-show-logo yes

# 900秒内,如果超过1个key被修改,则发起快照保存
save 900 1
# 300秒内,如果超过10个key被修改,则发起快照保存
save 300 10
# 60秒内,如果1万个key被修改,则发起快照保存
save 60 10000


stop-writes-on-bgsave-error yes


rdbcompression yes


rdbchecksum yes

dbfilename dump.rdb


rdb-del-sync-files no


dir ./




replica-serve-stale-data yes



repl-diskless-sync no


repl-diskless-sync-delay 5

repl-diskless-load disabled



repl-disable-tcp-nodelay no




replica-priority 100


# 设置密码
# requirepass 123456



lazyfree-lazy-eviction no
lazyfree-lazy-expire no
lazyfree-lazy-server-del no
replica-lazy-flush no


lazyfree-lazy-user-del no

oom-score-adj no

oom-score-adj-values 0 200 800



appendonly no

# The name of the append only file (default: "appendonly.aof")

appendfilename "appendonly.aof"



# 每次操作都会立即写入aof文件中
# appendfsync always
# 每秒持久化一次(默认配置)
appendfsync everysec
# 不主动进行同步操作,默认30s一次
# appendfsync no



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

jemalloc-bg-thread yes

二、连接使用

为了方便使用,建议下载个Redis Desktop Manager 可视化工具。

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/986252.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

高通DSP架构和HVX指令介绍

1. Qualcomm Snapdragon™处理器 Qualcomm Snapdragon™是高通的移动平台处理器,是一种系统级芯片(SoC),包含了CPU、GPU、DSP、调制解调器、无线电、摄像头处理器、安全处理器等多种功能。Snapdragon处理器广泛应用于智能手机、平板电脑、智能手表、智能音箱等移动设备中。…

使用ChatGLMTokenizer处理json格式数据

我下载了一些中文wikipedia数据,准备采用ChatGLMTokenizer对齐进行清洗,整理为预训练语料。 import numpy as np import json from tqdm import tqdm from chatglm_tokenizer.tokenization_chatglm import ChatGLMTokenizertokenizer ChatGLMTokenizer…

【算法专题突破】双指针 - 三数之和(7)

目录 1. 题目解析 2. 算法原理 3. 代码编写 写在最后: 1. 题目解析 题目链接:15. 三数之和 - 力扣(Leetcode) 题目就是要找出和为0的不重复的三元组, 注意三元组的每个元素是得不同的位置,那不重复又…

pnpm 升级

1. 在以下路径下删除pnpm包 2. 执行which pnpm,在结果目录中删除pnpm 3. sudo npm install -g pnpm 重新安装,node默认使用16

总结982

时间记录: 7:00~7:50早读,13年tex2 8:00~8:30列日任务知识点回顾 8:35~11:00数学108 11:17~11:56计网 2:30~4:09计网网课50min,做笔记10道题 4:22~6:23数据结构二叉树两道代码题 7:12~7:57数学进步本回顾 8:00…

深入探讨Kubernetes(K8s)在云原生架构中的关键作用和应用

文章目录 1. 容器化的应用程序管理2. 自动化扩展和负载均衡3. 容器编排和调度4. 存储管理5. 自动化滚动更新6. 多云和混合云部署7. 监控和日志8. 安全9. 社区支持和生态系统10. 未来展望案例 🎈个人主页:程序员 小侯 🎐CSDN新晋作者 &#x1…

webGIS外包开发框架及特点

WebGIS(Web地理信息系统)是一种用于在Web浏览器中展示和交互地理信息数据的技术。WebGIS开发需要使用特定的框架和工具来构建交互式地图应用程序。以下是一些常见的WebGIS开发框架以及它们的特点,希望对大家有所帮助。北京木奇移动技术有限公…

算法基础-数学知识-容斥原理、博弈论

容斥原理、博弈论 容斥原理890. 能被整除的数(二进制状态压缩版本,复杂度多一个Om)890. 能被整除的数(dfs版本) 博弈论无限制nim游戏AcWing 891. Nim游戏AcWing 892. 台阶-Nim游戏(待补) 集合版…

Spring Boot集成Elasticsearch实战

文章目录 一、简介二、安装与配置Elasticsearch三、集成Spring Boot与Elasticsearch1. 添加依赖与配置文件2. 创建Elasticsearch数据模型3. 定义Elasticsearch仓库接口4. 实现Elasticsearch数据操作 四、基本查询与索引操作1. 插入与更新数据2. 删除数据与索引3. 条件查询与分页…

aarch64 arm64 部署 stable diffusion webui 笔记 【3】

接上篇 aarch64 arm64 部署 stable diffusion webui 笔记 【2】继续安装其他依赖 gfpgan-CSDN博客 source venv/bin/activate export LD_LIBRARY_PATH/usr/local/lib64:/usr/local/lib:/usr/lib64:/usr/lib ./webui.sh 离线安装记录 (venv) [yeqiangceph3 stable-diffusio…

人脸识别技术,如何解决学校门禁安全?

在当今社会,学校安全已经成为一个备受关注的议题,而门禁监控系统已经成为学校管理和保障学生安全的重要工具之一。随着社会的不断发展和技术的不断进步,学校不再只是知识传授的场所,它们也成为了数百、数千甚至数万学生和教职员工…

【Spring Boot】JPA — JPA入门

JPA简介 1. JPA是什么 JPA是Sun官方提出的Java持久化规范,它为Java开发人员提供了一种对象/关联映射工具来管理Java应用中的关系数据,通过注解或者XML描述“对象-关系表”之间的映射关系,并将实体对象持久化到数据库中,极大地简…

欧洲云巨头OVHcloud收购边缘计算专家 gridscale

边缘计算社区近日获悉,欧洲云巨头OVHcloud已进入全面收购德国公司 gridscale 的谈判,该公司是一家专门从事超融合基础设施的软件提供商。 此次战略收购将标志着 OVHcloud 的另一个重要里程碑,使该集团能够显着加速其地理部署,并进…

智能化时代与智慧化时代

当今社会正处于快速发展的时代,科技的进步给我们带来了许多前所未有的机遇和挑战。在这个过程中,我们正逐步迈向智能化时代和智慧化时代,这两个时代代表了技术发展的不同阶段和方向。让我们深入了解这两个时代的概念、特点以及它们对未来的意…

发布 VectorTraits v1.0,它是 C# 下增强SIMD向量运算的类库

发布 VectorTraits v1.0, 它是C#下增强SIMD向量运算的类库 VectorTraits: SIMD Vector type traits methods (SIMD向量类型的特征方法). NuGet: https://www.nuget.org/packages/VectorTraits/1.0.0 源代码: https://github.com/zyl910/VectorTraits 用途 总所周知&#x…

Java死锁的原因及解决方法

要想知道死锁出现的原因和解决方法,首先得知道什么是死锁,死锁是两个或两个以上的运算单元(进程、线程或协程),互相持有对方所需的资源,导致它们都无法向前推进,从而导致永久阻塞的问题。从字面…

Spine2D骨骼动画播放器 - 微信小程序版

Spine2D骨骼动画播放器 - 微信小程序版 简介平台支持 界面预览使用说明演示视频 版本笨笨的小目标(废话)参考资料测试文件百度盘分享 相关文档 简介 本播放器是SpinePlayer的微信小程序版。由于官方并没有提供现成的运行库,只能自己改造。 设…

如何应用运营商大数据精准营销?

如何应用运营商大数据精准营销? 越来越多的企业逐渐觉察到运营商大数据所带来的商业价值,精准营销也被他们用的越来越娴熟。那么,企业的大数据精准营销该如何应用呢?想必是很多资源有限的中小型公司最想了解的。 一 数据驱动运营…

springCloud-LoadBalancer负载均衡

接上个博客springcloud-Eureka。 Eureka主要是如何通过eureka服务器进行服务注册与发现,也有简单的负载均衡,实际上它其中的负载均衡就是靠LoadBalancer实现的。 2020年前SpringCloud是采用Ribbon作为负载均衡实现,但是在2020后采用了LoadBal…

部署elasticsearch集群

创建es集群 编写一个docker-compose.yaml文件,内容如下 version: 2.2 services:es01:image: elasticsearch:7.12.1container_name: es01environment:- node.namees01- cluster.namees-docker-cluster- discovery.seed_hostses02,es03- cluster.initial_master_nod…