Redis开启远程访问

Redis开启远程访问

修改Redis相关配置

Redis默认只允许本地访问,若要redis可以远程访问,得先修改redis.conf中的配置。

(若是windows环境下,该配置文件名称为 redis.windows-service.conf

在redis安装目录下找到redis.conf文件并打开

复制代码
################################## NETWORK #####################################

# By default, if no "bind" configuration directive is specified, Redis listens
# for connections from all available network interfaces on the host machine.
# It is possible to listen to just one or multiple selected interfaces using
# the "bind" configuration directive, followed by one or more IP addresses.
# Each address can be prefixed by "-", which means that redis will not fail to
# start if the address is not available. Being not available only refers to
# addresses that does not correspond to any network interfece. Addresses that
# are already in use will always fail, and unsupported protocols will always BE
# silently skipped.
#
# Examples:
#
# bind 192.168.1.100 10.0.0.1     # listens on two specific IPv4 addresses
# bind 127.0.0.1 ::1              # listens on loopback IPv4 and IPv6
# bind * -::*                     # like the default, all available interfaces
#
# ~~~ WARNING ~~~ If the computer running Redis is directly exposed to the
# internet, binding to all the interfaces is dangerous and will expose the
# instance to everybody on the internet. So by default we uncomment the
# following bind directive, that will force Redis to listen only on the
# IPv4 and IPv6 (if available) loopback interface addresses (this means Redis
# will only be able to accept client connections from the same host that it is
# running on).
#
# IF YOU ARE SURE YOU WANT YOUR INSTANCE TO LISTEN TO ALL THE INTERFACES
# JUST COMMENT OUT THE FOLLOWING LINE.
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

 bind 127.0.0.1 -::1

# Protected mode is a layer of security protection, in order to avoid that
# Redis instances left open on the internet are accessed and exploited.

把这一行bind 127.0.0.1 -::1注释掉

此外,若是新版本(3.2之后)的还得修改一下redis的保护模式,同在redis.conf文件下

复制代码
# By default protected mode is enabled. You should disable it only if
# you are sure you want clients from other hosts to connect to Redis
# even if no authentication is configured, nor a specific set of interfaces
# are explicitly listed using the "bind" directive.
protected-mode yes

这里把protected-mode yes改为protected-mode no即可。

测试Redis远程访问

windows下:

复制代码
Administrator@MICRO-911300019 C:UsersAdministrator
# redis-cli -h 192.168.190.5 -p 6379 -a 123456
192.168.190.5:6379> select 1
OK
192.168.190.5:6379[1]>

linux下:

复制代码
[root@localhost ~]# redis -h 192.168.190.5 -p 6379 -a 123456
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
192.168.190.5:6379> 

Warning是提醒在命令上输入密码是不安全的。

相关推荐
晓晓_za8986682 分钟前
多租户 GEO 优化系统源码架构:权限隔离与数据分离实现
java·tcp/ip·spring·缓存·微服务·架构
烬羽6 分钟前
一个博客系统,为什么要拆成 6 张表?
数据库·mysql
程序员-Benothing8 分钟前
MySQL 中的日志类型有哪些?binlog、redo log 和 undo log 的作用和区别是什么?
数据库·mysql
XuCoder12 分钟前
你写的每条 SQL 都没加过锁,可 MySQL 凭什么不怕两个事务打架?
数据库·后端
2301_8009549922 分钟前
MySQL 数据库基础:数据类型、查询与备份恢复
数据库·mysql·oracle
起名真的太难了23 分钟前
Mysql的数据类型,查询与备份操作
数据库·sql·mysql
程序猿_极客24 分钟前
【免费】分享一套优质的基于Php+Mysql的电子购物网站的设计与实现,校园小卖部系统
数据库·mysql·php·购物商城系统
fīɡЙtīиɡ ℡25 分钟前
LLM/Agent 安全实战核心要点总结
网络·数据库·安全
程序员夏洛26 分钟前
MySQL 中有哪些锁类型?
数据库·mysql
Hive_MOM27 分钟前
制造企业技术文件与图纸管理数字化(DCC):从“图纸满天飞“到版本受控
服务器·数据库·制造