CentOS7.x系統安裝Redis6.0.1

CentOS7.x安裝Redis6.0.1

1.下載Redis

下載Redis最新穩定版6.0.1,https://redis.io/

[solang@solang ~]$ wget http://download.redis.io/releases/redis-6.0.1.tar.gz

2.安裝Redis

2.1編譯Redis

[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

2.2升級gcc版本

升級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 <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

2.3make install

在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

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章