CentOS 7安裝Redis

寒武沒有紀發表於2018-11-09

準備

CentOS:7

Redis:4.0.11

安裝

下載redis安裝包並上傳

解壓

[root@localhost redis]# tar -zxvf redis-4.0.11.tar.gz

執行編譯

[root@localhost redis]# make

可能存在異常問題

  • /bin/sh: cc: 未找到命令
[root@localhost redis-4.0.11]# make
cd src && make all
make[1]: 進入目錄“/opt/apps/redis/redis-4.0.11/src”
    CC adlist.o
/bin/sh: cc: 未找到命令
make[1]: *** [adlist.o] 錯誤 127
make[1]: 離開目錄“/opt/apps/redis/redis-4.0.11/src”
make: *** [all] 錯誤 2

redis依賴於gcc進行編譯,可使用yum安裝,如yum不可用,可以參考CentOS安裝配置yum進行配置

[root@localhost redis]# yum install gcc
  • 致命錯誤:jemalloc/jemalloc.h:沒有那個檔案或目錄
[root@localhost redis-4.0.11]# make
cd src && make all
make[1]: 進入目錄“/opt/apps/redis/redis-4.0.11/src”
    CC adlist.o
In file included from adlist.c:34:0:
zmalloc.h:50:31: 致命錯誤:jemalloc/jemalloc.h:沒有那個檔案或目錄
 #include <jemalloc/jemalloc.h>
                               ^
編譯中斷。
make[1]: *** [adlist.o] 錯誤 1
make[1]: 離開目錄“/opt/apps/redis/redis-4.0.11/src”
make: *** [all] 錯誤 2

檢視 redis 說明檔案 README.md ,存在關於 Allocator 的說明資訊

Allocator

Selecting a non-default memory allocator when building Redis is done by setting
the MALLOC environment variable. Redis is compiled and linked against libc
malloc by default, with the exception of jemalloc being the default on Linux
systems. This default was picked because jemalloc has proven to have fewer
fragmentation problems than libc malloc.

To force compiling against libc malloc, use:
% make MALLOC=libc

To compile against jemalloc on Mac OS X systems, use:
% make MALLOC=jemalloc

關於分配器 Allocator ,如果存在 MALLOC 這個環境變數,會使用這個環境變數去構建 Redis 。但 libc 並不是預設分配器, 預設的是 jemalloc ,因此可以通過指定解決。

make MALLOC=libc

編譯測試

[root@localhost redis-4.0.11]# make test
cd src && make test
make[1]: 進入目錄“/opt/apps/redis/redis-4.0.11/src”
    CC Makefile.dep
make[1]: 離開目錄“/opt/apps/redis/redis-4.0.11/src”
make[1]: 進入目錄“/opt/apps/redis/redis-4.0.11/src”
You need tcl 8.5 or newer in order to run the Redis test
make[1]: *** [test] 錯誤 1
make[1]: 離開目錄“/opt/apps/redis/redis-4.0.11/src”
make: *** [test] 錯誤 2

redis編譯測試依賴於 tcl,可以 yum 安裝

[root@localhost redis-4.0.11]# yum install tcl

編譯並安裝

[root@localhost redis-4.0.11]# make install

其它

  • 訪問來源限制

預設為bind 127.0.0.1,限制本機訪問,可設定不限制訪問來源IP(註釋效果一樣)或指定訪問IP

bind 0.0.0.0

相關文章