重庆小潘seo博客

当前位置:首页 > 重庆网络营销 > 小潘杂谈 >

小潘杂谈

Linux下设置redis访问密码的方法

时间:2020-09-24 02:00:08 作者:重庆seo小潘 来源:
今天服务器安装了redis,为了安全设置一下访问redis-server的密码。 推荐:《redis教程》 一、查找redis.conf文件 我们服务器已经安装了redis,现在通过命令查看下redis的进程:[root@lnp ~]# ps -aux|grep redisroot73740.00.0 1453127524 ?Ssl16:370:00 red

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

推荐:《redis教程》

一、查找redis.conf文件

我们服务器已经安装了redis,现在通过命令查看下redis的进程:[root@lnp ~]# ps -aux|grep redisroot73740.00.0 1453127524 ?Ssl16:370:00 redis-server 192.168.17.105:6379root106920.00.0 112724984 pts/7S+16:540:00 grep --color=auto redis可以看到我们的redis-server的服务地址为192.168.17.105,端口为6379,对外访问的时候需要指定对应的IP和端口:redis-cli -h 192.168.17.105 -p 6379查找redis安装目录> whereis redisredis: /usr/local/redis我们可以看到redis在该目录下安装,然后找到配置文件redis.conf> find /usr/local/redis/ -name redis.conf/usr/local/redis/etc/redis.conf修改配置文件:vim redis.conf改该配置文件即可:# requirepass foobaredrequirepass 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-cliCould not connect to Redis at 127.0.0.1:6379: Connection refusedCould not connect to Redis at 127.0.0.1:6379: Connection refusednot connected> exit[root@lnp etc]# redis-cli -h 192.168.17.105 -p 6379192.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 123Warning: 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以上就是Linux下设置redis访问密码的方法的详细内容,更多请关注小潘博客其它相关文章!