CentOS 7.7系统安装Redis 6.0.3

前提操作

避免出现如下的错误

yum -y install gcc tcl
yum -y install centos-release-scl
yum -y install devtoolset-9-gcc devtoolset-9-gcc-c++ devtoolset-9-binutils
echo "source /opt/rh/devtoolset-9/enable" >> /etc/profile

1.下载Redis

下载地址:https://redis.io/

wget http://download.redis.io/releases/redis-6.0.3.tar.gz

2.安装Redis

2.1编译Redis

tar -zxv -f redis-6.0.3.tar.gz -C /usr/local/
cd redis-6.0.3
make MALLOC=libc
make test

在redis根目录下执行make install命令,此命令会将redis/src下的一些脚本拷贝到/usr/local/bin/目录下,
因为/usr/local/bin/目录已经在path环境变量中配置了,所以执行此命令的目的是在任何目录下都可以直接启动停止redis。

# make install

常见错误

make[3]: cc: Command not found
make[3]: *** [net.o] Error 127
make[3]: Leaving directory `/usr/local/redis-6.0.1/deps/hiredis'
make[2]: *** [hiredis] Error 2
make[2]: Leaving directory `/usr/local/redis-6.0.1/deps'
make[1]: [persist-settings] Error 2 (ignored)
    CC adlist.o
/bin/sh: cc: command not found
make[1]: *** [adlist.o] Error 127
make[1]: Leaving directory `/usr/local/redis-6.0.1/src'
make: *** [all] Error 2

解决办法:
安装gcc:yum install gcc
2.

server.c:5099:19: error: ‘struct redisServer’ has no member named ‘ipfd_count’
         if (server.ipfd_count > 0 || server.tlsfd_count > 0)
                   ^
server.c:5099:44: error: ‘struct redisServer’ has no member named ‘tlsfd_count’
         if (server.ipfd_count > 0 || server.tlsfd_count > 0)
                                            ^
server.c:5101:19: error: ‘struct redisServer’ has no member named ‘sofd’
         if (server.sofd > 0)
                   ^
server.c:5102:94: error: ‘struct redisServer’ has no member named ‘unixsocket’
             serverLog(LL_NOTICE,"The server is now ready to accept connections at %s", server.unixsocket);
                                                                                              ^
server.c:5103:19: error: ‘struct redisServer’ has no member named ‘supervised_mode’
         if (server.supervised_mode == SUPERVISED_SYSTEMD) {
                   ^
server.c:5104:24: error: ‘struct redisServer’ has no member named ‘masterhost’
             if (!server.masterhost) {
                        ^
server.c:5117:15: error: ‘struct redisServer’ has no member named ‘maxmemory’
     if (server.maxmemory > 0 && server.maxmemory < 1024*1024) {
               ^
server.c:5117:39: error: ‘struct redisServer’ has no member named ‘maxmemory’
     if (server.maxmemory > 0 && server.maxmemory < 1024*1024) {
                                       ^
server.c:5118:176: error: ‘struct redisServer’ has no member named ‘maxmemory’
         serverLog(LL_WARNING,"WARNING: You specified a maxmemory value that is less than 1MB (current value is %llu bytes). Are you sure this is what you really want?", server.maxmemory);
                                                                                                                                                                                ^
server.c: In function ‘hasActiveChildProcess’:
server.c:1476:1: warning: control reaches end of non-void function [-Wreturn-type]
 }
 ^
server.c: In function ‘allPersistenceDisabled’:
server.c:1482:1: warning: control reaches end of non-void function [-Wreturn-type]
 }
 ^
server.c: In function ‘writeCommandsDeniedByDiskError’:
server.c:3747:1: warning: control reaches end of non-void function [-Wreturn-type]
 }
 ^
server.c: In function ‘iAmMaster’:
server.c:4914:1: warning: control reaches end of non-void function [-Wreturn-type]
 }
 ^
make[1]: *** [server.o] Error 1
make[1]: Leaving directory `/usr/local/redis-6.0.1/src'
make: *** [all] Error 2

解决办法:
查看gcc版本是否在5.3以上,CentOS7默认安装4.8.5。
升级gcc到5.3以上版本,升级到gcc 9

gcc -v

Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-redhat-linux/4.8.5/lto-wrapper
Target: x86_64-redhat-linux
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-bootstrap --enable-shared --enable-threads=posix --enable-checking=release --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --with-linker-hash-style=gnu --enable-languages=c,c++,objc,obj-c++,java,fortran,ada,go,lto --enable-plugin --enable-initfini-array --disable-libgcj --with-isl=/builddir/build/BUILD/gcc-4.8.5-20150702/obj-x86_64-redhat-linux/isl-install --with-cloog=/builddir/build/BUILD/gcc-4.8.5-20150702/obj-x86_64-redhat-linux/cloog-install --enable-gnu-indirect-function --with-tune=generic --with-arch_32=x86-64 --build=x86_64-redhat-linux
Thread model: posix
gcc version 4.8.5 20150623 (Red Hat 4.8.5-39) (GCC)
# 编译出错时,清除编译生成的文件     不执行也可以
make distclean
yum -y install centos-release-scl
yum -y install devtoolset-9-gcc devtoolset-9-gcc-c++ devtoolset-9-binutils
# 需要注意的是scl命令启用只是临时的,退出shell或重新打开一个shell就会恢复原系统gcc版本
scl enable devtoolset-9 bash
gcc -v
#执行以下命令永久使用
echo "source /opt/rh/devtoolset-9/enable" >> /etc/profile
# 注:执行完此命令后,其它的shell窗口需要关闭重新打开才生效。
# 重新打开shell窗口,再次编译
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 `/usr/local/redis-6.0.1/src'
make: *** [all] Error 2

解决办法:

make MALLOC=libc
posted @ 2020-05-25 09:55  哈喽哈喽111111  阅读(4485)  评论(1编辑  收藏  举报