一、安装Redis

1、安装C语言的编译环境

1 yum install gcc

 

2、下载redis

右键复制下载链接并在终端执行下载命令

Redis官网: https://redis.io/

基于Cenos7安装使用Redis_redis

 

 1 [root@host-yht yht]# wget https://download.redis.io/releases/redis-6.2.6.tar.gz
 2 --2021-10-11 10:43:57--  https://download.redis.io/releases/redis-6.2.6.tar.gz
 3 正在解析主机 download.redis.io (download.redis.io)... 45.60.125.1
 4 正在连接 download.redis.io (download.redis.io)|45.60.125.1|:443... 已连接。
 5 已发出 HTTP 请求,正在等待回应... 200 OK
 6 长度:2476542 (2.4M) [application/octet-stream]
 7 正在保存至: “redis-6.2.6.tar.gz”
 8 
 9 100%[===================================================================================================>] 2,476,542    493KB/s 用时 5.3s   
10 
11 2021-10-11 10:44:05 (454 KB/s) - 已保存 “redis-6.2.6.tar.gz” [2476542/2476542])

注意:你要清楚你自己将这个文件下载到哪儿的

 

3、解压

 1 [root@host-yht yht]# tar -zxvf redis-6.2.6.tar.gz
 2 redis-6.2.6/
 3 redis-6.2.6/.github/
 4 redis-6.2.6/.github/ISSUE_TEMPLATE/
 5 以下省略 

 

4、进入redis安装目录使用make命令进行编译

 1 [root@host-yht yht]# cd redis-6.2.6
 2 [root@host-yht redis-6.2.6]# make
 3 //太多省略
 4 .
 5 .
 6 CC redis-cli.o
 7 CC cli_common.o
 8 LINK redis-cli
 9 CC redis-benchmark.o
10 LINK redis-benchmark
11 INSTALL redis-check-rdb
12 INSTALL redis-check-aof
13 
14 Hint: It's a good idea to run 'make test' ;)
15 
16 make[1]: 离开目录“/home/yht/redis-6.2.6/src”

//编译完成

 

5、进行安装

 1 [root@host-yht redis-6.2.6]# make install
 2 cd src && make install
 3 make[1]: 进入目录“/home/yht/redis-6.2.6/src”
 4     CC Makefile.dep
 5 make[1]: 离开目录“/home/yht/redis-6.2.6/src”
 6 make[1]: 进入目录“/home/yht/redis-6.2.6/src”
 7 
 8 Hint: It's a good idea to run 'make test' ;)
 9 
10     INSTALL redis-server
11     INSTALL redis-benchmark
12     INSTALL redis-cli
13 make[1]: 离开目录“/home/yht/redis-6.2.6/src”

//安装成功
1 //进入该目录/usr/local/bin
2 [root@host-yht redis-6.2.6]# cd /usr/local/bin
3 [root@host-yht bin]# ls
4 redis-benchmark  redis-check-aof  redis-check-rdb  redis-cli  redis-sentinel  redis-server

 

默认安装目录:  /usr/local/bin

redis-benchmark: 性能测试工具

redis-check-aof: 修复有问题的AOF文件
redis-check-dump:修复有问题的dump.rdb文件
redis-sentinel: Redis集群使用
redis-cli: 客户端,操作入口
redis-server: Redis服务器启动命令

 

 

二、Redis的使用

1、启动

前台启动(不推荐):

 

1 redis-server

 

 

 

    退出:ctrl+c

后台启动(推荐):

  • 先进性相关配置,进入你的redis目录找到redis.conf文件:

 

1 [root@host-yht /]# cd /home/yht/redis-6.2.6
2 [root@host-yht redis-6.2.6]# ls
3 00-RELEASENOTES  CONDUCT       COPYING  INSTALL   MANIFESTO  redis.conf  runtest-cluster    runtest-sentinel  src    TLS.md
4 BUGS             CONTRIBUTING  deps     Makefile  README.md  runtest     runtest-moduleapi  sentinel.conf     tests  utils

 

 

  • 将redis.con文件复制到另一个目录下(随便):
1 [root@host-yht redis-6.2.6]# cp redis.conf /home/yht/redis.conf
//注意你是复制到的那个目录

 

  • 对该复制后的配置经行修改:将“daemonize no”改为“daemonize no”

你可以在vim底部命令模式按  "/  + daemo"   进行搜索

基于Cenos7安装使用Redis_ide_02

 

  •  后台启动: redis-server [你修改的那个配置文件的目录]/redis.conf
1 [root@host-yht yht]# redis-server /home/yht/redis.conf

 

  • 查看redis的后台进程,是否启动成功
1 [root@host-yht yht]# ps -ef | grep redis
2 root       3316      1  0 10:05 ?        00:00:00 redis-server 127.0.0.1:6379
3 root       3373   2826  0 10:08 pts/0    00:00:00 grep --color=auto redis

 

 

2、进入redis终端

1 [root@host-yht yht]# redis-cli
2 127.0.0.1:6379> 

 

测试验证:

1 127.0.0.1:6379> ping
2 PONG  //连接正常

 

 

3、关闭redis

  • 可以进入redis终端直接输入shutdown关闭:
1 127.0.0.1:6379> shutdown
2 not connected> 

 

  • 也可以在centos终端使用使用redis.cli shutdown
1 [root@host-yht yht]# redis-cli shutdown

 

  • 也可以直接杀掉redis的进程:
1 [root@host-yht yht]# ps -ef | grep redis
2 root       3558      1  0 10:24 ?        00:00:00 redis-server 127.0.0.1:6379
3 root       3564   2826  0 10:24 pts/0    00:00:00 grep --color=auto redis
4 [root@host-yht yht]# kill -9 3558
5 [root@host-yht yht]# ps -ef | grep redis
6 root       3583   2826  0 10:26 pts/0    00:00:00 grep --color=auto redis

 

 

暂时学习到这儿,持续更新中、、、、