Linux下如何设置redis访问密码(代码)


本文摘自PHP中文网,作者不言,侵删。

本篇文章给大家带来的内容是关于Linux下如何设置redis访问密码(代码),有一定的参考价值,有需要的朋友可以参考一下,希望对你有所帮助。

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

一、查找redis.conf文件

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

1

2

3

[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和端口:

1

redis-cli -h 192.168.17.105 -p 6379

查找redis安装目录

1

2

> whereis redis

redis: /usr/local/redis

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

1

2

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

/usr/local/redis/etc/redis.conf

修改配置文件:

1

vim redis.conf

改该配置文件即可:

1

2

# requirepass foobared

requirepass 123   指定密码123

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

1

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

二、连接测试

通过密码-a访问:

1

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

运行结果:

1

2

3

4

5

6

7

8

9

10

11

12

13

14

[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

相关推荐:

win7版下Redis如何设置访问密码的详解(图)

redis访问权限控制,密码设置

以上就是Linux下如何设置redis访问密码(代码)的详细内容,更多文章请关注木庄网络博客

相关阅读 >>

怎么下载linux操作系统

linux查看历史命令

linux文件无法删除

linux .权限不够怎么办

linux中某个目录进不去导致卡死问题

linux系统格式化分区用哪个命令

如何使用linux自定义镜像创建实例

linux实现显示器不休眠

linux运行快吗

2021年最好用的linux服务器系统

更多相关阅读请进入《Redis》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...