Redis安全配置:
/etc/redis/redis.conf
1 2 3 |
port 6379 #修改默认端口 bind 127.0.0.1 #修改绑定ip requirepass 123456 #修改redis密码,去掉默认前面的#为启用密码 |
php连接设置密码的redis方法
1 2 3 4 5 6 7 8 9 |
<?php //Connecting to Redis server on localhost $redis = new Redis(); $redis->connect('127.0.0.1', 6379); $redis->auth('123456'); echo "Connection to server sucessfully"; //check whether server is running or not echo "Server is running: " . $redis->ping(); ?> |
访问这个文件,提示如下则表示成功
1 |
Connection to server sucessfullyServer is running: +PONG |
登陆客户端验证
1 2 3 |
redis-cli -h 127.0.0.1 -p 6379 127.0.0.1:6379> auth myPassword OK |
在Redis集群中使用认证密码
如果Redis服务器,使用了集群。除了在master中配置密码外,也需要在slave中进行相应配置。
在slave的配置文件中找到如下行,去掉注释并修改与master相同的密码即可:
# masterauth master-password
更多待涛哥实践总结
转载请注明:PHP笔记 » Redis安全设置认证密码以及PHP操作