【Azure Redis 缓存】Windows和Linux系统本地安装Redis, 加载dump.rdb中数据以及通过AOF日志文件追加数据

简介: 【Azure Redis 缓存】Windows和Linux系统本地安装Redis, 加载dump.rdb中数据以及通过AOF日志文件追加数据

任务描述

本次集中介绍使用Windows和Linux()搭建本地Redis服务器的步骤,从备份的RDB文件中加载数据,以及如何生成AOF文件和通过AOF文件想已经运行的Redis追加数据。

 

操作步骤

Windows版本

启动Redis-server

1:下载Redis for Windows的压缩包或者安装文件,此处通过下载zip文件作为示例:https://github.com/microsoftarchive/redis/releases

2:解压压zip包到本地Redis目录,通过CMD命令,启动Redis-server.exe文件。

3:新开CMD窗口。进入Reids目录,通过redis-cli连接到Redis server。

加载dump.rdb文件

把准备好的RDB文件改名为dump.rdb复制到本地与Redis-server.exe同级目录下,重新启动redis-server.exe

Redis-Server会默认从当前启动文件夹中加载dump的文件作为初始化数据。

C:\Program Files\Redis>redis-server
[32728] 24 Jan 19:56:21.300 # Warning: no config file specified, 
using the default config. In order to specify a config file use redis-server /path/to/redis.conf
                _._
           _.-``__ ''-._
      _.-``    `.  `_.  ''-._           Redis 3.2.100 (00000000/0) 64 bit
  .-`` .-```.  ```\/    _.,_ ''-._
 (    '      ,       .-`  | `,    )     Running in standalone mode
 |`-._`-...-` __...-.``-._|'` _.-'|     Port: 6379
 |    `-._   `._    /     _.-'    |     PID: 32728
  `-._    `-._  `-./  _.-'    _.-'
 |`-._`-._    `-.__.-'    _.-'_.-'|
 |    `-._`-._        _.-'_.-'    |           http://redis.io
  `-._    `-._`-.__.-'_.-'    _.-'
 |`-._`-._    `-.__.-'    _.-'_.-'|
 |    `-._`-._        _.-'_.-'    |
  `-._    `-._`-.__.-'_.-'    _.-'
      `-._    `-.__.-'    _.-'
          `-._        _.-'
              `-.__.-'

[32728] 24 Jan 19:56:21.303 # Server started, Redis version 3.2.100
[32728] 24 Jan 19:56:22.124 * DB loaded from disk: 0.821 seconds
[32728] 24 Jan 19:56:22.124 * The server is now ready to accept connections on port 6379

 

追加AOF数据

1:准备好aof文件,如无,可以通过redis命令BGREWRITEAOF生成最新的appendonly.aof文件

2:使用redis-cli --pipe命令,追加aof中的数据到Redis中。注: 此处的pipe后符号必须为 <

redis-cli --pipe  < appendonly.aof

 

Linux版本

启动Redis-server

使用任何方式登录进Linux虚拟机,如本地使用PuTTY,登录到Linux后,完完全全参考Redis的官网启动Reids服务:https://redis.io/download#installation

有三种方式安装Reids,从源代码,从Ubuntu PPA和从Snapcraft

From source code

Download, extract and compile Redis with:

$ wget https://download.redis.io/releases/redis-6.0.10.tar.gz
$ tar xzf redis-6.0.10.tar.gz
$ cd redis-6.0.10
$ make

The binaries that are now compiled are available in the src directory. Run Redis with:

$ src/redis-server

You can interact with Redis using the built-in client:

$ src/redis-cli
redis> set foo bar
OK
redis> get foo
"bar"
From the official Ubuntu PPA

You can install the latest stable version of Redis from the redislabs/redis package repository. Add the repository to the apt index, update it and install:

$ sudo add-apt-repository ppa:redislabs/redis
$ sudo apt-get update
$ sudo apt-get install redis
From Snapcraft

You can install the latest stable version of Redis from the Snapcraft marketplace:

$ sudo snap install redis

如当前使用的为Ubuntu的PPA命令安装和启动Redis服务:

复制RDB文件进入Linux

查看当前Linux中运行的Redis目录,使用redis-cli连接成功后,使用config get dir命令查看。

127.0.0.1:6379> config get dir
1) "dir"
2) "/var/lib/redis"

通常来讲,第二行数据的路径为当前Redis服务的启动路径,把RDB文件改名为dump.rdb后复制到该目录下

使用PSCP命令复制到/tmp目录,然后再Linux中使用root权限复制到/var/lib/redis目录

#在Windows中运行pscp命令。如遇见无法访问某个文件夹,则修改文件目录
#如pscp: unable to open /var/lib/redis/dump.rdb: permission denied,则导入文件到/tmp目录

pscp -pw Password "C:\Program Files\Redis\dump.rdb" username@192.168.135.195:/tmp

#在Linux中运行COPY命令
~$ sudo su ~$ cd /tmp :/tmp# cp dump.rdb /var/lib/redis

加载dump.rdb文件

当dump.rdb文件存在于redis目录后。重启Reids服务即可

关闭Redis Server有几种方式:

1)通过Redis-cli发送shutdown命令

2)redis-server stop 或者 redis-server start 命令

3)service redis-server stop 或者 service redis-server start 命令

注:如果在Linux已apt-get install redis-server安装后启动的Redis,则需要使用第三种方式停止Redis服务。

追加AOF数据

在Windows中,使用PSCP命令把准备好的AOF文件发送到Linux tmp目录中

在tmp目录下使用 redis-cli --pipe < appendonly.aof 追加aof日志到运行的Redis中。然后通过info Keyspace查看当前的信息

 

操作中遇见的错误:

1:no config file specified, using the default config. In order to specify a config file use redis-server /path/to/redis.conf

在redis的目录文件中,已经包含了redis.windows.config文件,可以在启动redis-server时指定config文件。如:redis-server redis.windows.conf

 

2:Creating Server TCP listening socket 127.0.0.1:6379: bind: No error

表明6379已经被占用,可以通过redis-cli连接上去。然后执行shutdown命令关闭已经运行的Redis-server, 重启即可。

SHUTDOWN & RESTART

 

 

参考资料:

Windows Redis: https://github.com/microsoftarchive/redis/releases

Reids官网:https://redis.io/download#installation

Linux Copy File Command:https://www.cyberciti.biz/faq/copy-command/

Redis Backup:https://www.w3resource.com/redis/redis-backup.php

Copy File:https://comtechies.com/copy-files-between-windows-and-linux.html

Putty Copy File:https://www.ssh.com/ssh/putty/putty-manuals/0.68/Chapter5.html

相关文章
WGLOG日志管理系统是怎么收集日志的
WGLOG通过部署Agent客户端采集日志,Agent持续收集指定日志文件并上报Server,Server负责展示与分析。Agent与Server需保持相同版本。官网下载地址:www.wgstart.com
|
7月前
|
Prometheus 监控 Cloud Native
基于docker搭建监控系统&日志收集
Prometheus 是一款由 SoundCloud 开发的开源监控报警系统及时序数据库(TSDB),支持多维数据模型和灵活查询语言,适用于大规模集群监控。它通过 HTTP 拉取数据,支持服务发现、多种图表展示(如 Grafana),并可结合 Loki 实现日志聚合。本文介绍其架构、部署及与 Docker 集成的监控方案。
654 122
基于docker搭建监控系统&日志收集
|
7月前
|
运维 安全 Linux
【清爽加速】Windows 11 Pro 24H2-Emmy精简系统
“清爽加速”Windows 11 Pro 24H2 针对老旧或低配设备,通过精简系统、优化服务与简化装机流程,降低资源占用,提升运行流畅度,兼顾安全性与稳定性,让老设备也能轻松应对日常办公与轻度娱乐需求。
429 1
【清爽加速】Windows 11 Pro 24H2-Emmy精简系统
|
7月前
|
缓存 Java 应用服务中间件
Spring Boot配置优化:Tomcat+数据库+缓存+日志,全场景教程
本文详解Spring Boot十大核心配置优化技巧,涵盖Tomcat连接池、数据库连接池、Jackson时区、日志管理、缓存策略、异步线程池等关键配置,结合代码示例与通俗解释,助你轻松掌握高并发场景下的性能调优方法,适用于实际项目落地。
1214 5
|
7月前
|
Ubuntu
在Ubuntu系统上设置syslog日志轮替与大小限制
请注意,在修改任何系统级别配置之前,请务必备份相应得原始档案并理解每项变更可能带来得影响。
839 2
|
7月前
|
安全 搜索推荐 开发者
【适度精简】Windows 7 旗舰版-emmy精简系统
Windows 7旗舰版因硬件占用高、冗余组件多、兼容性差及缺乏安全更新等问题,逐渐难以满足用户需求。适度精简版通过去除无用组件、优化性能与安全性,提升老旧设备运行效率,增强兼容性与稳定性,同时保留用户熟悉的操作界面,降低学习成本,满足个性化需求,延续Windows 7的实用价值。
347 2
|
7月前
|
安全 数据安全/隐私保护 Windows
ZyperWin++使用教程!让Windows更丝滑!c盘飘红一键搞定!ZyperWin++解决系统优化、Office安装和系统激活
ZyperWin++是一款仅5MB的开源免费Windows优化工具,支持快速优化、自定义设置与垃圾清理,兼具系统加速、隐私保护、Office安装等功能,轻便无广告,小白也能轻松上手,是提升电脑性能的全能管家。
2067 0
|
8月前
|
Ubuntu Linux Windows
windows11系统安装ubuntu系统详细步骤
安装后,您可以直接从商店启动应用程序来源
1487 0
|
存储 缓存 NoSQL
Spring Boot2.5 实战 MongoDB 与高并发 Redis 缓存|学习笔记
快速学习 Spring Boot2.5 实战 MongoDB 与高并发 Redis 缓存
Spring Boot2.5 实战 MongoDB 与高并发 Redis 缓存|学习笔记
|
缓存 NoSQL 安全
6.0Spring Boot 2.0实战 Redis 分布式缓存6.0|学习笔记
快速学习6.0Spring Boot 2.0实战 Redis 分布式缓存6.0。
636 0
6.0Spring Boot 2.0实战 Redis 分布式缓存6.0|学习笔记