1.安装
$ wget http://download.redis.io/releases/redis-2.8.9.tar.gz
$ tar xzf redis-2.8.9.tar.gz
$ cd redis-2.8.9
$ make
make之后,会出现一句提示:
Hint: To run 'make test' is a good idea ;)
其实不测试,一般都可以用。但是既然人家建议了,咱们就走一下make test吧。
运行
#make test
成功以后,提示:
\o/ All tests passed without errors!
Cleanup: may take some time... OK
make[1]: Leaving directory `/root/redis-2.8.9/src'
执行完后,会在当前目录中的src目录中生成相应的执行文件,如:redis-server redis-cli等;
2.精简运行文件
mkdir /usr/local/redis/{conf,bin,db} -pv
cp redis.conf /usr/local/redis/conf
cd src
cp redis-benchmark redis-check-aof redis-check-dump redis-cli redis-server mkreleasehdr.sh /usr/local/redis/bin/
3.启动redis
/usr/local/redis/bin/redis-server /usr/local/redis/conf/redis.conf
[26765] 10 May 23:52:10.706 * Increased maximum number of open files to 10032 (it was originally set to 1024).
_._
_.-``__ ''-._
_.-`` `. `_. ''-._ Redis 2.8.9 (00000000/0) 64 bit
.-`` .-```. ```\/ _.,_ ''-._
( ' , .-` | `, ) Running in stand alone mode
|`-._`-...-` __...-.``-._|'` _.-'| Port: 6379
| `-._ `._ / _.-' | PID: 26765
`-._ `-._ `-./ _.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' | http://redis.io
`-._ `-._`-.__.-'_.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' |
`-._ `-._`-.__.-'_.-' _.-'
`-._ `-.__.-' _.-'
`-._ _.-'
`-.__.-'
[26765] 10 May 23:52:10.708 # Server started, Redis version 2.8.9
[26765] 10 May 23:52:10.708 # WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect.
[26765] 10 May 23:52:10.708 * The server is now ready to accept connections on port 6379
此时启动所有的配置都是默认的,可以看到redis是前台运行,启动服务默认端口6379
4.查询运行
# netstat -tlnp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:6379 0.0.0.0:* LISTEN 26765/redis-server
5.客户端连接
# ./redis-cli
127.0.0.1:6379> set foo bar
OK
127.0.0.1:6379> get foo
"bar"
127.0.0.1:6379>
6.关闭redis
redis-cli shutdown
也可以指定端口:
redis-cli -p 6380 shutdown