CentOS7.x安装Redis6.0.1
下载Redis最新稳定版6.0.1,https://redis.io/
[solang@solang ~]$ wget http://download.redis.io/releases/redis-6.0.1.tar.gz
[solang@solang ~]$ tar -zxf redis-6.0.1.tar.gz -C /usr/local/
[solang@solang ~]$ cd /usr/local/redis-6.0.1/
[solang@solang redis-6.0.1]$ make
执行make
后有错
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
编译Redis的时候需要安装gcc
[root@solang ~]# yum -y install gcc
以普通用户再次编译
[solang@solang redis-6.0.1]$ make
出现下面的错误
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。
[solang@solang redis-6.0.1]$ 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
升级gcc
到5.3以上版本,升级到gcc 9
版本
[root@solang ~]# yum -y install centos-release-scl
[root@solang ~]# yum -y install devtoolset-9-gcc devtoolset-9-gcc-c++ devtoolset-9-binutils
[root@solang ~]# scl enable devtoolset-9 bash
[root@solang ~]# gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/opt/rh/devtoolset-9/root/usr/libexec/gcc/x86_64-redhat-linux/9/lto-wrapper
Target: x86_64-redhat-linux
Configured with: ../configure --enable-bootstrap --enable-languages=c,c++,fortran,lto --prefix=/opt/rh/devtoolset-9/root/usr --mandir=/opt/rh/devtoolset-9/root/usr/share/man --infodir=/opt/rh/devtoolset-9/root/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-shared --enable-threads=posix --enable-checking=release --enable-multilib --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --with-gcc-major-version-only --with-linker-hash-style=gnu --with-default-libstdcxx-abi=gcc4-compatible --enable-plugin --enable-initfini-array --with-isl=/builddir/build/BUILD/gcc-9.1.1-20190605/obj-x86_64-redhat-linux/isl-install --disable-libmpx --enable-gnu-indirect-function --with-tune=generic --with-arch_32=x86-64 --build=x86_64-redhat-linux
Thread model: posix
gcc version 9.1.1 20190605 (Red Hat 9.1.1-2) (GCC)
需要注意的是scl
命令启用只是临时的,退出shell
或重新打开一个shell
就会恢复原系统gcc
版本。
执行以下命令永久使用gcc 9
,其中/opt/rh/devtoolset-9/
是scl
命令启用后gcc -v
中的COLLECT_LTO_WRAPPER
路径前缀。
[root@solang ~]# echo "source /opt/rh/devtoolset-9/enable" >> /etc/profile
注:执行完此命令后,其它的shell窗口需要关闭重新打开才生效。
重新打开shell窗口,以普通用户再次编译
[solang@solang redis-6.0.1]$ make
Hint: It's a good idea to run 'make test' ;)
make[1]: Leaving directory `/usr/local/redis-6.0.1/src'
此次编译成功。
若出现以下的错误,使用make MALLOC=libc
进行编译。
zmalloc.h:50:31: fatal error: jemalloc/jemalloc.h: No such file or directory
#include
^
compilation terminated.
make[1]: *** [adlist.o] Error 1
make[1]: Leaving directory `/usr/local/redis-6.0.1/src'
make: *** [all] Error 2
在redis根目录下执行make install
命令,此命令会将redis/src
下的一些脚本拷贝到/usr/local/bin/
目录下,因为/usr/local/bin/
目录已经在path环境变量中配置了,所以执行此命令的目的是在任何目录下都可以直接启动停止redis。
[solang@solang redis-6.0.1]$ make install
cd src && make install
make[1]: Entering directory `/usr/local/redis-6.0.1/src'
CC Makefile.dep
make[1]: Leaving directory `/usr/local/redis-6.0.1/src'
make[1]: Entering directory `/usr/local/redis-6.0.1/src'
Hint: It's a good idea to run 'make test' ;)
INSTALL install
INSTALL install
INSTALL install
INSTALL install
INSTALL install
make[1]: Leaving directory `/usr/local/redis-6.0.1/src'
本文参考:
Centos7.6安装redis6.0.1
Linux下安装Redis3.0.0