ICode9

精准搜索请尝试: 精确搜索
首页 > 数据库> 文章详细

redis远程连接

2020-02-20 15:04:51  阅读:210  来源: 互联网

标签:redis 0.1 bind Redis 连接 密码 127.0 远程


redis 远程连接方法

解决方法

1、修改redis服务器的配置文件

vi redis.conf

注释以下绑定的主机地址

# bind 127.0.0.1

vim  redis.conf

bind  0.0.0.0

protected-mode   no

2、修改redis服务器的参数配置

修改redis的守护进程为no,不启用

127.0.0.1:6379> config  set   daemonize  "no"

OK

修改redis的保护模式为no,不启用

127.0.0.1:6379> config   set   protected-mode"no"

OK

或者

config set requirepass 123 ->123是密码

注意:开启 6379端口

 

3、远程连接

$ redis-cli -h 138.138.138.138  -p  6379 

redis>ping

PONG

-------------------------------------------------------------------------------------------------------------------

如何让Redis允许远程连接,并设置密码

最近网站数据量过大,需要在数据库上层增加一个缓存层,所以采用了Redis作为数据库。但是Redis默认是不允许远程连接的,主要还是考虑到了安全问题。

但是如果需要远程连接,那该如何操作呢:

/etc/redis/redis.conf文件里面修改如下配置文件,


 

################################## NETWORK #####################################

# By default, if no "bind" configuration directive is specified, Redis listens

# for connections from all the network interfaces available on the server.

# It is possible to listen to just one or multiple selected 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 ::1

#

# ~~~ 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 into

# the IPv4 lookback interface address (this means Redis will be able to

# accept connections only from clients running into the same computer it

# is running).

#

# IF YOU ARE SURE YOU WANT YOUR INSTANCE TO LISTEN TO ALL THE INTERFACES

# JUST COMMENT THE FOLLOWING LINE.

# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

bind 127.0.0.1 ::1

bind 127.0.0.1 ::1注释掉:


 

# bind 127.0.0.1 ::1

这样就可以远程连接了。

 

允许远程连接就带来了一个很大的问题,可以用过互联网破解Redis密码,所以需要设置Redis的密码。

redis的查询速度是非常快的,外部用户一秒内可以尝试多大150K个密码;所以密码要尽量长(对于DBA 没有必要必须记住密码);

所以需要设置一个很长的密码,防止破解。

找到刚才的配置文件,有如下内容:


 

################################## SECURITY ###################################

# Require clients to issue AUTH 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 xxxxxxxxxxxx

修改requirepass 后面就是密码,密码设置的尽量长。

 

之后重启Redis,在真正的项目上,需要注意数据的持久化,否则重启数据会丢失。

如果是用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

2、Redis启动:


 

redis-server

若纷飞 发布了9 篇原创文章 · 获赞 18 · 访问量 6554 私信 关注

标签:redis,0.1,bind,Redis,连接,密码,127.0,远程
来源: https://blog.csdn.net/zlc1990628/article/details/104410451

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有