1. 环境介绍
- CentOS7 (未安装Development Tools)
2. 下载Redis5.0-rc3
wget -O redis-5.0-rc3.tar.gz https://github.com/antirez/redis/archive/5.0-rc3.tar.gz
3. 解压redis
tar -zxvf redis-5.0-rc3.tar.gz -C /usr/local
4. 编译并安装
cd /usr/local/redis-5.0-rc3 make
此时会出错:
compilation terminated.
make[1]: *** [adlist.o] Error 1 make[1]: Leaving directory `/usr/local/redis-5.0-rc3/src' make: *** [all] Error 2
安装Development Tools
yum groupinstall 'Development Tools'
再次执行,还会报错
make
cd src && make all
make[1]: Entering directory `/usr/local/redis-5.0-rc3/src' CC adlist.o In file included from adlist.c:34:0: 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-5.0-rc3/src' make: *** [all] Error 2
最后解决方案如下:
cd /usr/local/redis-5.0-rc3/deps; make hiredis lua jemalloc linenoise
编译完成后再次在/usr/local/redis-5.0-rc3
中执行make命令
cd /usr/local/redis-5.0-rc3 make
出现如下即编译成功
Hint: It's a good idea to run 'make test' 😉 make[1]: Leaving directory `/usr/local/redis-5.0-rc3/src'
然后在/usr/local/redis-5.0-rc3/src
中执行安装命令:
cd /usr/local/redis-5.0-rc3/src make install
会出现如下日志信息
Hint: It's a good idea to run 'make test' 😉 INSTALL install INSTALL install INSTALL install INSTALL install INSTALL install
5. 修改redis.conf配置文件
vim /usr/local/redis-5.0-rc3/redis.conf
只需要调整如下几个即可
protected-mode no # 关闭保护模式 daemonize yes # 守护进程模式开启
6. 启动redis5.0
/usr/local/redis-5.0-rc3/src/redis-server /usr/local/redis-5.0-rc3/redis.conf
其实我们在执行make install
的时候会将src下面的几个命令复制到/usr/local/bin/
下面去,也可以执行如下命令启动redis5.0
/usr/local/bin/redis-server /usr/local/redis-5.0-rc3/redis.conf
检查端口
netstat -ltnp |grep 6379
如果有端口监听,说明redis已经启动成功。
连接下试试
redis-cli
127.0.0.1:6379> info # Server redis_version:4.9.103 redis_git_sha1:00000000 redis_git_dirty:0 redis_build_id:207f31cf830c081e redis_mode:standalone os:Linux 3.10.0-693.17.1.el7.x86_64 x86_64 arch_bits:64 multiplexing_api:epoll atomicvar_api:atomic-builtin gcc_version:4.8.5 process_id:20361 run_id:4835668974ad86f1db9b3c8b98e02be1a87a7b9b tcp_port:6379 uptime_in_seconds:689 uptime_in_days:0 hz:10 lru_clock:3944003
为什么能在任意目录执行redis-cli
命令呢,因为redis-cli
命令在/usr/local/bin
目录里面,而该目录又配置在PATH中,所以你可以向执行ls、mkdir等命令的方式去执行redis-cli
或者redis-server
等命令。
一般我们在安装完redis后就会将其安装包给删除,那么我们只需要将redis.conf配置文件移动的其他目录,比如:/etc/redis/redis.conf
中,具体位置在哪请按照自己的习惯或者规范放置即可。