Linux CentOS中Redis安装

Linux CentOS中Redis安装

Redis下载地址:Redis下载地址,下载最新发布版本。
本次演示的下载的是 2.8.17版本,下载到Linux系统中。

$ cd /usr/development/
$ wget http://download.redis.io/releases/redis-2.8.17.tar.gz
$ cd redis-2.8.17
$ make

在最后一部执行时,有的Linux系统中会发生错误,错误代码如下:

cd src && make all
make[1]: Entering directory `/usr/development/redis-2.8.17/src'
rm -rf redis-server redis-sentinel redis-cli redis-benchmark redis-check-dump redis-check-aof *.o *.gcda *.gcno *.gcov redis.info lcov-html
(cd ../deps && make distclean)
make[2]: Entering directory `/usr/development/redis-2.8.17/deps'
(cd hiredis && make clean) > /dev/null || true
(cd linenoise && make clean) > /dev/null || true
(cd lua && make clean) > /dev/null || true
(cd jemalloc && [ -f Makefile ] && make distclean) > /dev/null || true
(rm -f .make-*)
make[2]: Leaving directory `/usr/development/redis-2.8.17/deps'
(rm -f .make-*)
echo STD=-std=c99 -pedantic >> .make-settings
echo WARN=-Wall -W >> .make-settings
echo OPT=-O2 >> .make-settings
echo MALLOC=jemalloc >> .make-settings
echo CFLAGS= >> .make-settings
echo LDFLAGS= >> .make-settings
echo REDIS_CFLAGS= >> .make-settings
echo REDIS_LDFLAGS= >> .make-settings
echo PREV_FINAL_CFLAGS=-std=c99 -pedantic -Wall -W -O2 -g -ggdb   -I../deps/hiredis -I../deps/linenoise -I../deps/lua/src -DUSE_JEMALLOC -I../deps/jemalloc/include >> .make-settings
echo PREV_FINAL_LDFLAGS=  -g -ggdb -rdynamic >> .make-settings
(cd ../deps && make hiredis linenoise lua jemalloc)
make[2]: Entering directory `/usr/development/redis-2.8.17/deps'
(cd hiredis && make clean) > /dev/null || true
(cd linenoise && make clean) > /dev/null || true
(cd lua && make clean) > /dev/null || true
(cd jemalloc && [ -f Makefile ] && make distclean) > /dev/null || true
(rm -f .make-*)
(echo "" > .make-ldflags)
(echo "" > .make-cflags)
MAKE hiredis
cd hiredis && make static
make[3]: Entering directory `/usr/development/redis-2.8.17/deps/hiredis'
gcc -std=c99 -pedantic -c -O3 -fPIC  -Wall -W -Wstrict-prototypes -Wwrite-strings -g -ggdb  net.c
make[3]: gcc:命令未找到
make[3]: *** [net.o] 错误 127
make[3]: Leaving directory `/usr/development/redis-2.8.17/deps/hiredis'
make[2]: *** [hiredis] 错误 2
make[2]: Leaving directory `/usr/development/redis-2.8.17/deps'
make[1]: [persist-settings] 错误 2 (忽略)
    CC adlist.o
/bin/sh: cc: command not found
make[1]: *** [adlist.o] 错误 127
make[1]: Leaving directory `/usr/development/redis-2.8.17/src'
make: *** [all] 错误 2

这是由于Linux系统中默认没有安装gcc,这会导致我们无法make成功。
下边使用yum安装gcc:

$ yum -y install gcc

等待安装gcc成功后,继续执行make操作:

$ make

执行完成后,仍然会报错,下边是错误代码

    [root@localhost redis-2.8.17]# make
    cd src && make all
    make[1]: Entering directory `/usr/development/redis-2.8.17/src'
        CC adlist.o
    在包含自 adlist.c:34 的文件中:
    zmalloc.h:50:31: 错误:jemalloc/jemalloc.h:没有那个文件或目录
    zmalloc.h:55:2: 错误:#error "Newer version of jemalloc required"
    make[1]: *** [adlist.o] 错误 1
    make[1]: Leaving directory `/usr/development/redis-2.8.17/src'
    make: *** [all] 错误 2
    [root@localhost redis-2.8.17]# rpm -qa | grep gcc
    libgcc-4.4.7-17.el6.x86_64
    gcc-c++-4.4.7-17.el6.x86_64
    gcc-4.4.7-17.el6.x86_64
    [root@localhost redis-2.8.17]# make  && make install 
    cd src && make all
    make[1]: Entering directory `/usr/development/redis-2.8.17/src'
        CC adlist.o
    在包含自 adlist.c:34 的文件中:
    zmalloc.h:50:31: 错误:jemalloc/jemalloc.h:没有那个文件或目录
    zmalloc.h:55:2: 错误:#error "Newer version of jemalloc required"
    make[1]: *** [adlist.o] 错误 1
    make[1]: Leaving directory `/usr/development/redis-2.8.17/src'
    make: *** [all] 错误 2
    [root@localhost redis-2.8.17]# l
    -bash: l: command not found

以上原因:jemalloc重载了Linux下的ANSI C的malloc和free函数。

解决办法:

在执行make操作时,添加参数:

$ make MALLOC=libc

make 完成后,出现以下代码时,代表Redis已经安装完成。

Hint: To run 'make test' is a good idea ;) 

然后在redis安装目录下执行开启redis服务:

[root@localhost redis-2.8.17]# ./src/redis-server

打开另一个命令行窗口,开启一个客户端:

[root@localhost redis-2.8.17]# ./src/redis-cli
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值