1. Install Redis step
1.1. 参考:
1.2. 源码安装
- 下载:从Redis官网下载最新版本的
redis
安装文件,本次安装使用的最新稳定版本是4.0.2
;wget http://download.redis.io/releases/redis-4.0.2.tar.gz
解压到指定目录;
tar xzf redis-4.0.2.tar.gz
使用
make test
命令进行编译测试,确定没有问题;使用
make
命令进行编译;➜ source sudo wget http://download.redis.io/releases/redis-3.2.9.tar.gz ➜ source sudo tar -xzvf redis-3.2.9.tar.gz ➜ source pwd /usr/local/source ➜ source cd .. ➜ local sudo ln -s /usr/local/source/redis-3.2.9 redis ➜ local cd redis ➜ redis sudo make test
使用
make install
命令进行编译安装;➜ redis sudo make install cd src && /Library/Developer/CommandLineTools/usr/bin/make install INSTALL redis-sentinel CC redis-cli.o LINK redis-cli CC redis-benchmark.o LINK redis-benchmark INSTALL redis-check-rdb Hint: It's a good idea to run 'make test' ;) INSTALL install INSTALL install INSTALL install INSTALL install INSTALL install
在终端输入
redis-server
来测试是否安装成功;➜ redis redis-server 45397:C 19 May 13:26:08.639 # Warning: no config file specified, using the default config. In order to specify a config file use redis-server /path/to/redis.conf 45397:M 19 May 13:26:08.641 * Increased maximum number of open files to 10032 (it was originally set to 2560). _._ _.-``__ ''-._ _.-`` `. `_. ''-._ Redis 3.2.9 (00000000/0) 64 bit .-`` .-```. ```\/ _.,_ ''-._ ( ' , .-` | `, ) Running in standalone mode |`-._`-...-` __...-.``-._|'` _.-'| Port: 6379 | `-._ `._ / _.-' | PID: 45397 `-._ `-._ `-./ _.-' _.-' |`-._`-._ `-.__.-' _.-'_.-'| | `-._`-._ _.-'_.-' | http://redis.io `-._ `-._`-.__.-'_.-' _.-' |`-._`-._ `-.__.-' _.-'_.-'| | `-._`-._ _.-'_.-' | `-._ `-._`-.__.-'_.-' _.-' `-._ `-.__.-' _.-' `-._ _.-' `-.__.-' 45397:M 19 May 13:26:08.646 # Server started, Redis version 3.2.9 45397:M 19 May 13:26:08.646 * The server is now ready to accept connections on port 6379
- 在
redis
目录下创建三个目录:bin
,etc
,db
- 把
/usr/local/redis/src
目录下的mkreleasehdr.sh,redis-benchmark, redis-check-dump, redis-cli, redis-server
复制到bin
目录:➜ redis sudo cp src/redis-server src/redis-cli src/mkreleasehdr.sh src/redis-benchmark bin
- 把
/usr/local/redis/redis.conf
文件复制到etc
目录下:➜ redis sudo cp redis.conf etc
修改
etc
下的配置文件:redis.conf
# 守护模式 daemonize yes #设置进程锁文件 pidfile /usr/local/redis/redis.pid #日志文件位置 logfile /usr/local/redis/log-redis.log
- 保存后,启动redis
➜ redis sudo ./bin/redis-server etc/redis.conf Password: ➜ redis ps -ef | grep 'redis' 0 45662 1 0 1:51下午 ?? 0:00.01 ./bin/redis-server 127.0.0.1:6379 501 45669 45402 0 1:51下午 ttys003 0:00.01 grep --color=auto --exclude-dir=.bzr --exclude-dir=CVS --exclude-dir=.git --exclude-dir=.hg --exclude-dir=.svn redis
查看日志文件
➜ redis tail -f log-redis.log `-._ `-._`-.__.-'_.-' _.-' |`-._`-._ `-.__.-' _.-'_.-'| | `-._`-._ _.-'_.-' | `-._ `-._`-.__.-'_.-' _.-' `-._ `-.__.-' _.-' `-._ _.-' `-.__.-' 45662:M 19 May 13:51:10.277 # Server started, Redis version 3.2.9 45662:M 19 May 13:51:10.277 * The server is now ready to accept connections on port 6379
- 使用客户端连接测试
➜ redis ./bin/redis-cli 127.0.0.1:6379> ping PONG 127.0.0.1:6379> ping test "test"
1.3. 安装过程可能遇到的问题
make[3]: gcc: Command not found
在make test
的时候,遇到错误:make[3]: gcc: Command not found
,由于用的虚拟机,没有安装gcc编译器,所以报错,解决办法是使用yum进行安装:# yum install gcc
zmalloc.h:50:31: error: jemalloc/jemalloc.h: No such file or directory
make test
时报错:zmalloc.h:50:31: error: 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 make[1]: Leaving directory `/usr/local/source/redis-4.0.2/src' make: *** [test] Error 2
原因分析:
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, 因为 jemalloc 被证明 有更少的 fragmentation problems 比libc。
但是如果你又没有jemalloc 而只有 libc 当然 make 出错。 所以加这么一个参数。
解决办法
make MALLOC=libc
couldn't execute "tclsh8.5": no such file or directory
异常原因:没有安装tcl
解决方案:yum install -y tcl。