最近在服务器部署pinpoint3.x时需要安装Redis,遇到一些问题以及解决的方法,记录一下。
环境:
- Linux版本:CentOS 6.8(x86),选择7及以上的版本,下面的问题可能都不会出现了
- gcc版本:8.3.1
- Red Hat:8.3.1-3
- Redis版本:7.0.15
0 正常安装
先上传安装包。
# 解压
[~] tar -zxf redis-7.0.15.tar.gz
# 移动到/usr/local/下并重命名为redis
[~] mv redis-7.0.15 /usr/local/redis
# 切换到redis根目录
[~] cd /usr/local/redis
# 编译
[/usr/local/redis] make
# 安装
[/usr/local/redis] make PREFIX=/usr/local/redis install
# “&”以后台方式启动
[/usr/local/redis] ./bin/redis-server& ./redis.conf
1 权限不足Permission denied
最基础纯粹的问题,线上服务器对成员有权限控制,可以先尝试添加权限:
chmod +x yourFile
否则还是老老实实去申请服务器的root权限吧。。。然后切换到root用户
sudo -iu root
2 缺少Python3
Redis是C实现的,所以需要安装C的依赖,这里已经装好了。但是还会报python3缺失的错误。
报错信息:
which: no python3 in (/usr/local/bin:/usr/local/sbin.........
解决方案
- 安装以下依赖
yum install -y zlib*
yum -y install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel
- 安装python3,点击此处获取py3安装包,下载后上传到服务器,解压
tar -zxvf Python-3.6.5.tgz
cd Python-3.6.5/
- 指定安装目录
./configure --prefix=/usr/local/python3 --with-ssl
- 编译,安装,依次执行以下命令:
make
make install
- 根据报错信息进行链接
ln -s /usr/local/python3/bin/python3 /usr/bin/python3
ln -s /usr/local/python3/bin/pip3 /usr/bin/pip3
3 make命令编译Redis时:No such file or directory
报错信息:
In file included from adlist.c:34:
zmalloc.h:50:31: warning: jemalloc/jemalloc.h: No such file or directory
zmalloc.h:55:2: error: #error "Newer version of jemalloc required"
make[1]: *** [adlist.o] Error 1
解决方案:
注意上面报错信息中的第二行“jemalloc/jemalloc.h”,可以发现当前文件夹的deps文件夹内包含“jemalloc”,那么
# 进入deps文件夹
cd deps/
# 执行make
make jemalloc
以此类推,缺少哪个就make哪个。然后回Redis目录重新编译。
4 MAKE hdr_histogram报错
执行make编译redis时。在make hdr_histogram时报错:
MAKE hdr_histogram
cd hdr_histogram && make
make[3]: Entering directory `/usr/local/redis/redis-7.0.15/deps/hdr_histogram'
cc -std=c99 -Wall -Os -g -DHDR_MALLOC_INCLUDE=\"hdr_redis_malloc.h\" -c hdr_histogram.c
In file included from hdr_histogram.c:18:
hdr_atomic.h: In function ‘hdr_atomic_load_pointer’:
hdr_atomic.h:100: error: ‘asm’ undeclared (first use in this function)
hdr_atomic.h:100: error: (Each undeclared identifier is reported only once
hdr_atomic.h:100: error: for each function it appears in.)
hdr_atomic.h:100: error: expected ‘;’ before ‘volatile’
hdr_atomic.h: In function ‘hdr_atomic_store_pointer’:
hdr_atomic.h:106: error: ‘asm’ undeclared (first use in this function)
hdr_atomic.h:106: error: expected ‘;’ before ‘volatile’
hdr_atomic.h: In function ‘hdr_atomic_load_64’:
hdr_atomic.h:112: error: ‘asm’ undeclared (first use in this function)
hdr_atomic.h:112: error: expected ‘;’ before ‘volatile’
hdr_atomic.h: In function ‘hdr_atomic_store_64’:
hdr_atomic.h:118: error: ‘asm’ undeclared (first use in this function)
hdr_atomic.h:118: error: expected ‘;’ before ‘volatile’
hdr_atomic.h: In function ‘hdr_atomic_exchange_64’:
hdr_atomic.h:124: error: ‘asm’ undeclared (first use in this function)
hdr_atomic.h:124: error: expected ‘;’ before ‘volatile’
hdr_atomic.h: In function ‘hdr_atomic_compare_exchange_64’:
hdr_atomic.h:136: error: ‘asm’ undeclared (first use in this function)
hdr_atomic.h:136: error: expected ‘;’ before ‘volatile’
make[3]: *** [hdr_histogram.o] Error 1
make[3]: Leaving directory `/usr/local/redis/redis-7.0.15/deps/hdr_histogram'
make[2]: *** [hdr_histogram] Error 2
make[2]: Leaving directory `/usr/local/redis/redis-7.0.15/deps'
make[1]: [persist-settings] Error 2 (ignored)
make[1]: *** No rule to make target `../deps/jemalloc/include/jemalloc/jemalloc.h', needed by `adlist.o'. Stop.
make[1]: Leaving directory `/usr/local/redis/redis-7.0.15/src'
make: *** [all] Error 2
通过报错信息可以看到,在make hdr_histogram时执行了两个命令:
cd hdr_histogram && make
cc -std=c99 -Wall -Os -g -DHDR_MALLOC_INCLUDE=\"hdr_redis_malloc.h\" -c hdr_histogram.c
解决方案:
进入deps下的hdr_histogram执行以下命令:
cc -std=gnu99 -Wall -Os -g -DHDR_MALLOC_INCLUDE=\"hdr_redis_malloc.h\" -c hdr_histogram.c
也就是将原命令中的“c99”改成“gnu99”。然后回deps文件夹中重新make hdr_histogram。最后回redis目录中重新编译即可。
5 通关
编译安装成功,运行成功。
