当前位置:首页 > 服务端 > Linux下设置redis访问密码

Linux下设置redis访问密码

Linux下设置redis访问密码

服务器安装了redis,为了安全设置一下访问redis-server的密码。

一、查找redis.conf文件

我们服务器已经安装了redis,现在通过命令查看下redis的进程:

[root@lnp ~]# ps -aux|grep redis
root      7374  0.0  0.0 145312  7524 ?        Ssl  16:37   0:00 redis-server 192.168.17.105:6379
root     10692  0.0  0.0 112724   984 pts/7    S+   16:54   0:00 grep --color=auto redis

可以看到我们的redis-server的服务地址为192.168.17.105,端口为6379,对外访问的时候需要指定对应的IP和端口:

redis-cli -h 192.168.17.105 -p 6379

查找redis安装目录

> whereis redis
redis: /usr/local/redis

我们可以看到redis在该目录下安装,然后找到配置文件redis.conf

> find /usr/local/redis/ -name redis.conf
/usr/local/redis/etc/redis.conf

修改配置文件:

vim redis.conf

改该配置文件即可:

# requirepass foobared
requirepass 123   指定密码123

最后一步,重新加载配置文件即可:

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

二、连接测试

通过密码-a访问:

> redis-cli -h 192.168.17.105 -p 6379 -a 123

运行结果:

[root@lnp etc]# redis-cli
Could not connect to Redis at 127.0.0.1:6379: Connection refused
Could not connect to Redis at 127.0.0.1:6379: Connection refused
not connected> exit

[root@lnp etc]# redis-cli -h 192.168.17.105 -p 6379
192.168.17.105:6379> keys *
(error) NOAUTH Authentication required.
192.168.17.105:6379> exit
[root@lnp etc]# redis-cli -h 192.168.17.105 -p 6379 -a 123
Warning: Using a password with '-a' option on the command line interface may not be safe.
192.168.17.105:6379> keys *
(empty list or set)
192.168.17.105:6379> exit

作者:Saggitarxm
来源链接:https://blog.csdn.net/xuezhangjun0121/article/details/107956357


版权声明:
1、JavaClub(https://www.javaclub.cn)以学习交流为目的,由作者投稿、网友推荐和小编整理收藏优秀的IT技术及相关内容,包括但不限于文字、图片、音频、视频、软件、程序等,其均来自互联网,本站不享有版权,版权归原作者所有。

2、本站提供的内容仅用于个人学习、研究或欣赏,以及其他非商业性或非盈利性用途,但同时应遵守著作权法及其他相关法律的规定,不得侵犯相关权利人及本网站的合法权利。
3、本网站内容原作者如不愿意在本网站刊登内容,请及时通知本站(javaclubcn@163.com),我们将第一时间核实后及时予以删除。





本文链接:https://www.javaclub.cn/server/68434.html

分享给朋友: