Linux安装Redis

本文介绍了在Linux环境下手动下载Redis6.2.5源码,使用wget下载,tar命令解压,通过gcc编译,解决编译错误,然后进行安装,包括设置后台运行和允许远程连接的配置步骤。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1、下载

  • 官网:Download | Redis ,将下载好的文件通过远程终端工具移到 Linux 下
  • Linux 命令 wget
[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

7、设置后台启动(建议)

Redis默认不是以守护进程的方式运行,可以通过该配置项修改,使用yes启用守护进程

进入Redis的安装目录,找到 redis.conf

[root@localhost etc]# cd /opt/redis-7.0.10/etc
[root@localhost etc]# ls
redis.conf
[root@localhost etc]# vi redis.conf

 修改:daemonize 默认是 no,改为 yes,然后保存退出

 启动

[root@localhost etc]# cd /opt/redis-7.0.10/bin/
[root@localhost bin]# ls
dump.rdb  mkreleasehdr.sh  redis-benchmark  redis-check-aof  redis-check-rdb  redis-cli  redis-server
[root@localhost bin]# ./redis-server /opt/redis-7.0.10/etc/redis.conf

关闭        kill 30895[进程号]

[root@localhost bin]# ps -aux | grep redis
root      1642  0.0  0.0 112808   976 pts/0    S+   16:46   0:00 grep --color=auto redis
root     30895  0.1  0.2 163156  8344 ?        Ssl  16:03   0:03 ./redis-server *:6379
[root@localhost bin]# kill 30895
[root@localhost bin]# ps -aux | grep redis
root      1734  0.0  0.0 112808   976 pts/0    S+   16:47   0:00 grep --color=auto redis

8、设置远程连接

将此处的bing注释掉,允许其他端口访问

 关闭保护模式,此处的yes改为no

 打开密码验证,将注释去掉

重启服务(先杀进程,再用上面提到的命令启动即可) 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值