linux 环境下redis安装 (一)

4 篇文章 0 订阅

1.官网下载redis

[root@localhost ~]# wget http://download.redis.io/releases/redis-5.0.5.tar.gz

2.解压文件

[root@localhost ~]# tar -zxvf redis-5.0.5.tar.gz

3.进入解压目录,编译

[root@localhost ~]# cd redis-5.0.5
[root@localhost redis-5.0.5]# make

4.启动redis-server 服务 【后台守护进行执行】

[root@localhost redis-5.0.5]# pwd
/root/redis-5.0.5
[root@localhost redis-5.0.5]# cd src/
[root@localhost src]# ./redis-server &

5.进入redis客户端

[root@localhost src]# pwd
/root/redis-5.0.5/src
[root@localhost src]# ./redis-cli 
127.0.0.1:6379> keys *
(empty list or set)

6.设置redis密码

1.redis命令方式设置(该方法在重启Redis后密码将失效)

[root@localhost src]# ./redis-cli 
127.0.0.1:6379> config set requirepass 123456ok
OK
127.0.0.1:6379> keys *
(error) NOAUTH Authentication required.
127.0.0.1:6379> 
#从上面可以看到密码设置成功,同时一旦密码设置成功,刚刚建立的连接将不能进行任何权限操作

使用-a 密码 登录redis

[root@localhost src]# ./redis-cli -h 127.0.0.1 -p 6379 -a 123456ok
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
127.0.0.1:6379> keys *
(empty list or set)

2.通过Redis配置文件redis.conf进行设置密码(注意:该方法设置密码后需要重启Redis才生效):

[root@localhost src]# find / -name redis.conf
/root/redis-5.0.5/redis.conf
[root@localhost src]# vim /root/redis-5.0.5/redis.conf 

在这里插入图片描述

重启redis:

[root@localhost src]# ps -ef|grep redis
root       8208   2629  0 02:21 pts/1    00:00:00 ./redis-server *:6379
root       8373   2629  0 02:25 pts/1    00:00:00 grep --color=auto redis
[root@localhost src]# kill -9 8208
#使用配置文件redis.conf【使用密码的时候需要添加配置文件路径、或修改配置的时候都需要加载配置文件】
[root@localhost src]# ./redis-server /root/redis-5.0.5/redis.conf 

重新连接redis客户端

#没有输入密码
[root@localhost src]# ./redis-cli -h 127.0.0.1 -p 6379
127.0.0.1:6379> keys *
(error) NOAUTH Authentication required.


#输入密码
[root@localhost src]# ./redis-cli -h 127.0.0.1 -p 6379 -a 123456ok
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
127.0.0.1:6379> keys *
1) "name"
2) "name1"

7.外部需要连接redis的时候

注意需要修改监听的地址(redis.conf配置文件):
在这里插入图片描述
8.现在想要将日志打印到文件中可以修改 (redis.conf配置文件)
在这里插入图片描述

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值