Docker 安装 Redis |学习笔记

本文涉及的产品
云数据库 Redis 版,社区版 2GB
推荐场景:
搭建游戏排行榜
简介: 快速学习 Docker 安装 Redis

开发者学堂课程【Docker 快速入门Docker 安装 Redis 】学习笔记,与课程紧密联系,让用户快速学习知识。

课程地址https://developer.aliyun.com/learning/course/850/detail/14054


Docker 安装 Redis


内容介绍:

一. 从 docker hub 上(阿里云加速器)拉取 redis 镜像到本地标签为3.2

二. 使用 redis3.2镜像创建容器(也叫运行镜像)


一. 从 docker hub上(阿里云加速器)拉取 redis 镜像到本地标签为3.2

Docker 上安装完mysql 后安装redis

# docker pull redis: 3.2 ( redis不限版本)

然后把3.2拉下

如图

image.png

这里 redis 应该小一点,此时 redis 75.99MB

# docker images

image.png

此时这个数据库已经作为镜像拉到了本地。


二. 使用 redis3.2 镜像创建容器(也叫运行镜像)

1.使用镜像

6379:6379

-v /zzyyuse/myredis/data:/data

-v /zzyyuse/myredis/conf/redis.conf:/usr/local/etc/redis/redis.conf

-d redis:3.2 redis-server /usr/localetc/redis/redis.conf

--appendonly yes

此时主机和docker 内部都是6379

#docker run -p

只要带端口的也可以映射别的底数。

两个 -v 需要注意 radis redis.conf

/zzyyuse/myredis/conf/redis.conf是一个路径,文件夹redis.conf 对应的是 /usr/local/etc/redis/redis.conf

-d 后台运行redis:3.2 redis-server

即把 /usr/local/etc/redis/redis.conf 弄起来

#appendonly yes 开启 lf ( lf比较重要),然后开始运行。

2. 在主机 /zzyyuse/myredis/conf/redis.conf 目录下新建 redis.conf 文件

vim /zzyyuse/myredis/conf/redis.conf/redis.conf

这里需要注意分清目录和 redis.conf 文件

举例:现在数值是6379,如果让 dockeer 上面的redis不用6379,并把docker里面的redis改成6381,应该怎么改

首先需要在主机上给一个 conf的配置文件,映射到容器里面

然后改主机的容器作用后再重新修改数据。

image.png/zzyyuse/myredis/conf/redis.conf 这3个是文件夹

后面的 /redis.conf 配置文件

Redis 最基本的配置文件

## Both the hard or the soft limit can be disabled by setting them to zero.

client-output-buffer-limit normal 0 0 0

client-output-buffer-limit slave 256mb 64mb 60

client-output-buffer-limit pubsub 32mb 8mb 60# Redis calls an internal function to perform many background tasks, like# closing connections of clients in timeout, purging expired keys that are

# never requested, and so forth.

## Not all tasks are performed with the same frequency, but Redis checks for

# tasks to perform according to the specified "hz" value.

## By default "hz" is set to 10. Raising the value will use more CPU when# Redis is idle, but at the same time will make Redis more responsive when# there are many keys expiring at the same time, and timeouts may be

#handled with more precision.

##The range is between 1 and 500, however a value over 100 is usually not#a good idea. Most users should use the default of 10 and raisethis up to

# 100 only in environments where very low latency is required.

hz 10# When a child rewrites the AOF file, if the following option is enabled

# the file will be fsync-ed every 32 MB of data generated. This is useful# in order to commit the file to the disk more incrementally and avoid

# big latency spikes.

aof-rewrite-incremental-fsync yes

:wq!

然后保存退出

# cd /zzyyuse/myredis/conf/

image.png

注意 conf下面的 drwxr-xr-x(在总用量4下面)是一个文件夹,而后面的 redis 下面才有我们需要的 redis.conf

(在总用量48下面)

接下来 #vimredis.confimage.png

(这个在 redis 基础课里面讲过)

但是注意要把

# bind 192.168.1.100 10.0.0.1

# bind 127.0.0.1::1

这里注掉,要绑定本机,并且应该开的地方开,改端口,然后退出

#dockerps

此时 redis:3.2 且 mysql : 5.6

STATUS 两个 up 都启动着

此时 mysql连接库,且外面也已经接, redis 也要连上

注意在启动的命令里面已经把redis-server 连接起来了

否则 up 就不会有一个radis3.2 服务,然后利用redis-cli把redis连接起来。

3.测试redis-cli 连接上来

#[ root@atguigu redis. conf]# docker exec -it ce38c8665cd5

redis-cli

127.0.0.1:6379> set k1 v1

OK

127.0.0.1:6379> set k2 v2

ОК

127.0.0.1:6379> set k3 c3

OK

0. 0. 1: 6379> SHUTDOWN

[ root@atguigu redis. conf]#

4.测试持久化文件生成

当前路径下面要测试一下持久化文件是否生产

此时需要 appendonly.aof ,这时退回主机输入

#root@atguigu redis. conf]# cd ..

[ root@atguigu conf]# 11

总用量4

drwxr-xr-x.2 root root 4096 7月 13 06:05 redis.conf

[ root@atguigu conf]# cd ..

[ root@atguigu myredis]# 11

总用量8

drwxr-xr-x.3 root root 4096 7月 13 06:03 conf

drwxr-xr-x.2 999 root 4096 7月 13 06:03 data

[ root@atguigu myredis]#

注意这里有个 data 对应之前那个 data

image.png

然后 root@atguigu myredis]# cd data/

[ root@atguigu data]# 11

总用量4

-rw-r--r--. 1 999 999 110 7月 13 06:06 appendonly.aof

root@atguigu data]# vim appendonly. Aof

相关实践学习
基于Redis实现在线游戏积分排行榜
本场景将介绍如何基于Redis数据库实现在线游戏中的游戏玩家积分排行榜功能。
云数据库 Redis 版使用教程
云数据库Redis版是兼容Redis协议标准的、提供持久化的内存数据库服务,基于高可靠双机热备架构及可无缝扩展的集群架构,满足高读写性能场景及容量需弹性变配的业务需求。 产品详情:https://www.aliyun.com/product/kvstore     ------------------------------------------------------------------------- 阿里云数据库体验:数据库上云实战 开发者云会免费提供一台带自建MySQL的源数据库 ECS 实例和一台目标数据库 RDS实例。跟着指引,您可以一步步实现将ECS自建数据库迁移到目标数据库RDS。 点击下方链接,领取免费ECS&RDS资源,30分钟完成数据库上云实战!https://developer.aliyun.com/adc/scenario/51eefbd1894e42f6bb9acacadd3f9121?spm=a2c6h.13788135.J_3257954370.9.4ba85f24utseFl
相关文章
|
23小时前
|
NoSQL Linux Redis
Redis的介绍,以及Redis的安装(本机windows版,虚拟机Linux版)和Redis常用命令的介绍
Redis的介绍,以及Redis的安装(本机windows版,虚拟机Linux版)和Redis常用命令的介绍
11 0
|
1天前
|
Java 应用服务中间件 云计算
在Docker中安装Tomact
在Docker中安装Tomact
|
1天前
|
Java Shell 开发者
都2024年了!你还不知道在Docker中安装jdk?
都2024年了!你还不知道在Docker中安装jdk?
|
1天前
|
JSON Linux 数据格式
在宝塔Linux中安装Docker
在宝塔Linux中安装Docker
|
4天前
|
存储 Linux Docker
arm安装docker与docker-copose
现在,你已经成功在ARM架构的设备上安装了Docker和Docker Compose。你可以使用它们来管理容器和容器化应用程序。请注意,ARM设备上的Docker支持可能受到限制,某些容器可能不兼容。确保你的容器映像支持ARM架构,以便在ARM设备上正确运行。
16 6
|
8天前
|
NoSQL Redis Docker
使用docker安装redis
该文档介绍了如何使用Docker快速搭建Redis数据库,以便于Spring Boot学习。主要内容包括获取Redis镜像、创建容器、配置持久化存储目录和修改默认配置文件,以及检查和访问Redis容器服务。此外,还提到若需外部访问,需开启宿主机防火墙相应端口。注意,本教程不深入讲解Docker,若想深入学习Docker,建议另寻专门课程。
|
8天前
|
Linux Docker 容器
centos7安装docker图文详解
该文档提供了在CentOS上安装Docker的步骤:检查系统内核版本(需大于3.10),更新yum,卸载旧版Docker,安装yum-utils和依赖包,设置Docker仓库,列出并选择Docker版本,安装Docker,最后启动并设置Docker开机启动,通过`docker version`验证安装是否成功。
|
8天前
|
NoSQL 网络协议 MongoDB
docker安装mongodb(单点)图文详解
该文档提供了一个快速搭建MongoDB环境的指南,适用于开发和学习,但不适用于生产。主要步骤包括:1) 使用Docker创建数据卷`mongo_data_db`和`mongo_data_configdb`。2) 拉取`mongo`镜像并运行名为`mymongo`的容器,映射端口并挂载数据卷。3) 初始化管理员账号,创建具有`root`权限的用户`admin`,密码为`adminpwd`。4) 防火墙开放端口27017。最后,提到了使用第三方客户端进行连接。
|
6月前
|
NoSQL Redis Docker
Mac下Docker安装Redis
Mac下Docker安装Redis
295 0
|
3月前
|
NoSQL Redis Docker
在docker中安装redis,并且阿里云服务器配置
在docker中安装redis,并且阿里云服务器配置
192 1