通常来说,生产环境下的Redis服务器只设置为仅本机访问(Redis默认也只允许本机访问)。有时候我们也许需要使Redi能被远程访问。此文介绍配置Redis允许远程访问。

配置

修改Redis配置文件/etc/redis/redis.conf,找到bind那行配置:

vim /etc/redis/redis.conf

去掉#注释并改为:

bind 0.0.0.0

在redis3.2之后,redis增加了protected-mode,在这个模式下,即使注释掉了bind 127.0.0.1,再访问redisd时候还是报错,如下

(error) 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.

修改办法:protected-mode no

指定配置文件然后重启Redis服务即可:

sudo redis-server /etc/redis/redis.conf

重启 redis 服务

sudo service redis-server restart

关于bind配置的含义,配置文件里的注释是这样说的:

# By default Redis listens for connections from all the network interfaces
# available on the server. It is possible to listen to just one or multiple
# interfaces using the "bind" configuration directive, followed by one or
# more IP addresses.
#
# Examples:
#
# bind 192.168.1.100 10.0.0.1
# bind 127.0.0.1

设置永久密码

Redis的安装目录中找到Redis的配置文件redis.conf(或redis.windows.conf),打开配置文件找到SECURITY部分,可以发现如下代码:

# Require clients to issue AUTH <PASSWORD> before processing any other
# commands.  This might be useful in environments in which you do not trust
# others with access to the host running redis-server.
#
# This should stay commented out for backward compatibility and because most
# people do not need auth (e.g. they run their own servers).
#
# Warning: since Redis is pretty fast an outside user can try up to
# 150k passwords per second against a good box. This means that you should
# use a very strong password otherwise it will be very easy to break.
#
# requirepass foobared

添加_requirepass yourpassword_(此处注意,行前不能有空格),保存之后,重启Redis服务。

远程连接

配置好Redis服务并重启服务后。就可以使用客户端远程连接Redis服务了。命令格式如下:

$ redis-cli -h {redis_host} -p {redis_port}

其中{redis_host}就是远程的Redis服务所在服务器地址,{redis_port}就是Redis服务端口(Redis默认端口是6379)。例如:

$ redis-cli -h 120.120.10.10 -p 6379
redis>ping
PONG[root@43-c58542295-0048 ~]# redis-cli -h 127.0.0.1 -p 6379 -a foobared
127.0.0.1:6379>

linux redis 远程访问相关推荐

  1. linux redis 启动警告解决方法

    如果启动前不对linux内核做任何更改,那么redis启动会报出警告,共三个:如下图所示 第一个警告:The TCP backlog setting of 511 cannot be enforced ...

  2. Linux Redis 重启数据丢失解决方案,Linux重启后Redis数据丢失解决方

    Linux Redis 重启数据丢失解决方案,Linux重启后Redis数据丢失解决方案 >>>>>>>>>>>>>> ...

  3. linux redis release.c:37:10: fatal error: release.h: No such file or directory

    ​​​​​​(1条消息) redis源码安装出现fatal error: jemalloc/jemalloc.h: No such file or directory_feinifi的博客-CSDN博 ...

  4. linux redis安装

    linux redis安装 1. https://redis.io/下载稳定版本安装.并解压 2.make 3. make PREFIX=/usr/local/redis install 4.进入/u ...

  5. linux redis-4.0,Linux Redis 4.0.2 安装部署

    Linux Redis 4.0.2 安装部署 01 安装GCC yum -y install gcc gcc-c++ libstdc++-devel tcl -y 02 下载安装包 cd /expor ...

  6. Linux Redis自动启动,Redis开机启动,Linux Redis设置开机启动

    Linux Redis自动启动,Redis开机启动,Linux Redis设置开机启动 >>>>>>>>>>>>>> ...

  7. linux安装redis清除错误,关于linux redis安装及安装遇到的问题

    redis官方传送门 Linux安装Redis服务步骤: 获取资源指定安装目录 [[email protected] mnt]# mkdir reids [[email protected] redi ...

  8. linux redis密码修改,Linux redis 安装并且修改密码

    linux redis 安装 1.检查是否有redis yum 源 yum install redis 2.下载fedora的epel仓库 yum install epel-release 3.安装r ...

  9. linux redis简单操作

    linux redis简单操作 1.centOS 系统安装redis https://blog.csdn.net/weixin_42835409/article/details/119562074 2 ...

  10. Linux redis 安装并且修改密码

    linux redis 安装 1.检查是否有redis yum 源 yum install redis 2.下载fedora的epel仓库 yum install epel-release 3.安装r ...

最新文章

  1. SQL的top 100 percent用法
  2. JVM-03内存区域与内存溢出异常(下)【OutOfMemoryError案例】
  3. GPUimage实时滤镜的实现
  4. (Excel)常用函数公式及操作技巧之九:查询和查找引用
  5. centos7 ifconfig命令找不到_centos7+mysql+gunicorn+flask项目部署
  6. php windows图片路径问题,解决PHP在Windows IIS 上传的图片无法访问的问题
  7. 设计赋能,数联杭温!2020温州“市长杯”·数字设计(杭州)专项赛开始报名啦!...
  8. mysql 同一字段分别统计,mysql查询同一个字段根据不同值分组成不同列统计
  9. python获取文件路径下的文件_python 获取文件下所有文件或目录os.walk()的实例
  10. 活动目录数据库重定向或迁移
  11. tostring会空指针吗_追了多年的开发框架,你还认识指针吗?
  12. Java 面试 ——可变参数、初始化数据块、设计秒杀系统
  13. [JSOI2010] 连通数
  14. Windows Server 2019 如何安装IIS 服务
  15. Android 项目必备(二)--> 启动页 引导页
  16. 【工具】笔记软件测评(简单)
  17. 机器人运动学---雅克比矩阵伪逆
  18. 如何用分词来简化状语从句
  19. 概率公式中的分号、逗号、竖线
  20. maxwell启停脚本

热门文章

  1. The Hacker Way
  2. Unity 鼠标点击事件穿透
  3. error Type referred to is not an annotation type:
  4. 移动端H5页面,通过点击软键盘搜索按钮实现搜索功能
  5. YNOI板刷计划记录
  6. “关灯”看这出戏,依旧是百年至美
  7. 边境的悍匪—机器学习实战:第二章 端到端的机器学习项目
  8. 陈睿竟也是个“大龄二次元宅”?还不知道的集美看过来
  9. 当360屠榜黑客奥斯卡,我们为什么要关注国家级网络安全战?
  10. QTreeView更改节点图标和大小