Redis-Linux下安装

本文详细记录了在CentOS7环境下安装Redis的过程,包括遇到的常见错误及解决方案。首先,由于新Linux环境缺少C编译器,需要安装gcc。接着,在编译Redis时,由于jemalloc头文件缺失,需要将MALLOC配置更改为libc。随后,运行Redis测试时,发现需要至少tcl 8.5版本,因此需更新tcl。完成这些步骤后,执行`make test`确保一切正常,最后启动Redis并检查进程及端口占用情况。

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

下载并安装

环境:centos7 64位,新安装的虚拟机

$ wget http://download.redis.io/releases/redis-3.2.1.tar.gz
$ tar xzf redis-3.2.1.gz
$ cd redis-3.2.1

编译

$ make

错误1: /bin/sh: cc: command not found

[redis@localhost redis-3.2.1]$ make
cd src && make all
make[1]: Entering directory `/home/redis/Desktop/redis-3.2.1/src'
    CC adlist.o
/bin/sh: cc: command not found
make[1]: *** [adlist.o] Error 127
make[1]: Leaving directory `/home/redis/Desktop/redis-3.2.1/src'
make: *** [all] Error 2

==这是一台新部署的linux环境,缺少C语言环境,所以需要安装gcc==

[redis@localhost redis-3.2.1]$ sudo yum install gcc


# 一直Y,出现Complete!表示安装成功
Dependency Updated:
  glibc.x86_64 0:2.17-106.el7_2.8               glibc-common.x86_64 0:2.17-106.el7_2.8              

Complete!

继续编译:

[redis@localhost redis-3.2.1]$ make
cd src && make all
make[1]: Entering directory `/home/redis/Desktop/redis-3.2.1/src'
    CC adlist.o
In file included from adlist.c:34:0:
zmalloc.h:50:31: fatal error: jemalloc/jemalloc.h: No such file or directory
 #include <jemalloc/jemalloc.h>
                               ^
compilation terminated.
make[1]: *** [adlist.o] Error 1
make[1]: Leaving directory `/home/redis/Desktop/redis-3.2.1/src'
make: *** [all] Error 2

错误2:error: jemalloc/jemalloc.h: No such file or directory

redis 环境变量 ==MALLOC== 默认的是 MALLOC=jemalloc, 我们的虚拟机中可能没有 jemalloc所以需要改为 libc

  • 解决:修改分配器,使用下面的命令
make MALLOC=libc

然后,根据提示执行make或make test,发现又出问题了,

错误3: You need tcl 8.5 or newer in order to run the Redis test

可能是版本太高导致的吧,没办法,强迫症,有新的稳定版的的出现,肯定会去用新的。

[redis@localhost redis-3.2.1]$ make test  ,
cd src && make test
make[1]: Entering directory `/home/redis/Desktop/redis-3.2.1/src'
You need tcl 8.5 or newer in order to run the Redis test
make[1]: *** [test] Error 1
make[1]: Leaving directory `/home/redis/Desktop/redis-3.2.1/src'
make: *** [test] Error 2
  • 解决:升级 tcl 喽

按顺序,分别执行以下命令

wget http://downloads.sourceforge.net/tcl/tcl8.6.1-src.tar.gz  
sudo tar xzvf tcl8.6.1-src.tar.gz  -C /usr/local/  
cd  /usr/local/tcl8.6.1/unix/  
sudo ./configure  
sudo make  
sudo make install   

make test

如果,不想在执行make操作时,出现这么多问题,先执行make test检测当前环境,提前解决这些问题也不错。

# make test
...# 经过漫长的检测,出现如下文字,则表示环境没问题,可以安装了
\o/ All tests passed without errors!
Cleanup: may take some time... OK
make[1]: Leaving directory `/home/redis/Desktop/redis-3.2.1/src'

如果make test正常,但是还会出现一些奇葩问题,可以考虑重新解压,重新安装

执行完make命令后,进入 src目录执行启动命令

$ ./redis-server   # 启动服务

再打开一个窗口,执行

$ ./redis-cli   #启动客户端

查看进程

  • 检测redis进程
ps -ef|grep redis
  • 检测端口
netstat -lntp | grep 6379
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值