您的位置:首页 > 数据库 > Redis

Redis配置文件中关于bind参数

2017-12-17 13:18 351 查看
在配置文件redis.conf中,默认的bind 接口是127.0.0.1,也就是本地回环地址。
这样的话,访问redis服务只能通过本机的客户端连接,而无法通过远程连接,
这样可以避免将redis服务暴露于危险的网络环境中,防止一些不安全的人随随便便通过远程
连接到redis服务。
如果bind选项为空的话,那会接受所有来自于可用网络接口的连接。

例子:
比如有两台redis服务器,ip分别为:192.168.1.101和192.168.1.103,如何在101上通过redis-cli访问103上的redis呢?在远程连接103之前,先讲下redis-cli的几个关键参数:

用法:redis-cli [OPTIONS] [cmd [arg [arg ...]]]

-h <主机ip>,默认是127.0.0.1
-p <端口>,默认是6379
-a <密码>,如果redis加锁,需要传递密码

--help,显示帮助信息

当在101上通过redis-cli访问103上的redis时,首先要修改103上的redis.conf文件,在bind下加一行:bind 192.168.1.101
这样103上的redis服务就可以listen来自192.168.1.101的连接。

通过对rendis-cli用法介绍,在101上连接103应该很简单:

[root@xsf001 ~]# redis-cli -h 192.168.1.103 -p 6379
redis 192.168.1.103:6379>


官方文档介绍:

Protected mode

Unfortunately many users fail to protect Redis instances from being accessed from external networks. Many instances are simply left exposed on the internet with public IPs. For this reasons since version 3.2.0, when Redis is executed with the default configuration (binding all the interfaces) and without any password in order to access it, it enters a special mode called proteced mode. In this mode Redis only replies to queries from the loopback interfaces, and reply to other clients connecting from other addresses with an error, explaining what is happening and how to configure Redis properly.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: