Redis安装及配置
1、软件环境
Redis版本 :redis-2.8.7
Linux 版本:Linux version 3.5.0-23-generic (buildd@akateko) (gcc version 4.6.3 (Ubuntu/Linaro 4.6.3-1ubuntu5) ) #35~precise1-Ubuntu SMP Fri Jan 25 17:15:33 UTC 2013
2、下载
下载redis:
可以在redis的官网下载 :
3、安装redis:
#tar xvzf redis-2.8.7.tar.gz
#cd redis-2.8.7
#make
make之后,会出现一句提示:
Hint: To run 'make test' is a good idea ;)
运行#make test
报错,提示You need 'tclsh8.5' in order to run the Redis test
到http://www.linuxfromscratch.org/blfs/view/cvs/general/tcl.html下载最新的tcl8.6.1-src.tar.gz
然后安装tcl8.6.1-src.tar.gz:
(configure和make的位置比较特殊,在安装目录的unix下,所以下面是tcl官方安装法)
#tar tcl8.6.1-src.tar.gz
#cd tcl8.6.1-src/unix/
#./configure
#make
#make test
#make install
然后在回到redis的代码目录运行测试吧
#cd redis-2.8.7
#make test
最后出现
\o/ All tests passed without errors! 成了
把src目录下面的redis-server 和redis-cli拷贝到bin目录下
# cp src/redis-server /usr/local/bin/
# cp src/redis-cli /usr/local/bin/
4、测试
运行程序 # redis-server
[13271] 16 Jun 20:43:40.086 # Warning: no config file specified, using the default config. In order to specify a config file use redis-server /path/to/redis.conf
[13271] 16 Jun 20:43:40.088 * Max number of open files set to 10032
[13271] 16 Jun 20:43:40.089 # Warning: 32 bit instance detected but no memory limit set. Setting 3 GB maxmemory limit with 'noeviction' policy now.
_._
_.-``__ ''-._
_.-`` `. `_. ''-._ Redis 2.8.7 (00000000/0) 32 bit
.-`` .-```. ```\/ _.,_ ''-._
( ' , .-` | `, ) Running in stand alone mode
|`-._`-...-` __...-.``-._|'` _.-'| Port: 6379
| `-._ `._ / _.-' | PID: 13271
`-._ `-._ `-./ _.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' | http://redis.io
`-._ `-._`-.__.-'_.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' |
`-._ `-._`-.__.-'_.-' _.-'
`-._ `-.__.-' _.-'
`-._ _.-'
`-.__.-'
[13271] 16 Jun 20:43:40.094 # Server started, Redis version 2.8.7
[13271] 16 Jun 20:43:40.094 # 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.
[13271] 16 Jun 20:43:40.116 * DB loaded from disk: 0.022 seconds
[13271] 16 Jun 20:43:40.117 * The server is now ready to accept connections on port 6379
5、修改安装配置方式
1)创建redis文件夹#mkdir /etc/redis
#mkdir /var/redis
2)将启动脚本复制到/etc/init.d目录下
# cp utils/redis_init_script /etc/init.d/redis_6379
3)修改启动脚本
确保REDIS_PORT就是你需要开启的端口,后面的pid文件和配置文件都会依赖它
# vim /etc/init.d/redis_6379
4)创建redis的工作目录
# mkdir /var/redis/6379
5)将redis的配置文件拷贝到/etc/redis目录下,并修改或确认参数
# cp redis.conf /etc/redis/6379.conf
#设置daemonize为yes
#设置pidfile为/var/run/redis_6379.pid
#设置loglevel
#设置logfile为/var/log/redis_6379.log
#设置dir为/var/redis/6379
6)使用下面命令设置新的init脚本
sudo update-rc.d redis_6379 defaults
7)启动redis
# /etc/init.d/redis_6379 start
8)确认是否OK
使用redis-cli save命令将数据dump到文件中,查看/var/redis/6379/ 下是否有dump.rdb文件以及log日志redis_6379.log是否生成在/var/log下。
6、客户端测试
# redis-cli
127.0.0.1:6379> zadd myzset 1 "one"
(integer) 1
127.0.0.1:6379> zadd myzset 1 "uno"
(integer) 1
127.0.0.1:6379> zadd myzset 2 "two" 3 "three"
(integer) 2
127.0.0.1:6379> zrange myzset 0 -1 withscores
1) "one"
2) "1"
3) "uno"
4) "1"
5) "two"
6) "2"
7) "three"
8) "3"
127.0.0.1:6379>
ok可以用了
参考文献:
博客 :
【1】http://www.cnblogs.com/nexiyi/p/3454898.html
【2】http://blog.csdn.net/chenggong2dm/article/details/6100001
【3】官网: http://redis.io
【4】Redis资料汇总专题:http://blog.nosqlfan.com/html/3537.html