Dcoker实战:Linux环境安装Redis图文教程

本文涉及的产品
Redis 开源版,标准版 2GB
推荐场景:
搭建游戏排行榜
云数据库 Tair(兼容Redis),内存型 2GB
简介: dockers 下载的redis 默认是没有 redis.conf 文件的,需要从官网下载,也可以使用我下载好的redis.conf 文件。对应的版本是7.0.2 。下载后将文件上传到 /home/redis/conf 里面去。

image_14ca7e16.png

今天给大家分享docker安装Redis图文教程,服务器版本为Centos8,希望对大家能有所帮助!

1.官网镜像版本查找

https://hub.docker.com/

image_f2893c1e.png

image_f65ff534.png

2、拉取redis镜像

docker pull redis:7.0.2

拉取redis镜像页面如下:

image_e6575446.png

3、创建redis 服务器挂在目录

mkdir /home/redis

mkdir /home/redis/data

mkdir /home/redis/conf

image_04f15bf9.png

4、下载redis.conf 文件

dockers 下载的redis 默认是没有 redis.conf 文件的,需要从官网下载,也可以使用我下载好的redis.conf 文件。对应的版本是7.0.2 。下载后将文件上传到 /home/redis/conf 里面去。

redis.conf 文件内容如下 已经去掉注释,如果需要特殊的配置去管网查看即可。

# Redis configuration file example.

# bind 127.0.0.1 -::1  #外网访问需要注释掉

protected-mode yes

port 6379

tcp-backlog 511

timeout 0

tcp-keepalive 300


daemonize no  

pidfile /var/run/redis_6379.pid


loglevel notice


logfile ""

databases 16

always-show-logo no


set-proc-title yes

proc-title-template "{
      
        
        title} {
      
        
        listen-addr} {
      
        
        server-mode}"

stop-writes-on-bgsave-error yes

rdbcompression yes

rdbchecksum yes

dbfilename dump.rdb

rdb-del-sync-files no

dir ./

replica-serve-stale-data yes

replica-read-only yes

repl-diskless-sync yes

repl-diskless-sync-delay 5

repl-diskless-sync-max-replicas 0

repl-diskless-load disabled

repl-disable-tcp-nodelay no

replica-priority 100

acllog-max-len 128

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


lazyfree-lazy-user-del no



lazyfree-lazy-user-flush no

oom-score-adj no

oom-score-adj-values 0 200 800

disable-thp yes

appendonly yes 

requirepass 654321

appendfilename "appendonly.aof"
appenddirname "appendonlydir"


appendfsync everysec

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
aof-timestamp-enabled no
slowlog-log-slower-than 10000
slowlog-max-len 128
latency-monitor-threshold 0
notify-keyspace-events ""
hash-max-listpack-entries 512
hash-max-listpack-value 64
list-max-listpack-size -2
list-compress-depth 0
set-max-intset-entries 512
zset-max-listpack-entries 128
zset-max-listpack-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

5、启动redis

docker run -p 6379:6379 --name redis -v /home/redis/conf/redis.conf:/etc/redis/redis.conf -v /home/redis/data:/data -d redis:7.0.2 redis-server /etc/redis/redis.conf --appendonly yes

参数说明:

  • - p 6379:6379 端口映射:前表示宿主主机部分:后表示容器部分。
  • --name redis 指定该容器名称,方便后续的查看和操作。
  • -v 挂载目录,规则与端口映射相同。
  • -d redis 表示后台启动redis
  • redis-server /etc/redis/redis.conf 以配置文件启动redis,加载容器内的conf文件,最终找到的是挂载的目录/home/redis/conf/redis.conf
  • appendonly yes 开启redis 持久化

image_3c835a2b.png

6、常用命令

docker ps |grep redis \# 查看redis 是否启动成功

image_1ec67a27.png

docker logs redis \# 查看docker容器中的redis日志

image_89d142b8.png

docker exec -it redis /bin/bash \#进入容器

docker exec -it redis redis-server -v \#查看redis版本 7.0.2

image_460950e2.png

设置防火墙命令

systemctl start firewalld #启动防火墙 
firewall-cmd --zone=public --add-port=6379/tcp --permanent # 设置Redis 6379 端口
:firewall-cmd --zone=public --add-port=9000/tcp --permanent 设置Portainer 9000 端口
firewall-cmd --reload #刷新防火墙

停止、重启、删除命令

docker stop redis #停止
docker start redis  #重启
docker rm redis  #删除容器
docker rmi redis #删除镜像```


[1.]: #1.%E5%AE%98%E7%BD%91%E9%95%9C%E5%83%8F%E7%89%88%E6%9C%AC%E6%9F%A5%E6%89%BE
[2_redis]: #2%E3%80%81%E6%8B%89%E5%8F%96redis%E9%95%9C%E5%83%8F
[3_redis]: #3%E3%80%81%E5%88%9B%E5%BB%BAredis%20%E6%9C%8D%E5%8A%A1%E5%99%A8%E6%8C%82%E5%9C%A8%E7%9B%AE%E5%BD%95
[4_redis.conf]: #4%E3%80%81%E4%B8%8B%E8%BD%BDredis.conf%20%E6%96%87%E4%BB%B6
[5_redis]: #5%E3%80%81%E5%90%AF%E5%8A%A8redis
相关实践学习
基于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
相关文章
|
3天前
|
安全 Linux 网络安全
Linux环境中安装和使用Paramiko
Linux环境中安装和使用Paramiko
27 12
|
1天前
|
NoSQL Redis 数据安全/隐私保护
Redis 最流行的图形化界面下载及使用超详细教程(带安装包)! redis windows客户端下载
文章提供了Redis最流行的图形化界面工具Another Redis Desktop Manager的下载及使用教程,包括如何下载、解压、连接Redis服务器以及使用控制台和查看数据类型详细信息。
13 6
Redis 最流行的图形化界面下载及使用超详细教程(带安装包)! redis windows客户端下载
|
1天前
|
Linux Docker 容器
Centos安装docker(linux安装docker)——超详细小白可操作手把手教程,包好用!!!
本篇博客重在讲解Centos安装docker,经博主多次在不同服务器上测试,极其的稳定,尤其是阿里的服务器,一路复制命令畅通无阻。
18 4
Centos安装docker(linux安装docker)——超详细小白可操作手把手教程,包好用!!!
|
1天前
|
存储 数据可视化 Java
震惊!如何在linux下部署项目,部署/运行jar包 超详细保姆级教程!
如何在Linux系统下部署和运行Java项目jar包,包括传输文件到Linux、使用nohup命令运行jar包、查看端口状态、杀死进程和查看项目运行状态,以及如何解决“没有主清单属性”的错误。
19 1
震惊!如何在linux下部署项目,部署/运行jar包 超详细保姆级教程!
|
11天前
|
Ubuntu Linux 网络安全
从头安装Arch Linux系统
本文记录了作者安装Arch Linux系统的过程,包括安装成果展示和遇到的疑难点及其解决方法,如硬盘不足、下载失败、设置时区、安装微码和配置无密码登录等。
从头安装Arch Linux系统
|
12天前
|
关系型数据库 MySQL Linux
Linux 安装 mysql 【使用 tar.gz | tar.xz安装包-离线安装】
在Linux系统中使用tar.xz压缩包安装MySQL数据库的详细步骤。包括下载MySQL压缩包,解压到指定目录,创建mysql用户和组,设置目录权限,初始化MySQL,配置my.cnf文件,启动服务,以及修改root用户密码。此外,还提供了如何设置Windows远程登录MySQL服务器的方法。
Linux 安装 mysql 【使用 tar.gz | tar.xz安装包-离线安装】
|
2天前
|
Java 关系型数据库 MySQL
Linux环境
Linux环境
14 5
|
2天前
|
Ubuntu Linux 数据安全/隐私保护
Linux的安装过程
Linux的安装过程
11 4
|
3天前
|
Linux 定位技术 虚拟化
Linux 安装
Linux 安装
12 5
|
1天前
|
NoSQL Redis 数据库
Redis 图形化界面下载及使用超详细教程(带安装包)! redis windows下客户端下载
文章提供了Redis图形化界面工具的下载及使用教程,包括如何连接本地Redis服务器、操作键值对、查看日志和使用命令行等功能。
8 0
Redis 图形化界面下载及使用超详细教程(带安装包)! redis windows下客户端下载