今天服务器安装了redis,为了安全设置一下访问redis-server的密码。
推荐:《redis教程》
一、查找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
修改配置文件:
一个经过完善设计的经典网上购物系统,适用于各种服务器环境的高效网上购物系统解决方案,shopxp购物系统Html版是我们首次推出的免费购物系统源码,完整可用。我们的系统是免费的不需要购买,该系统经过全面测试完整可用,如果碰到问题,先检查一下本地的配置或到官方网站提交问题求助。 网站管理地址:http://你的网址/admin/login.asp 用户名:admin 密 码:admin 提示:如果您
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









