Centos安装配置Redis6.x

安装依赖

//检查是否有依赖
gcc -v
//没有则安装
yum install -y gcc

下载编译

//创建目录,tools目录已经事先创建
mkdir /tools/redis
//进入目录
cd /tools/redis
//下载redis
wget https://download.redis.io/releases/redis-6.2.9.tar.gz
//解压缩
tar -zxvf redis-6.2.9.tar.gz
//重命名,非必须
mv redis-6.2.9 redis6
//编译
cd redis6
make install

编辑配置文件

vim redis.conf

redis.conf中需要变更的部分(比较简单的配置,其余配置可自行搜索)

#开启守护线程
daemonize yes
#开启远程连接
bind 0.0.0.0
protected-mode no
#设置redis密码
requirepass pwd

启动测试

#启动
src/redis-server redis.conf
#连接测试
[root@hecs-166225 redis6]# src/redis-cli
127.0.0.1:6379> keys*
(error) ERR unknown command `keys*`, with args beginning with:
127.0.0.1:6379> exit
[root@hecs-166225 redis6]# src/redis-cli
127.0.0.1:6379> keys *
(error) NOAUTH Authentication required.
127.0.0.1:6379> auth pwd
OK
127.0.0.1:6379> keys *
(empty array)

添加用户名验证

redis6新增了用户名密码验证的方式,我们可以先看下默认的用户列表

127.0.0.1:6379> acl list
1) "user default on #b2bc59a37aeddac473f82919c30af0a04c7756ca7d8e5b63df4f78602be5d735 ~* &* +@all"

在redis.conf中禁用default用户,新建新用户

#禁用default用户
user default off
#定义一个新用户root,添加到all权限组,从dangerous权限组移除,有所有键的操作权限,密码为pwd
user root on +@all -@dangerous allkeys >pwd

重启redis

[root@hecs-166225 redis6]# ps -aux|grep redis
root     27346  0.1  0.0 162524  2888 ?        Ssl  11:01   0:01 src/redis-server 0.0.0.0:6379
root     31089  0.0  0.0 112812   976 pts/0    S+   11:18   0:00 grep --color=auto redis
[root@hecs-166225 redis6]# kill 27346
[root@hecs-166225 redis6]# src/redis-server redis.conf
[root@hecs-166225 redis6]# ps -aux|grep redis
root     31361  0.0  0.0 162524  2712 ?        Ssl  11:19   0:00 src/redis-server 0.0.0.0:6379
root     31391  0.0  0.0 112812   980 pts/0    S+   11:19   0:00 grep --color=auto redis

测试验证

[root@hecs-166225 redis6]# src/redis-cli
127.0.0.1:6379> auth pwd
(error) WRONGPASS invalid username-password pair or user is disabled.
127.0.0.1:6379> auth root pwd
OK

参考资料

[1].Redis版本

  • 8
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值