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
您可能感兴趣的文章
- 12-22使用mysql记录从url返回的http GET请求数据操作
- 12-22详解sql中exists和in的语法与区别
- 12-22hive从mysql导入数据量变多的解决方案
- 12-22如何为PostgreSQL的表自动添加分区
- 12-22postgresql 实现得到时间对应周的周一案例
- 12-22sqoop export导出 map100% reduce0% 卡住的多种原因及解决
- 12-22mysql查询条件not in 和 in的区别及原因说明
- 12-22解决mysql使用not in 包含null值的问题
- 12-22解决从集合运算到mysql的not like找不出NULL的问题
- 12-22postgresql 实现多表关联删除


阅读排行
推荐教程
- 12-11mysql代码执行结构实例分析【顺序、分支、循环结构】
- 12-08添加mysql的用户名和密码是什么语句?
- 12-20PhpMyAdmin出现错误数据无法导出怎么办?
- 12-19Redis中实现查找某个值的范围
- 12-15浅析mysql迁移到clickhouse的5种方法
- 12-15CentOS7 64位下MySQL5.7安装与配置教程
- 12-14Mysql大型SQL文件快速恢复方案分享
- 12-14mysql 5.7.27 安装配置方法图文教程
- 12-13MySQL给新建用户并赋予权限最简单的方法
- 12-13关于MySQL索引的深入解析





