redis安装常见问题
1、不能编译没有GCC 编译工具
安装报错:
问题1:make时可能会报如下错误
cc -c -std=c99 -pedantic -O2 -Wall -W -g -rdynamic -ggdb adlist.c
make: cc:命令未找到
make: *** [adlist.o] 错误 127
解决方法:安装gcc
命令如下:yum install gcc
2、make时可能会报如下错误:
collect2: ld returned 1 exit status
make[1]: *** [redis-server] Error 1
make[1]: Leaving directory `/usr/local/redis/src'
make: *** [all] Error 2
解决办法:
编辑src/.make-settings里的OPT,改为OPT=-O2 -march=i686
3、make时可能会报如下错误:
make[1]: Entering directory `/usr/local/redis/redis-6.0.8/src'
CC Makefile.dep
make[1]: Leaving directory `/usr/local/redis/redis-6.0.8/src'
make[1]: Entering directory `/usr/local/redis/redis-6.0.8/src'
CC adlist.o
adlist.c:1:0: error: CPU you selected does not support x86-64 instruction set
解决办法:
编辑src/.make-settings里的OPT,改为OPT=-O2 -march=x86-64
4、make时可能会报如下错误:
cc: error: ../deps/hiredis/libhiredis.a: No such file or directory
cc: error: ../deps/lua/src/liblua.a: No such file or directory
cc: error: ../deps/jemalloc/lib/libjemalloc.a: No such file or directory
make: *** [redis-server] Error 1
分别进入redis下的deps下的hiredis、lua 运行make
注意:jemalloc下可能要先运行./configure,然后make
回到src目录运行 make
如果报如下错误:
cd src && make all
make[1]: 进入目录“/home/redis/redis-3.0.2/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]: 离开目录“/home/redis/redis-3.0.2/src”
make: *** [all] 错误 2
使用命令make MALLOC=libc重新编译
5.修改默认端口号
为redis分配一个7777端口,操作步骤如下:
1.打开redis.conf配置文件,找到port 6379这行,把6379改为7777。====>vi /etc/redis/redis.conf
2、启动redis服务:/usr/local/bin/redis-server /etc/redis/redis.conf
3、通过“[root@localhost redis-stable]# ps -ef | grep redis ”查看进程,
4、redis-cli -p 7777, 测试端口是否创建成功。
5.127.0.0.1:7777> set name dzh
OK
127.0.0.1:7777> get name
"dzh"
127.0.0.1:7777> del name
(integer) 1
6.最新版redis, 可能需要升级gcc版本
server.c:5304: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:5307:31: error: ‘struct redisServer’ has no member named ‘server_cpulist’
redisSetCpuAffinity(server.server_cpulist);
解决办法:
# 查看gcc版本是否在5.3以上,centos7.6默认安装4.8.5
gcc -v
# 升级gcc到5.3及以上,如下: 升级到gcc 9.3:
yum -y install centos-release-scl
yum -y install devtoolset-9-gcc devtoolset-9-gcc-c++ devtoolset-9-binutils
scl enable devtoolset-9 bash
需要注意的是scl命令启用只是临时的,退出shell或重启就会恢复原系统gcc版本。 如果要长期使用gcc 9.3的话:
echo "source /opt/rh/devtoolset-9/enable" >>/etc/profile
这样退出shell重新打开就是新版的gcc了 以下其他版本同理,修改devtoolset版本号即可