首页 > 技术文章 > Linux 安装 Redis 及踩坑

netyts 2021-08-16 16:55 原文

1、下载

[root@localhost ~]# wget https://download.redis.io/releases/redis-6.2.5.tar.gz  #wget方法下载(若没有wget,可先用yum下载wget)
--2021-08-16 16:31:49--  https://download.redis.io/releases/redis-6.2.5.tar.gz
正在解析主机 download.redis.io (download.redis.io)... 45.60.125.1
正在连接 download.redis.io (download.redis.io)|45.60.125.1|:443... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:2465302 (2.4M) [application/octet-stream]
正在保存至: “redis-6.2.5.tar.gz”

100%[======================================================================================================================================>] 2,465,302   3.42MB/s 用时 0.7s   

2021-08-16 16:31:49 (3.42 MB/s) - 已保存 “redis-6.2.5.tar.gz” [2465302/2465302])

 

2、解压

[root@localhost opt]# ll
总用量 2408
-rw-r--r--. 1 root root 2465302 7月  22 02:51 redis-6.2.5.tar.gz
[root@localhost opt]# tar -zxvf redis-6.2.5.tar.gz  #解压命令

 

3、编译  进入解药后的 redis 中执行 make

[root@localhost opt]# ll
总用量 2412
drwxrwxr-x. 7 root root    4096 7月  22 02:06 redis-6.2.5
-rw-r--r--. 1 root root 2465302 7月  22 02:51 redis-6.2.5.tar.gz
[root@localhost opt]# cd redis-6.2.5
[root@localhost redis-6.2.5]# make

如果编辑报错(因为Redis是C实现的,需要gcc来进行编译,所以原因是系统未安装gcc)

MAKE hiredis
cd hiredis && make static 
make[3]: 进入目录“/opt/redis-6.2.5/deps/hiredis”
cc -std=c99 -pedantic -c -O3 -fPIC   -Wall -W -Wstrict-prototypes -Wwrite-strings -Wno-missing-field-initializers -g -ggdb alloc.c
make[3]: cc:命令未找到
make[3]: *** [alloc.o] 错误 127
make[3]: 离开目录“/opt/redis-6.2.5/deps/hiredis”
make[2]: *** [hiredis] 错误 2
make[2]: 离开目录“/opt/redis-6.2.5/deps”
make[1]: [persist-settings] 错误 2 (忽略)
    CC adlist.o
/bin/sh: cc: 未找到命令
make[1]: *** [adlist.o] 错误 127
make[1]: 离开目录“/opt/redis-6.2.5/src”
make: *** [all] 错误 2

执行如下语句,然后重新解压再编译

[root@localhost redis-6.2.5]# yum install -y gcc g++ gcc-c++ make

 

4、编译没问题后,进入 src 目录

[root@localhost redis-6.2.5]# ls
00-RELEASENOTES  CONDUCT       COPYING  INSTALL   MANIFESTO  redis.conf  runtest-cluster    runtest-sentinel  src    TLS.md
BUGS             CONTRIBUTING  deps     Makefile  README.md  runtest     runtest-moduleapi  sentinel.conf     tests  utils
[root@localhost redis-6.2.5]# cd src
[root@localhost src]# sudo make install  #执行命令
    CC Makefile.dep

Hint: It's a good idea to run 'make test' ;)

    INSTALL redis-server
    INSTALL redis-benchmark
    INSTALL redis-cli

 

5、至此,Redis已经安装完成,最后整理一下文件

在 Redis 目录下创建 etc 和 bin 两个文件夹,将 redis.conf 移入新建的 etc 目录下

[root@localhost src]# cd ..
[root@localhost redis-6.2.5]# mkdir etc
[root@localhost redis-6.2.5]# mkdir bin
[root@localhost src]# mv redis.conf /opt/redis-6.2.5/etc/  #文件复制

将 src 下部分文件(如下)移入新建的 bin 目录下

[root@localhost redis-6.2.5]# cd src
[root@localhost src]# mv mkreleasehdr.sh redis-benchmark redis-check-aof redis-check-rdb redis-cli redis-server /opt/redis-6.2.5/bin/  #文件复制

 

6、启动服务

[root@localhost redis-6.2.5]# cd bin
[root@localhost bin]# redis-server 
6313:C 16 Aug 2021 16:50:31.914 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
6313:C 16 Aug 2021 16:50:31.914 # Redis version=6.2.5, bits=64, commit=00000000, modified=0, pid=6313, just started
6313:C 16 Aug 2021 16:50:31.914 # Warning: no config file specified, using the default config. In order to specify a config file use redis-server /path/to/redis.conf
6313:M 16 Aug 2021 16:50:31.915 * Increased maximum number of open files to 10032 (it was originally set to 1024).
6313:M 16 Aug 2021 16:50:31.915 * monotonic clock: POSIX clock_gettime
                _._                                                  
           _.-``__ ''-._                                             
      _.-``    `.  `_.  ''-._           Redis 6.2.5 (00000000/0) 64 bit
  .-`` .-```.  ```\/    _.,_ ''-._                                  
 (    '      ,       .-`  | `,    )     Running in standalone mode
 |`-._`-...-` __...-.``-._|'` _.-'|     Port: 6379
 |    `-._   `._    /     _.-'    |     PID: 6313
  `-._    `-._  `-./  _.-'    _.-'                                   
 |`-._`-._    `-.__.-'    _.-'_.-'|                                  
 |    `-._`-._        _.-'_.-'    |           https://redis.io       
  `-._    `-._`-.__.-'_.-'    _.-'                                   
 |`-._`-._    `-.__.-'    _.-'_.-'|                                  
 |    `-._`-._        _.-'_.-'    |                                  
  `-._    `-._`-.__.-'_.-'    _.-'                                   
      `-._    `-.__.-'    _.-'                                       
          `-._        _.-'                                           
              `-.__.-'                                               

6313:M 16 Aug 2021 16:50:31.916 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
6313:M 16 Aug 2021 16:50:31.916 # Server initialized

 

推荐阅读