使用docker-compose进行redis服务的配置和部署
最编程
2024-08-14 22:38:27
...
前言
在使用docker部署redis的时候,遇到很多坑,在此记录下遇到的问题
一、安装docker和docker-compose
### 安装docker
curl -sSL https://get.daocloud.io/docker | sh
### 启动docker
systemctl start docker
### 安装docker-compose
curl -L https://get.daocloud.io/docker/compose/releases/download/1.24.1/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose
### 将可执行权限应用于二进制文件
chmod +x /usr/local/bin/docker-compose
二、下载redis版本,本文中选择的是6.2.6版本
下载网址:download.redis.io/releases/
三、解压并复制redis.conf配置文件到服务器上,本文是放在/etc/redis/redis.conf
四、修改redis.conf配置文件
### 指定redis绑定的主机地址,注释掉这部分,使redis可以外部访问
# bind 127.0.0.1 -::1
### 指定访问redis服务端的端口
port 6379
### 指定客户端连接redis服务器时,当闲置的时间为多少(如300)秒时关闭连接(0表示禁用)
timeout 0
### 默认情况下,Redis不作为守护进程运行。如果需要,请使用“yes”
daemonize no
### 给redis设置密码,不需要密码的话则注释
# requirepass foobared
### 开启redis持久化,默认为no
appendonly yes
### 防止出现远程主机强迫关闭了一个现有的连接的错误 默认是300
tcp-keepalive 300
### 指定redis数据库的日志级别,常用的日志级别有debug、verbose、notice、warning,不进行修改的情况下默认的是notice
loglevel notice
### 指定redis数据库多长时间内(s)有多少次(c)更新操作时就把缓存中的数据同步到本地库,比如:save 600 2,指的是10分钟内有2次更新操作,就同步到本地库
save <s><c>
### 指定redis的最大内存。由于Redis 在启动时会把数据加载到内存中,当数据达到最大内存时,redis会自动把已经到期和即将到期的key值。所以可以根据需求调整自己的所需的最大内存
maxmemory 500mb
### 设置了maxmemory的选项,redis内存使用达到上限。可以通过设置LRU算法来删除部分key,释放空间。默认是按照过期时间的,如果set时候没有加上过期时间就会导致数据写满maxmemory
maxmemory-policy volatile-lru
### 设置外部网络连接redis服务,开启需配置bind ip或者设置访问密码,关闭此时外部网络可以直接访问
# protected-mode yes
五、配置docker-compose.yml
my_redis:
image: redis:6.2.6-alpine # 指定服务镜像,最好是与之前下载的redis配置文件保持一致
container_name: my_redis # 容器名称
restart: on-failure # 重启方式
environment:
- TZ=Asia/Shanghai # 设置时区
volumes: # 配置数据卷
- /root/redis/data:/data
- /etc/redis/redis.conf:/etc/redis/redis.conf
ports: # 映射端口
- "6380:6379"
sysctls: # 设置容器中的内核参数
- net.core.somaxconn=1024
# - vm.overcommit_memory=1
command: /bin/sh -c "echo 'vm.overcommit_memory = 1' >> /etc/sysctl.conf
&& redis-server /etc/redis/redis.conf --appendonly yes" # 指定配置文件并开启持久化
privileged: true # 使用该参数,container内的root拥有真正的root权限。否则,container内的root只是外部的一个普通用户权限
六、启动容器
### 启动容器
docker-compose up -d
### 进入容器
docker exec -it my_redis /bin/sh
### 进入客户端
redis-cli
### 如果设置了密码,需要输入auth 密码
auth 你的密码
### 查看已存储的key
keys *
### 查看redis信息
info
七、redis启动后遇到的问题
- Warning: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128 意思:无法强制执行TCP backlog设置511,因为/proc/sys/net/core/somaxconn被设置为较低的值128
echo "net.core.somaxconn=551" > /etc/sysctl.conf
sysctl net.core.somaxconn=551
- Warning:overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect
意思: overcommit_memory的值设置为0! 在内存不足的情况下,后台保存可能会失败。 要解决此问题,请将“vm.overcommit_memory = 1”添加到/etc/sysctl.conf,然后重新启动或运行命令“sysctl vm.overcommit_memory = 1”以使其生效
echo 1 > /proc/sys/vm/overcommit_memory
echo "vm.overcommit_memory=1" >> /etc/sysctl.conf
sysctl vm.overcommit_memory=1
- redis报错:RDB: 0 MB of memory used by copy-on-write
由于我redis.conf配置文件,配置了save,将缓存中的数据同步到本地库,所以我暂时的解决方法是取消保存,设置save ""
八、分享个redis可视化工具
redis-insight下载链接:redis.com/redis-enter…
上一篇: 进入程序员的世界:探索Linux挂载
下一篇: 在Linux中学习如何挂载新硬盘
推荐阅读
-
Java 8新特性探究(十三)JavaFX 8新特性以及开发2048游戏-JavaFX历史## 跟java在服务器端和web端成绩相比,桌面一直是java的软肋,于是Sun公司在2008年推出JavaFX,弥补桌面软件的缺陷,请看下图JavaFX一路走过来的改进 从上图看出,一开始推出时候,开发者需使用一种名为JavaFX Script的静态的、声明式的编程语言来开发JavaFX应用程序。因为JavaFX Script将会被编译为Java bytecode,程序员可以使用Java代码代替。 JavaFX 2.0之后的版本摒弃了JavaFX Script语言,而作为一个Java API来使用。因此使用JavaFX平台实现的应用程序将直接通过标准Java代码来实现。 JavaFX 2.0 包含非常丰富的 UI 控件、图形和多媒体特性用于简化可视化应用的开发,WebView可直接在应用中嵌入网页;另外 2.0 版本允许使用 FXML 进行 UI 定义,这是一个脚本化基于 XML 的标识语言。 从JDK 7u6开始,JavaFx就与JDK捆绑在一起了,JavaFX团队称,下一个版本将是8.0,目前所有的工作都已经围绕8.0库进行。这是因为JavaFX将捆绑在Java 8中,因此该团队决定跳过几个版本号,迎头赶上Java 8。 ##JavaFx8的新特性 ## ###全新现代主题:Modena 新的Modena主题来替换原来的Caspian主题。不过在Application的start方法中,可以通过setUserAgentStylesheet(STYLESHEET_CASPIAN)来继续使用Caspian主题。 参考http://fxexperience.com/2013/03/modena-theme-update/ ###JavaFX 3D 在JavaFX8中提供了3D图像处理API,包括Shape3D (Box, Cylinder, MeshView, Sphere子类),SubScene, Material, PickResult, LightBase (AmbientLight 和PointLight子类),SceneAntialiasing等。Camera类也得到了更新。从JavaDoc中可以找到更多信息。 ###富文本 强化了富文本的支持 ###TreeTableView ###日期控件DatePicker 增加日期控件 ###用于 CSS 结构的公共 API
-
使用docker-compose进行redis服务的配置和部署
-
CentOS 7安装ipvsadm和Nginx,并进行基本配置与测试 下面是重写后的段落: 1. 关闭防火墙 2. 在浏览器中输入服务器IP地址并访问 3. 修改网页内容以区分不同的服务器 4. 配置lvs/nat,使用自定义的脚本 5. 检查ipvsadm设置的规则 6. 关闭防火墙 7. 测试LVS效果。
-
使用ipvsadm和脚本进行LVS的配置方法
-
Intellij IDEA 插件开发入门详解 - 如何添加 Application 和 Project Component,并创建 Action? 在本文中,我们将详细介绍如何在 IntelliJ IDEA 中添加 Application 和 Project Component,并且通过这些组件来创建一个简单的 Action。 首先,我们将在 src 目录上使用 Alt+Insert 快捷键打开 New 对话框,然后从中选择 Application Component 并输入名称如 MyComponent。接下来,我们在 MyComponent 类中添加一个 sayHello 方法并编写相关逻辑。 然后,我们需要为我们的插件添加一个 Action,使用户可以通过菜单或其它方式访问它。为此,我们将创建一个新的类 SayHelloAction 继承自 AnAction 类,并在 actionPerformed 方法中获取 Application 和 MyComponent 对象,最后调用 MyComponent 的 sayHello 方法。 最后,我们需要为我们的插件配置相关的文件以确保它可以正常运行。在本文中,我们将详细介绍如何进行这些配置。
-
如何使用LntonMedia免费版RTMP流媒体服务器进行C和GO语言数据转换的实操教程
-
HHKB BT 蓝牙键盘:装逼必备利器?" 使用HHKB BT 蓝牙键盘的心得体会 在互联网的世界里,越来越多的人都追求个性化和独特性,无论是穿着打扮,还是使用的电子产品,都能看到人们的创意和想法。最近我在网上看到了一款备受推崇的机械键盘——HHKB BT 蓝牙键盘。 HHKB BT 蓝牙键盘是一款由日本知名键盘制造商 Filco 生产的产品,被誉为程序员的信仰。其最大的特点就是采用了静电容轴,按键更加灵敏且耐用。此外,HHKB BT 蓝牙键盘还具有非常紧凑的设计,仅60个键位,非常适合长时间工作或编程的人士使用。 然而,当我收到 HHKB BT 蓝牙键盘并开始使用时,我发现了一些问题。首先,数字键整体向右移动了一位,这对于习惯使用数字键的人来说是一种困扰。其次,HHKB BT 蓝牙键盘的价格较高,并且只能通过代购购买,售后服务也不完善。 尽管存在这些问题,我还是对 HHKB BT 蓝牙键盘产生了浓厚的兴趣。我尝试将数字键重新排列,使其更适合我的使用习惯,同时我也开始学习如何更有效地使用 HHKB BT 蓝牙键盘进行编程。 总的来说,HHKB BT 蓝牙键盘是一款非常专业且高效的机械键盘,如果你是一位需要长时间使用键盘的开发者或者程序员,那么它绝对值得你考虑。当然,高昂的价格和售后服务的问题也需要你权衡一下是否值得投资。
-
【摩尔线程+Colossal-AI强强联手】MusaBert登上CLUE榜单TOP10:技术细节揭秘 - 技术实力:摩尔线程凭借"软硬兼备"的技术底蕴,让MusaBert得以从底层优化到顶层。其内置多功能GPU配备AI加速和并行计算模块,提供了全面的AI与科学计算支持,为AI推理和低资源条件下的大模型训练等场景带来了高效、经济且环保的算力。 - 算法层面亮点:依托Colossal-AI AI大模型开发系统,MusaBert在训练过程中展现出了卓越的并行性能与易用性,特别在预处理阶段对DataLoader进行了优化,适应低资源环境高效处理海量数据。同时,通过精细的建模优化、领域内数据增强以及Adan优化器等手段,挖掘和展示了预训练语言模型出色的语义理解潜力。基于MusaBert,摩尔线程自主研发的MusaSim通过对比学习方法微调,结合百万对标注数据,MusaSim在多个任务如语义相似度、意图识别和情绪分析中均表现出色。 - 数据资源丰富:MusaBert除了自家高质量语义相似数据外,还融合了悟道开源200GB数据、CLUE社区80GB数据,以及浪潮公司提供的1TB高质量数据,保证模型即便在较小规模下仍具备良好性能。 当前,MusaBert已成功应用于摩尔线程的智能客服与数字人项目,并广泛服务于语义相似度、情绪识别、阅读理解与声韵识别等领域。为了降低大模型开发和应用难度,MusaBert及其相关高质量模型代码已在Colossal-AI仓库开源,可快速训练优质中文BERT模型。同时,通过摩尔线程与潞晨科技的深度合作,仅需一张多功能GPU单卡便能高效训练MusaBert或更大规模的GPT2模型,显著降低预训练成本,进一步推动双方在低资源大模型训练领域的共享目标。 MusaBert荣登CLUE榜单TOP10,象征着摩尔线程与潞晨科技联合研发团队在中文预训练研究领域的领先地位。展望未来,双方将携手探索更大规模的自然语言模型研究,充分运用上游数据资源,产出更为强大的模型并开源。持续强化在摩尔线程多功能GPU上的大模型训练能力,特别是在消费级显卡等低资源环境下,致力于降低使用大模型训练的门槛与成本,推动人工智能更加普惠。而潞晨科技作为重要合作伙伴,将继续发挥关键作用。
-
【2022新手指南】Java编程进阶之路 - 六、技术架构篇 ### MySQL索引底层解析与优化实战 - 你会讲解MySQL索引的数据结构吗?性能调优技巧知多少? - Redis深度揭秘:你知道多少?从基础到哨兵、主从复制全梳理 - Redis持久化及哨兵模式详解,还有集群搭建和Leader选举黑箱打开 - Zookeeper是个啥?特性和应用场景大公开 - ZooKeeper集群搭建攻略及 Leader选举、读写一致性、共享锁实现细节 - 探究ZooKeeper中的Leader选举机制及其在分布式环境中的作用 - Zab协议深入剖析:原理、功能与在Zookeeper中的核心地位 - RabbitMQ全方位解读:工作模式、消费限流、可靠投递与配置策略 - 设计者视角:RabbitMQ过期时间、死信队列与延时队列实践指南 - RocketMQ特性和应用场景揭示:理解其精髓与差异化优势 - Kafka详细介绍:特性及广泛应用于实时数据处理的场景解析 - ElasticSearch实力揭秘:特性概述与作为搜索引擎的广泛应用 - MongoDB认知升级:非关系型数据库的优势阐述,安装与使用实战教学 - BIO/NIO/AIO网络模型对比:掌握它们的区别与在网络编程中的实际应用 - Netty带你飞:理解其超快速度背后的秘密,包括线程模型分析 - 网络通信黑科技:Netty编解码原理与常用编解码器的应用,Protostuff实战演示 - 解密Netty粘包与拆包现象,怎样有效应对这一常见问题 - 自定义Netty心跳检测机制,轻松调整检测间隔时间的艺术 - Dubbo轻骑兵介绍:核心特性概览,服务降级实战与其实现益处 - Dubbo三大神器解读:本地存根与本地伪装的实战运用与优势呈现 ----------------------- 七、结语与回顾
-
如何轻松使用JMeter进行HTTP接口测试 - 一步步教你设置线程组、 cookie、默认值与Sampler,加上响应断言和监听器,打造基础测试案例。针对复杂情况,将子系统和流程测试分类组织,确保数据一致性。同时,别忘了感谢阅读,给新手提供实战学习资源与全套测试指南,助你轻松踏上自动化测试之路! - 在"测试计划"点击右键,添加"线程组"并设定初始"线程数"和"循环次数" - 配置"HTTP Cookie管理器"与"Http请求默认值",输入目标系统信息,如域名、端口、协议等,让所有相关Sampler共享这些默认设置 - 在线程组内增加"HTTP Request"的Sampler,并填入接口详情,比如路径、请求方法及参数 - 添加"响应断言"检查接口返回结果,通过正则表达式验证预期结果 - 安装监听器,实时查看测试执行状况 - 如需处理流程性接口,请依次添加多个相关Sampler,关联前后请求间的上下文数据 特别提示:为了帮助大家避免学习中的曲折,我们准备了详尽的视频和文档资料库,无论你是软件测试的新手还是老司机,都能从中找到所需的全方位支持。只需点击下方链接加入我们的学习交流社群,就能立刻获取这份珍贵的学习宝藏!再次感谢您的耐心阅读,愿它成为您前行路上的一大助力!