`

redis学习笔记-添加访问密码,设置随机启动

 
阅读更多

添加访问密码

你的redis在真实环境中不可以谁想访问就访问,所以,必须要设置密码。

设置密码的步骤如下:

<!--[if !supportLists]-->1.       <!--[endif]-->修改redis.conf文件配置

root@ubuntu:/usr/local/redis-2.4.14# vim redis.conf

# requirepass foobared去掉注释,foobared改为自己的密码,我在这里改为123456

requirepass 123456

<!--[if !supportLists]-->2.       <!--[endif]-->启动服务

root@ubuntu:/usr/local/redis-2.4.14# ./src/redis-server redis.conf

<!--[if !supportLists]-->3.       <!--[endif]-->客户端连接

naxsu@ubuntu:/usr/local/redis-2.4.14$ ./src/redis-cli

redis 127.0.0.1:6379> get a

(error) ERR operation not permitted

redis 127.0.0.1:6379>

提示没有权限

naxsu@ubuntu:/usr/local/redis-2.4.14$ ./src/redis-cli -a 123456

redis 127.0.0.1:6379> get a

"b"

到此说明设置密码有效了。

设置随机启动

在服务器上,你每次重启机器后再去启动redis的服务,这是很麻烦的,所以将Redis作为 Linux 服务随机启动是很有必要的。

修改/etc/rc.local文件

root@ubuntu:/usr/local/redis-2.4.14# vim /etc/rc.local

在最后加入下面一行代码

./usr/local/redis-2.4.14/src/redis-server /usr/local/redis-2.4.14/redis.conf

重启机器看看效果

 

根据我的测试,设置是成功的。

 

下节:redis数据类型

 

 

 

学习笔记系统文章下载地址:http://itway.iteye.com/blog/1555285

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics