Redis3.2.11安装

1.下载redis3的稳定版本:

下载地址:http://download.redis.io/releases/

2.上传redis-3.2.11.tar.gz到虚拟机

3.解压redis源码包:

tar -zxvf redis-3.2.11.tar.gz -C /解压目录/
比如:tar -zxvf redis-3.2.11.tar.gz -C /home/hadoop/app/

4.进入到源码包中,编译并安装redis:

cd /home/hadoop/app/redis-3.2.11/
make && make install

注意:
这里直接编译可能会报错,缺少依赖包。那是因为如果虚拟机是最小化安装的话,会缺少gcc依赖(c语言的编译器(redis是用C语言编写的))

解决办法:
配置本地YUM源并安装redis依赖的rpm包:

yum -y install gcc

然后继续执行make && make install编译安装可能还会报错,这个错误的原因是没有安装jemalloc内存分配器,可以安装jemalloc或直接输入:

 sudo make MALLOC=libc && make instal

5.进入到安装目录:

cd /home/hadoop/app/redis-3.2.11

目录结构如下:
在这里插入图片描述

6.修改配置文件redis.conf

sudo vim redis.conf

只需要修改四个选项就可以了:

daemonize yes #redis后台运行
#cluster-enabled yes #默认是没有开启集群模式,如果要开启集群模式,将注释去掉
protected-mode no #关闭保护模式,使其他机器也可以访问本机redis
appendonly yes #开启aof日志,它会每次写操作都记录一条日志
bind 192.168.1.207(本机IP)

然后还需要修改日志文件的目录:
(1).新建一个文件redis_log.log,并修改他的权限:

sudo touch /home/hadoop/app/redis-3.2.11/redis_log.log
sudo chmod 777 /home/hadoop/app/redis-3.2.11/redis_log.log

(2).新建一个目录redis_dbfile,并修改他的权限:

sudo mkdir /home/hadoop/app/redis-3.2.11/redis_dbfile
sudo chmod 777 /home/hadoop/app/redis-3.2.11/redis_dbfile

然后修改redis.conf文件:
1.将logfile ""修改为logfile /home/hadoop/app/redis-3.2.11/redis_log.log
在这里插入图片描述

2.将dir /.修改为dir /home/hadoop/app/redis-3.2.11/redis_dbfile/
在这里插入图片描述

修改完成后就可以了。

7.启动redis

cd /home/hadoop/app/redis-3.2.11/

./src/redis-server redis.conf

8.查看redis进程状态

ps -ef | grep redis

在这里插入图片描述
如图所示,表示已启动。

9.使用命令行客户端连接redis

./src/redsi-cli -h 连接IP(刚刚修改redis.conf文件中bind后面的IP)

或者:

./src/redsi-cli -p 6379

在这里插入图片描述

10.设置密码

连接上redis后,执行:

config set requirepass 123(密码)

修改完密码之后,再次连接redis时要输入密码才可以进行操作。

>AUTH 密码

11.关闭redis

./src/redis-cli shutdown

在执行该命令时可能会出现如下错误:
DENIED Redis is running in protected mode because protected mode is enabled, no bind address was specified, no authentication password is requested to clients. In this mode connections are only accepted from the loopback interface. If you want to connect from external computers to Redis you may adopt one of the following solutions: 1) Just disable protected mode sending the command ‘CONFIG SET protected-mode no’ from the loopback interface by connecting to Redis from the same host the server is running, however MAKE SURE Redis is not publicly accessible from internet if you do so. Use CONFIG REWRITE to make this change permanent. 2) Alternatively you can just disable the protected mode by editing the Redis configuration file, and setting the protected mode option to ‘no’, and then restarting the server. 3) If you started the server manually just for testing, restart it with the ‘–protected-mode no’ option. 4) Setup a bind address or an authentication password. NOTE: You only need to do one of the above things in order for the server to start accepting connections from the outside.

此时,一定要查看redis.conf文件中的protected-mode是否为no,还要查看刚才创建的redis_log.log文件和redsi_dbfile目录的权限是否为777.

12.redis的一些简单操作

1.查看key:

 >keys *

2.添加数据

>set key value

3.获取数据

>get key

3.value的加减操作

一次加1:
>INCR key

一次多加:

>INCRBY key 100

减得话和加一样,命令是DECRBY

附加

如果在maven中使用redis,要添加redis的Java依赖:

<dependency>
    <groupId>redis.clients</groupId>
    <artifactId>jedis</artifactId>
    <version>2.9.0</version>
  </dependency>

jedis是用来连接redis的jar包,在Github上都可以找到,不再详细阐述。

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值