小飞知识库 | YeLu🤠MiLu🤪 小飞知识库 | YeLu🤠MiLu🤪
  • 函数式编程
  • Spring
  • SpringMVC
  • SpringBoot
  • SpringCloud
  • Mybatis
  • JVM
  • JUC并发编程
  • 设计模式
  • 单元测试
  • Redis
  • RabbitMQ
  • mysql
  • oracle
  • linux
  • nginx
  • docker
  • elasticSearch
  • windows
  • 虚拟机
  • 监控系统
  • https
  • 内网穿透
  • 前端文章

    • JavaScript
  • 页面

    • HTML
    • CSS
  • 学习笔记

    • 《JavaScript教程》
    • 《JavaScript高级程序设计》
    • 《ES6 教程》
    • 《Vue》
    • 《React》
    • 《TypeScript 从零实现 axios》
    • TypeScript
    • JS设计模式总结
  • 技术文档
  • GitHub技巧
  • Nodejs
  • 博客搭建
  • 版本管理

    • Git笔记
  • 项目构建

    • maven
  • 学习
  • 面试
  • 心情杂货
  • 实用技巧
  • 友情链接
  • JAR包相关
  • 关于
  • 收藏
  • 分类
  • 标签
  • 归档
GitHub (opens new window)

YeLu

爱技术的YeLu🤠
  • 函数式编程
  • Spring
  • SpringMVC
  • SpringBoot
  • SpringCloud
  • Mybatis
  • JVM
  • JUC并发编程
  • 设计模式
  • 单元测试
  • Redis
  • RabbitMQ
  • mysql
  • oracle
  • linux
  • nginx
  • docker
  • elasticSearch
  • windows
  • 虚拟机
  • 监控系统
  • https
  • 内网穿透
  • 前端文章

    • JavaScript
  • 页面

    • HTML
    • CSS
  • 学习笔记

    • 《JavaScript教程》
    • 《JavaScript高级程序设计》
    • 《ES6 教程》
    • 《Vue》
    • 《React》
    • 《TypeScript 从零实现 axios》
    • TypeScript
    • JS设计模式总结
  • 技术文档
  • GitHub技巧
  • Nodejs
  • 博客搭建
  • 版本管理

    • Git笔记
  • 项目构建

    • maven
  • 学习
  • 面试
  • 心情杂货
  • 实用技巧
  • 友情链接
  • JAR包相关
  • 关于
  • 收藏
  • 分类
  • 标签
  • 归档
GitHub (opens new window)
  • Redis

    • redis介绍

    • redis安装

      • 基础安装
        • 1、将.gz复制到 /usr/local
        • 2、解压.gz
        • 3、安装c语言编译环境
        • 4、进入解压根目录进行编译
        • 5、进入src目录进行安装
        • 6、创建两个文件夹
        • 7、将配置文件复制到etc目录
        • 8、将运行命令复制到bin目录下
        • 9、启动服务端
        • 10、启动客户端
        • 11、关闭服务
        • 12、查看redis进程状态
        • 13、测试
        • 14、改配置文件后台启动redis
        • 15、修改配置文件允许外网访问
        • 16、外部无法访问常见问题
    • redis基础

    • redis进阶

  • 缓存
  • Redis
  • redis安装
YeLu🤠
2023-04-04
目录

基础安装

官网 (opens new window)

# 1、将.gz复制到 /usr/local

cp /root/redis-5.0.7.tar.gz /usr/local
# 第二种方式通过源码方式安装
wget http://download.redis.io/releases/redis-5.0.7.tar.gz
1
2
3

# 2、解压.gz

cd /usr/local
tar -zxvf redis-5.0.7.tar.gz
1
2

# 3、安装c语言编译环境

yum install gcc
1

# 4、进入解压根目录进行编译

cd /usr/local/redis-5.0.7
make
1
2

# 5、进入src目录进行安装

cd /usr/localredis-5.0.7/src
make install
1
2

# 6、创建两个文件夹

mkdir -p /usr/local/redis/bin
mkdir -p /usr/local/redis/etc
1
2

# 7、将配置文件复制到etc目录

cd /usr/local/redis-5.0.7
cp redis.conf /usr/local/redis/etc/
1
2

# 8、将运行命令复制到bin目录下

cd /src
mv mkreleasehdr.sh redis-benchmark redis-check-aof redis-check-dump redis-cli redis-server /usr/local/redis/bin
1
2

# 9、启动服务端

cd /usr/local/redis/bin
./redis-server /usr/local/redis/etc/redis.conf

redis启动
第一种方式 默认无密码启动方式 ./redis-server 或者 ./redis-server --port 6380
如果设置密码,这种方式启动redis,调用时就会出现异常 Caused by: redis.clients.jedis.exceptions.JedisDataException: ERR Client sent AUTH, but no password is set
第二种 已设置访问密码启动方式 ./redis-server …/redis.conf
1
2
3
4
5
6
7

# 10、启动客户端

cd /usr/local/redis/bin
./redis-cli
./redis-cli -h 127.0.0.1 -p 6379 -a QE%^E3323BAHBSGA1932ASKJA/123456 # 这个是设置了密码的启动客户端
1
2
3

# 11、关闭服务

# 如果是用apt-get或者yum install安装的redis,可以直接通过下面的命令停止/启动/重启redis
/etc/init.d/redis-server stop
/etc/init.d/redis-server start
/etc/init.d/redis-server restart
# 如果是通过源码安装的redis,则可以通过redis的客户端程序redis-cli的shutdown命令来重启redis
1.redis关闭
redis-cli -h 127.0.0.1 -p 6379 shutdown
redis-cli -h 127.0.0.1 -p 6379 -a password shutdown
# 如果上述方式都没有成功停止redis,则可以使用 kill -9 杀死redis进程
1
2
3
4
5
6
7
8
9

# 12、查看redis进程状态

ps -ef | grep redis
1

# 13、测试

set xff 124
get xff
1
2

# 14、改配置文件后台启动redis

vim ../etc/redis.conf
修改 配置文件中 daemonize 设置为 yes 即可
1
2

# 15、修改配置文件允许外网访问

  • 若以上配置修改之后,防火墙也关闭了,但是外部也无法访问redis这个时候需要修改redis配置
cd /usr/local/redis/etc
vim redis.conf
1
2
  • 打开cmd 然后使用 telnet ip 端口 来ping 配置的redis(要保证redis已启动),发现无法ping通。
  • 这是因为在redis.conf中有个配置 bind 127.0.0.1 这个是默认只有本机访问,把这个注释掉就好了
  • 注释掉之后,先关闭redis服务,然后在启动服务,之后监控redis进程如下
cd /usr/local/redis/bin 进入bin目录下
./redis-cli -h 127.0.0.1 -p 6379 shutdown 关闭redis服务
./redis-server /usr/local/redis/etc/redis.conf 启动redis服务
ps -ef | grep redis 查看redis进程
1
2
3
4
  • 这个*****号就表示允许其它用户访问了。然后在用打开本机的 cmd 使用 telnet ip 端口 就能ping通了

# 16、外部无法访问常见问题

  • 打开本机的 cmd 使用 telnet ip 端口若报如下的错:

  • -DENIED Redis is running in protected mode because protected mode is enabled, no bind address was specified, no authentication password is requested to clients. In this mode connections are only accepted from the loopback interface. If you want to connect from external computers to Redis you may adopt one of the following solutions: 1) Just disable protected mode sending the command 'CONFIG SET protected-mode no' from the loopback interface by connecting to Redis from the same host the server is running, however MAKE SURE Redis is not publicly accessible from internet if you do so. Use CONFIG REWRITE to make this change permanent. 2) Alternatively you can just disable the protected mode by editing the Redis configuration file, and setting the protected mode option to 'no', and then restarting the server. 3) If you started the server manually just for testing, restart it with the '--protected-mode no' option. 4) Setup a bind address or an authentication password. NOTE: You only need to do one of the above things in order for the server to start accepting connections from the outside.

  • 出现如上错误,说明Redis服务的配置需要调整,即Redis开启了保护模式(默认开启),同时Redis又没有设置访问密码造成的。仔细阅读报错,可以发现,Redis提供了4中解决该报错的方式,具体如下:

线程“main”中的异常 redis.clients.jedis.exceptions.JedisDataException:DENIED Redis 正在保护模式下运行,因为已启用保护模式,未指定绑定地址,未向客户端请求身份验证密码。在此模式下,仅接受来自环回接口的连接。
如果您想从外部计算机连接到 Redis,您可以采用以下解决方案之一:
1) 只需禁用保护模式,通过从与服务器相同的主机连接到 Redis,从环回接口发送命令“CONFIG SET protected-mode no”正在运行,但是如果这样做,请确保 Redis 不能从 Internet 公开访问。使用 CONFIG REWRITE 使此更改永久化。
2) 或者,您可以通过编辑 Redis 配置文件 redis.conf 并将保护模式选项设置为"no", 即把protected-mode yes修改成protected-mode no,然后重新启动服务器来禁用保护模式。
3) 如果您手动启动服务器只是为了测试,请使用"--protected-mode no"选项重新启动它。 
4) 设置绑定地址或认证密码即设置bind的地址和Redis密码。这种方式是在正式、联网环境可以安全使用的方法
注意:您只需要执行上述操作之一,服务器就可以开始接受来自外部的连接。

1
2
3
4
5
6
7
8
#redis
最近更新: 2025/07/30, 15:37:56
redis介绍
五种数据类型

← redis介绍 五种数据类型→

最近更新
01
服务端配置
07-30
02
frp 安装
07-30
03
Prometheus采集Springboot应用
02-20
更多文章>
Theme by Vdoing | Copyright © 2019-2025 | YeLu🤠MiLu🤪 | MIT License 蜀ICP备2024116879号 | 川公网安备51012202001998号
  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式
欢迎你,我的朋友
看板娘