刚开始自己搭建redis,踩了很多的坑,现将遇到的问题整理如下:
1、安装,首先,如果是在linux上安装的话,只需要按照官网上的要求去安装即可。
Installation
Download, extract and compile Redis with:
$ wget http://download.redis.io/releases/redis-3.2.5.tar.gz$ tar xzf redis-3.2.5.tar.gz$ cd redis-3.2.5$ make
The binaries that are now compiled are available in the
src
directory. Run Redis with:
$ src/redis-server
You can interact with Redis using the built-in client:
$ src/redis-cliredis> set foo barOKredis> get foo"bar"
如果是在windows下安装的情况下,则需要去另外一个地址去下载,因为redis本身是没有windows版本的,只不过有个组织开发了一个windows版本的,如下:(这一段是拷贝的别人的)
项目地址是:
在 Release 页面中,可以找到 msi 安装文件以及 .zip 文件(而且有3.0的beta版,请下拉查找)。
下载解压,没什么好说的,在解压后的bin目录下有以下这些文件:
- redis-benchmark.exe #基准测试
- redis-check-aof.exe # aof
- redis-check-dump.exe # dump
- redis-cli.exe # 客户端
- redis-server.exe # 服务器
- redis.windows.conf # 配置文件
启动命令:
redis-server.exe redis.windows.conf
- D:\Develop\redis-2.8.12>redis-server.exe redis.windows.conf
- [7736] 10 Aug 21:39:42.974 #
- The Windows version of Redis allocates a large memory mapped file for sharing
- the heap with the forked process used in persistence operations. This file
- will be created in the current working directory or the directory specified by
- the 'dir' directive in the .conf file. Windows is reporting that there is
- insufficient disk space available for this file (Windows error 0x70).
- You may fix this problem by either reducing the size of the Redis heap with
- the --maxheap flag, or by starting redis from a working directory with
- sufficient space available for the Redis heap.
- Please see the documentation included with the binary distributions for more
- details on the --maxheap flag.
- Redis can not continue. Exiting.
根据提示,是 maxheap 标识有问题,打开配置文件
redis.windows.conf ,
搜索
maxheap
, 然后直接指定好内容即可.
- .......
- #
- # maxheap <bytes>
- maxheap 1024000000
- .......
然后再次启动,OK,成功.
- D:\work\redis-3.2.100>redis-server redis.windows.conf
- _._
- _.-``__ ''-._
- _.-`` `. `_. ''-._ Redis 3.2.1000 (00000000/0) 64 bit
- .-`` .-```. ```\/ _.,_ ''-._
- ( ' , .-` | `, ) Running in stand alone mode
- |`-._`-...-` __...-.``-._|'` _.-'| Port: 6379
- | `-._ `._ / _.-' | PID: 6731
- `-._ `-._ `-./ _.-' _.-'
- |`-._`-._ `-.__.-' _.-'_.-'|
- | `-._`-._ _.-'_.-' | http://redis.io
- `-._ `-._`-.__.-'_.-' _.-'
- |`-._`-._ `-.__.-' _.-'_.-'|
- | `-._`-._ _.-'_.-' |
- `-._ `-._`-.__.-'_.-' _.-'
- `-._ `-.__.-' _.-'
- `-._ _.-'
- `-.__.-'
- [6736] 10 Nov 16:01:22.247 # Server started, Redis version 3.2.100
- [6736] 10 Nov 16:01:22.248 * The server is now ready to accept connections on port 6379
然后可以使用自带的客户端工具进行测试。
双击打开
redis-cli.exe
, 如果不报错,则连接上了本地服务器,然后测试,比如 set命令,get命令:
- 127.0.0.1:6379> set test qqqq
- OK
- 127.0.0.1:6379> get test
- "qqqq"
- 127.0.0.1:6379>
如果需要帮助,可以在 cli窗口中输入 help查看,例如:
127.0.0.1:6379> help
2、关于在使用过程中踩的坑
redis默认是只允许本地连接,如果想要在外部调用,则会报connection refused,如下图:
所以需要在redis.conf中把bind的本地ip给注释掉,或者绑定对应的外部的ip地址,另外如果允许的客户端够多的话,对内存有一定的要求,如果没有那么多的内存的话需要将maxclint的数目改小一点。
再者还有一个问题,redis默认是开启保护模式的,如果外部想要连接,需要将保护模式去掉,或者绑定0.0.0.0这个ip地址,或者是设置用户名和密码