redis默认情况下是没有开启密码访问功能,需要配置redis.config文件。
1、找到配置文件并且打开
~% vi /usr/local/redis-6.2.6/redis.conf
当前文件搜索/requirepass,键盘上按n一个个查看,找到 #require pass foobared,修改为requirepass 123(密码),保存退出。
2、重启redis服务器
< 127.0.0.1:6379> shutdown ~ % redis-server
这个时候你会发现密码没有效果,具体你看下redis服务器启动过程有句话:
# Warning: no config file specified, using the default config. In order to specify a config file use redis-server /path/to/redis.conf
redis服务器需要指定config文件,所以需要带配置文件启动:
~ % redis-server /usr/local/redis-6.2.6/redis.conf
3、连接
1)通过命令连接:
~ % redis-cli -h 127.0.0.1 -p 6379 127.0.0.1:6379> ping (error) NOAUTH Authentication required. 127.0.0.1:6379> auth 123 OK 127.0.0.1:6379&g