CentOS6.4 安装Redis

CentOS7下Redis的安装

按照下面步骤依次执行
1.检查依赖,安装依赖

  Redis是一种高级key-value数据库。它跟memcached类似,不过数据可以持久化,而且支持的数据类型很丰富。有字符串,链表,集
合和有序集合。支持在服务器端计算集合的并,交和补集(difference)等,还支持多种排序功能。所以Redis也可以被看成是一个数据结构服务
器。

1、下载软件:

本文主要记录了CentOS安装redis环境的主要步骤,步骤主要分4大块,分别为

  • 客户端安装
  • 环境配置
  • 启动并测试
  • 服务创建
    有兴趣的同学可以作为参考,如果遇到问题也可以留言,共同交流。

1.1. 什么是redis

Redis是用C语言开发的一个开源的高性能键值对(key-value)数据库。它通过提供多种键值数据类型来适应不同场景下的存储需求,目前为止Redis支持的键值数据类型如

下:

字符串类型

散列类型

列表类型

集合类型

有序集合类型

[root@ecs-3c46 ~]# whereis gcc
gcc: /usr/bin/gcc /usr/lib/gcc /usr/libexec/gcc /usr/share/man/man1/gcc.1.gz
[root@ecs-3c46 ~]# whereis tc
tc: /sbin/tc /usr/lib64/tc /usr/share/tc /usr/share/man/man8/tc.8.gz
[root@ecs-3c46 ~]# whereis wget
wget: /usr/bin/wget /usr/share/man/man1/wget.1.gz
[root@ecs-3c46 ~]# yum -y install tcl

  Redis的所有数据都是保存在内存中,然后不定期的通过异步方式保存到磁盘上(这称为“半持久化模式”);也可以把每一次数据变化都写入到一个append
only file(aof)里面(这称为“全持久化模式”)。

  wget wget http://download.redis.io/releases/redis-2.8.7.tar.gz

安装步骤

  • ### 安装

1.2. Redis的安装

redis是C语言开发,建议在linux上运行,本教程使用Centos6.4作为安装环境。

安装redis需要先将官网下载的源码进行编译,编译依赖gcc环境,如果没有gcc环境,需要安装gcc:yum
install gcc-c++

redis的安装:

$ wget
$ tar xzf redis-3.0.1.tar.gz
$ cd redis-3.0.1
$ make
$ make install
在安装成功之后,可以运行测试,确认Redis的功能是否正常
$ make test

启动
$ redis-server

1.1. 什么是redis
Redis是用C语言开发的一个开源的高性能键值对(key-value)数据库。它通过提供多种键值数据类型来适应不…

2.进入/user/local/src/

 

2、解压软件并编译安装:

安装编译环境(务必提前安装)
yum -y install gcc openssl-devel libyaml-devel libffi-devel readline-devel zlib-devel gdbm-devel ncurses-devel gcc-c++ automake autoconf
[root@ecs-3c46 ~]# cd /usr/local/src/

1.安装tcl支持

  tar -zxvf redis-2.8.7.tar.gz

切换命令到/usr/local/目录下
    cd /usr/local

3.wget下载redis

$yum install tcl

  mv redis-2.8.7.tar.gz redis

下载redis安装包
wget http://download.redis.io/releases/redis-3.0.6.tar.gz
[root@ecs-3c46 src]# wget http://download.redis.io/releases/redis-3.0.7.tar.gz

安装gcc,不然make的时候会报错

  cd redis

解压安装包并安装
tar xvf redis-3.0.6.tar.gz
cd redis-3.0.6/
make MALLOC=libc
make install
  • ### 配置

4.解压

make[3]: gcc:命令未找到,//没有安装gcc

[root@winner ~]# yum install -y gcc g++ gcc-c++ make
[root@winner ~]# gcc -v

  make&&make install

创建redis配置文件目录
// 切换命令到/etc目录下
cd /etc
// 创建redis配置文件目录
mkdir redis
[root@ecs-3c46 src]tar zxvf redis-3.0.7.tar.gz

2.安装redis

  等待编译一端时间即可(如果您的机器上没有c++编译环境,可以通过yum安装
gcc ,命令:yum -y install gcc)

创建log、pid等目录(放在/var目录下)
// 命令切换至/var目录下
cd /var
// 创建redis目录
mkdir redis
// 进入redis目录
cd redis
// 创建log等目录
mkdir data log run

5.将文件转存到/usr/local/redis

[root@winner 桌面]# wget http://download.redis.io/releases/redis-3.0.5.tar.gz
下载下来以后在桌面,可以拷贝到/usr/local中

[root@winner local]# tar zxf redis-3.0.5.tar.gz 

[root@winner local]# cd redis-3.0.5

[root@winner redis-3.0.5]$ make

  cd src

修改配置文件
// 切换命令至redis安装包目录
cd /usr/local/redis-3.0.6
// 复制安装包中的redis.conf文件至/etc/redis目录
cp redis.conf /etc/redis
// 目录切换至/etc/redis
cd /etc/redis
// 编辑redis.conf文件
vim redis.conf
// 修改redis为后台运行
daemonize  yes
// 修改pid目录为前面创建的run目录
pidfile  /var/redis/run/redis.pid
// 修改默认端口(默认为6379)
port  6379
// 修改日志目录为前面创建的log目录
logfile  /var/redis/log/redis.log
  • ### 启动并测试
[root@ecs-3c46 src]mkdir /usr/local/redis
[root@ecs-3c46 src]mv redis-3.0.7 /usr/local/redis
[root@ecs-3c46 src]ll /usr/local/redis

出现了错误

  启动redis-server:./redis-server  ../redis.conf

启动redis
redis-server /etc/redis/redis.conf
// 查看redis服务是否启动(出现redis-server的进程说明启动成功)
ps -ef|grep redis

6.编译安装

zmalloc.h:50:31: 错误:jemalloc/jemalloc.h:没有那个文件或目录zmalloc.h:55:2: 错误:#error "Newer version of jemalloc required"make[1]: *** [adlist.o] 错误 1make[1]: Leaving directory `/home/winner/桌面/redis-3.0.5/src'make: *** [all] 错误 2解决办法是:

  启动会发送警告:

测试redis功能是否正常
// 进入redis客户端命令界面
redis-cli -c -p 6379
// 获取test键值(返回nil)
get test
// 给test键赋值
set test "测试"
// 再次查看test键值(返回‘测试’)
get test

如果能够正常获取到test的值,则redis已能正常运行。

  • ### 服务创建

目前redis的启动方式不是以服务形式启动的,为了使用方便,下面会说下redis以服务器形式启动及开机自启动的设置方法。

[root@ecs-3c46 src]cd /usr/local/redis
[root@ecs-3c46 redis]make && make install
make MALLOC=libc

[winner@winner redis-3.0.5]$ make MALLOC=libc

Hint: It's a good idea to run 'make test' ;)

make[1]: Leaving directory `/usr/local/redis-3.0.5/src'

  [16403] 12 Dec 21:55:32.830 # 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.

创建自启动脚本
// 拷贝redis客户端自带的自启动脚本至/etc/init.d目录,文件在redis客户端的utils目录下
cd /usr/local/redis-3.0.6/utils
cp redis_init_script /etc/init.d
// 重命名/etc/init.d目录下的redis_init_script为redis
mv redis_init_script redis
// 编辑redis脚本
vim redis
// 将脚本中对应节点数据改为如下所示:
PIDFILE=/var/redis/run/redis.pid
CONF="/etc/redis/redis.conf"

 7.在etc目录下创建redi文件夹并创建配置文件,并修改配置文件

安装

  安装提示,解决上述问题。默认的情况下,redis监听6379端口。

测试脚本
// 如果前面步骤中开启的redis进程未关闭,则先使用stop命令停止
service redis stop
// 显示正常停止后使用start命令即可启动redis
service redis start
// 使用前面步骤中提到的测试redis客户端的方式测试redis是否启动成功
redis-cli -c -p 6379
[root@ecs-3c46 redis]mkdir -p /etc/redis
[root@ecs-3c46 redis]pwd
[root@ecs-3c46 redis]cp -fr /usr/local/redis/redis.conf /etc/redis/
[root@winner redis-3.0.5]# make install

cd src && make install
make[1]: Entering directory `/usr/local/redis-3.0.5/src'

Hint: It's a good idea to run 'make test' ;)

    INSTALL install
    INSTALL install
    INSTALL install
    INSTALL install
    INSTALL install
make[1]: Leaving directory `/usr/local/redis-3.0.5/src'

[root@winner redis-3.0.5]#cp redis.conf /etc/

  3、测试使用redis  #使用 telnet 

开机自启动
chkconfig redis on

如果提示服务redis不支持chkconfig,原因为redis启动脚本未设置启动优先级,返回到/etc/init.d目录,修改redis脚本如下

#!/bin/sh
# chkconfig:   2345 90 10
#
# Simple Redis init.d script conceived to work on Linux systems
# as it does use of the /proc filesystem.

再次设置chkconfig redis
on,无错误提示则成功,至此,centos安装redis所有步骤已完成,尽情的折腾去吧。。。
PS:下一篇文章会写下redis集群配置,有兴趣的同学可以关注,3Q!

8.vim编辑/etc/redis/redis.conf,修改daemonize属性为yes

测试通过后安装,安装后会自动把redis-server,redis-cli,redis-benchmark,redis-check-aof,redis-check-dump复制到/usr/local/bin目录下。

  

[root@ecs-3c46 redis]# vim /etc/redis/redis.conf
# By default Redis does not run as a daemon. Use 'yes' if you need it.
# Note that Redis will write a pid file in /var/run/redis.pid when daemonized.
daemonize yes

参数介绍:

[likehua@localhost local]$ telnet localhost 6379
Trying ::1...
Connected to localhost.
Escape character is '^]'.
set likehua likehua
+OK
get likehua
$7
likehua

 9.执行/usr/loal/bin/redis-server /etc/redis/redis.conf来启动redis服务器

make install命令执行完成后,会在/usr/local/bin目录下生成几个可执行文件,分别是redis-server、redis-cli、
redis-benchmark、redis-check-aof 、redis-check-dump,它们的作用如下:

   4、使用redis-benchmark对redis可以进行简单的性能测试。

[root@ecs-3c46 redis]# /usr/loal/bin/redis-server /etc/redis/redis.conf
-bash: /usr/loal/bin/redis-server: No such file or directory
[root@ecs-3c46 redis]# /usr/local/bin/redis-server /etc/redis/redis.conf
73449:M 13 May 10:56:00.839 * Increased maximum number of open files to 10032 (it was originally set to 1024).
                _._                                                  
           _.-``__ ''-._                                             
      _.-``    `.  `_.  ''-._           Redis 3.0.7 (00000000/0) 64 bit
  .-`` .-```.  ```\/    _.,_ ''-._                                   
 (    '      ,       .-`  | `,    )     Running in standalone mode
 |`-._`-...-` __...-.``-._|'` _.-'|     Port: 6379
 |    `-._   `._    /     _.-'    |     PID: 73449
  `-._    `-._  `-./  _.-'    _.-'                                   
 |`-._`-._    `-.__.-'    _.-'_.-'|                                  
 |    `-._`-._        _.-'_.-'    |           http://redis.io        
  `-._    `-._`-.__.-'_.-'    _.-'                                   
 |`-._`-._    `-.__.-'    _.-'_.-'|                                  
 |    `-._`-._        _.-'_.-'    |                                  
  `-._    `-._`-.__.-'_.-'    _.-'                                   
      `-._    `-.__.-'    _.-'                                       
          `-._        _.-'                                           
              `-.__.-'                                               
redis-server:Redis服务器的daemon启动程序

redis-cli:Redis命令行操作工具。也可以用telnet根据其纯文本协议来操作

redis-benchmark:Redis性能测试工具,测试Redis在当前系统下的读写性能

redis-check-aof:数据修复

redis-check-dump:检查导出工具

  

 10.再打开一个终端,切换至redis的安装目录执行redis-cli

3. 修改redis配置文件

图片 1图片 2

[root@ecs-3c46 bin]# redis-cli
127.0.0.1:6379> keys *
(empty list or set)
127.0.0.1:6379> 
a)[root@winner 桌面]# cd /etc

b) [root@winner etc]# vi redis.conf

c) 修改daemonize no改成yes。
  1 [likehua@localhost src]$ ./redis-benchmark -h localhost -p 6379 -c 1000 -n 100000
  2 ====== PING_INLINE ======
  3   100000 requests completed in 2.03 seconds
  4   1000 parallel clients
  5   3 bytes payload
  6   keep alive: 1
  7 
  8 0.00% <= 8 milliseconds
  9 0.04% <= 9 milliseconds
 10 66.42% <= 10 milliseconds
 11 88.10% <= 11 milliseconds
 12 91.29% <= 12 milliseconds
 13 93.57% <= 13 milliseconds
 14 96.30% <= 14 milliseconds
 15 98.13% <= 15 milliseconds
 16 98.78% <= 16 milliseconds
 17 99.37% <= 17 milliseconds
 18 99.77% <= 18 milliseconds
 19 99.93% <= 19 milliseconds
 20 99.97% <= 20 milliseconds
 21 100.00% <= 20 milliseconds
 22 49333.99 requests per second
 23 
 24 ====== PING_BULK ======
 25   100000 requests completed in 1.98 seconds
 26   1000 parallel clients
 27   3 bytes payload
 28   keep alive: 1
 29 
 30 0.00% <= 6 milliseconds
 31 0.01% <= 7 milliseconds
 32 0.15% <= 8 milliseconds
 33 15.79% <= 9 milliseconds
 34 58.19% <= 10 milliseconds
 35 92.03% <= 11 milliseconds
 36 96.30% <= 12 milliseconds
 37 98.24% <= 13 milliseconds
 38 98.90% <= 14 milliseconds
 39 99.30% <= 15 milliseconds
 40 99.63% <= 16 milliseconds
 41 99.99% <= 17 milliseconds
 42 100.00% <= 17 milliseconds
 43 50581.69 requests per second
 44 
 45 ====== SET ======
 46   100000 requests completed in 2.00 seconds
 47   1000 parallel clients
 48   3 bytes payload
 49   keep alive: 1
 50 
 51 0.00% <= 7 milliseconds
 52 0.24% <= 8 milliseconds
 53 6.78% <= 9 milliseconds
 54 62.14% <= 10 milliseconds
 55 88.33% <= 11 milliseconds
 56 93.36% <= 12 milliseconds
 57 96.28% <= 13 milliseconds
 58 97.19% <= 14 milliseconds
 59 98.11% <= 15 milliseconds
 60 98.58% <= 16 milliseconds
 61 98.91% <= 17 milliseconds
 62 99.49% <= 18 milliseconds
 63 99.84% <= 19 milliseconds
 64 100.00% <= 19 milliseconds
 65 49900.20 requests per second
 66 
 67 ====== GET ======
 68   100000 requests completed in 1.97 seconds
 69   1000 parallel clients
 70   3 bytes payload
 71   keep alive: 1
 72 
 73 0.00% <= 5 milliseconds
 74 0.01% <= 6 milliseconds
 75 0.24% <= 7 milliseconds
 76 9.30% <= 8 milliseconds
 77 35.68% <= 9 milliseconds
 78 53.22% <= 10 milliseconds
 79 80.98% <= 11 milliseconds
 80 95.27% <= 12 milliseconds
 81 97.05% <= 13 milliseconds
 82 98.47% <= 14 milliseconds
 83 99.40% <= 15 milliseconds
 84 99.76% <= 16 milliseconds
 85 99.94% <= 17 milliseconds
 86 100.00% <= 17 milliseconds
 87 50813.01 requests per second
 88 
 89 ====== INCR ======
 90   100000 requests completed in 2.01 seconds
 91   1000 parallel clients
 92   3 bytes payload
 93   keep alive: 1
 94 
 95 0.00% <= 6 milliseconds
 96 0.03% <= 7 milliseconds
 97 0.26% <= 8 milliseconds
 98 10.85% <= 9 milliseconds
 99 51.33% <= 10 milliseconds
100 86.53% <= 11 milliseconds
101 91.05% <= 12 milliseconds
102 93.84% <= 13 milliseconds
103 97.30% <= 14 milliseconds
104 99.09% <= 15 milliseconds
105 99.78% <= 16 milliseconds
106 99.93% <= 17 milliseconds
107 100.00% <= 17 milliseconds
108 49825.61 requests per second
109 
110 ====== LPUSH ======
111   100000 requests completed in 1.98 seconds
112   1000 parallel clients
113   3 bytes payload
114   keep alive: 1
115 
116 0.00% <= 6 milliseconds
117 0.77% <= 7 milliseconds
118 2.36% <= 8 milliseconds
119 11.40% <= 9 milliseconds
120 53.46% <= 10 milliseconds
121 90.92% <= 11 milliseconds
122 96.49% <= 12 milliseconds
123 98.51% <= 13 milliseconds
124 99.33% <= 14 milliseconds
125 99.82% <= 15 milliseconds
126 99.91% <= 16 milliseconds
127 100.00% <= 17 milliseconds
128 100.00% <= 17 milliseconds
129 50479.56 requests per second
130 
131 ====== LPOP ======
132   100000 requests completed in 1.97 seconds
133   1000 parallel clients
134   3 bytes payload
135   keep alive: 1
136 
137 0.00% <= 6 milliseconds
138 1.08% <= 7 milliseconds
139 8.16% <= 8 milliseconds
140 22.76% <= 9 milliseconds
141 54.23% <= 10 milliseconds
142 86.55% <= 11 milliseconds
143 96.52% <= 12 milliseconds
144 98.67% <= 13 milliseconds
145 99.56% <= 14 milliseconds
146 99.83% <= 15 milliseconds
147 99.92% <= 16 milliseconds
148 100.00% <= 16 milliseconds
149 50735.67 requests per second
150 
151 ====== SADD ======
152   100000 requests completed in 2.01 seconds
153   1000 parallel clients
154   3 bytes payload
155   keep alive: 1
156 
157 0.00% <= 6 milliseconds
158 0.00% <= 7 milliseconds
159 0.20% <= 8 milliseconds
160 3.06% <= 9 milliseconds
161 74.43% <= 10 milliseconds
162 91.78% <= 11 milliseconds
163 95.16% <= 12 milliseconds
164 96.61% <= 13 milliseconds
165 97.22% <= 14 milliseconds
166 98.35% <= 15 milliseconds
167 99.45% <= 16 milliseconds
168 100.00% <= 16 milliseconds
169 49751.24 requests per second
170 
171 ====== SPOP ======
172   100000 requests completed in 1.98 seconds
173   1000 parallel clients
174   3 bytes payload
175   keep alive: 1
176 
177 0.00% <= 6 milliseconds
178 0.25% <= 7 milliseconds
179 9.22% <= 8 milliseconds
180 27.89% <= 9 milliseconds
181 51.53% <= 10 milliseconds
182 83.58% <= 11 milliseconds
183 95.62% <= 12 milliseconds
184 98.06% <= 13 milliseconds
185 99.22% <= 14 milliseconds
186 99.83% <= 15 milliseconds
187 99.86% <= 16 milliseconds
188 99.90% <= 17 milliseconds
189 99.93% <= 18 milliseconds
190 99.97% <= 19 milliseconds
191 100.00% <= 19 milliseconds
192 50530.57 requests per second
193 
194 ====== LPUSH (needed to benchmark LRANGE) ======
195   100000 requests completed in 2.01 seconds
196   1000 parallel clients
197   3 bytes payload
198   keep alive: 1
199 
200 0.00% <= 6 milliseconds
201 0.08% <= 7 milliseconds
202 0.32% <= 8 milliseconds
203 5.15% <= 9 milliseconds
204 51.92% <= 10 milliseconds
205 91.54% <= 11 milliseconds
206 94.53% <= 12 milliseconds
207 96.95% <= 13 milliseconds
208 98.08% <= 14 milliseconds
209 98.76% <= 15 milliseconds
210 99.68% <= 16 milliseconds
211 100.00% <= 16 milliseconds
212 49652.43 requests per second
213 
214 ====== LRANGE_100 (first 100 elements) ======
215   100000 requests completed in 4.00 seconds
216   1000 parallel clients
217   3 bytes payload
218   keep alive: 1
219 
220 0.00% <= 14 milliseconds
221 4.44% <= 15 milliseconds
222 23.32% <= 16 milliseconds
223 26.30% <= 17 milliseconds
224 27.43% <= 18 milliseconds
225 28.36% <= 19 milliseconds
226 28.98% <= 20 milliseconds
227 32.42% <= 21 milliseconds
228 74.49% <= 22 milliseconds
229 89.15% <= 23 milliseconds
230 95.46% <= 24 milliseconds
231 95.91% <= 25 milliseconds
232 96.45% <= 26 milliseconds
233 97.53% <= 27 milliseconds
234 98.42% <= 28 milliseconds
235 98.79% <= 29 milliseconds
236 98.95% <= 30 milliseconds
237 99.15% <= 31 milliseconds
238 99.30% <= 32 milliseconds
239 99.42% <= 33 milliseconds
240 99.53% <= 34 milliseconds
241 99.60% <= 35 milliseconds
242 99.67% <= 36 milliseconds
243 99.77% <= 37 milliseconds
244 99.94% <= 38 milliseconds
245 100.00% <= 38 milliseconds
246 25006.25 requests per second
247 
248 ====== LRANGE_300 (first 300 elements) ======
249   100000 requests completed in 6.69 seconds
250   1000 parallel clients
251   3 bytes payload
252   keep alive: 1
253 
254 0.00% <= 16 milliseconds
255 0.01% <= 17 milliseconds
256 0.04% <= 18 milliseconds
257 0.08% <= 19 milliseconds
258 0.11% <= 20 milliseconds
259 0.15% <= 21 milliseconds
260 0.18% <= 22 milliseconds
261 0.22% <= 23 milliseconds
262 0.24% <= 24 milliseconds
263 0.26% <= 25 milliseconds
264 0.29% <= 26 milliseconds
265 2.09% <= 27 milliseconds
266 8.86% <= 28 milliseconds
267 21.91% <= 29 milliseconds
268 32.42% <= 30 milliseconds
269 47.12% <= 31 milliseconds
270 57.70% <= 32 milliseconds
271 64.38% <= 33 milliseconds
272 68.73% <= 34 milliseconds
273 71.52% <= 35 milliseconds
274 73.66% <= 36 milliseconds
275 75.44% <= 37 milliseconds
276 77.48% <= 38 milliseconds
277 79.79% <= 39 milliseconds
278 81.49% <= 40 milliseconds
279 83.05% <= 41 milliseconds
280 84.96% <= 42 milliseconds
281 86.70% <= 43 milliseconds
282 88.68% <= 44 milliseconds
283 93.08% <= 45 milliseconds
284 95.99% <= 46 milliseconds
285 99.41% <= 47 milliseconds
286 99.47% <= 48 milliseconds
287 99.54% <= 49 milliseconds
288 99.59% <= 50 milliseconds
289 99.65% <= 51 milliseconds
290 99.72% <= 52 milliseconds
291 99.78% <= 53 milliseconds
292 99.84% <= 54 milliseconds
293 99.88% <= 55 milliseconds
294 99.90% <= 56 milliseconds
295 99.93% <= 57 milliseconds
296 99.96% <= 58 milliseconds
297 99.99% <= 59 milliseconds
298 100.00% <= 59 milliseconds
299 14949.92 requests per second
300 
301 ====== LRANGE_500 (first 450 elements) ======
302   100000 requests completed in 8.71 seconds
303   1000 parallel clients
304   3 bytes payload
305   keep alive: 1
306 
307 0.00% <= 20 milliseconds
308 0.02% <= 21 milliseconds
309 0.07% <= 22 milliseconds
310 0.10% <= 23 milliseconds
311 0.13% <= 24 milliseconds
312 0.16% <= 25 milliseconds
313 0.17% <= 26 milliseconds
314 0.18% <= 27 milliseconds
315 0.20% <= 28 milliseconds
316 0.21% <= 29 milliseconds
317 0.22% <= 30 milliseconds
318 0.23% <= 31 milliseconds
319 0.26% <= 32 milliseconds
320 0.34% <= 33 milliseconds
321 0.63% <= 34 milliseconds
322 3.99% <= 35 milliseconds
323 7.57% <= 36 milliseconds
324 10.77% <= 37 milliseconds
325 13.87% <= 38 milliseconds
326 16.86% <= 39 milliseconds
327 24.72% <= 40 milliseconds
328 40.82% <= 41 milliseconds
329 49.31% <= 42 milliseconds
330 54.46% <= 43 milliseconds
331 60.03% <= 44 milliseconds
332 65.25% <= 45 milliseconds
333 70.38% <= 46 milliseconds
334 74.43% <= 47 milliseconds
335 78.07% <= 48 milliseconds
336 81.36% <= 49 milliseconds
337 84.61% <= 50 milliseconds
338 87.36% <= 51 milliseconds
339 89.99% <= 52 milliseconds
340 92.09% <= 53 milliseconds
341 94.16% <= 54 milliseconds
342 95.79% <= 55 milliseconds
343 96.93% <= 56 milliseconds
344 97.84% <= 57 milliseconds
345 98.52% <= 58 milliseconds
346 98.91% <= 59 milliseconds
347 99.26% <= 60 milliseconds
348 99.47% <= 61 milliseconds
349 99.51% <= 62 milliseconds
350 99.53% <= 63 milliseconds
351 99.55% <= 64 milliseconds
352 99.57% <= 65 milliseconds
353 99.61% <= 66 milliseconds
354 99.65% <= 67 milliseconds
355 99.69% <= 68 milliseconds
356 99.73% <= 69 milliseconds
357 99.78% <= 70 milliseconds
358 99.83% <= 71 milliseconds
359 99.86% <= 72 milliseconds
360 99.89% <= 73 milliseconds
361 99.91% <= 74 milliseconds
362 99.93% <= 75 milliseconds
363 99.95% <= 76 milliseconds
364 99.96% <= 77 milliseconds
365 99.98% <= 78 milliseconds
366 100.00% <= 78 milliseconds
367 11479.74 requests per second
368 
369 ====== LRANGE_600 (first 600 elements) ======
370   100000 requests completed in 11.03 seconds
371   1000 parallel clients
372   3 bytes payload
373   keep alive: 1
374 
375 0.00% <= 19 milliseconds
376 0.01% <= 20 milliseconds
377 0.03% <= 21 milliseconds
378 0.04% <= 22 milliseconds
379 0.05% <= 23 milliseconds
380 0.07% <= 24 milliseconds
381 0.08% <= 25 milliseconds
382 0.09% <= 26 milliseconds
383 0.10% <= 27 milliseconds
384 0.12% <= 28 milliseconds
385 0.12% <= 29 milliseconds
386 0.14% <= 30 milliseconds
387 0.16% <= 31 milliseconds
388 0.20% <= 32 milliseconds
389 0.23% <= 33 milliseconds
390 0.27% <= 34 milliseconds
391 0.29% <= 35 milliseconds
392 0.32% <= 36 milliseconds
393 0.36% <= 37 milliseconds
394 0.39% <= 38 milliseconds
395 0.43% <= 39 milliseconds
396 0.47% <= 40 milliseconds
397 0.50% <= 41 milliseconds
398 0.53% <= 42 milliseconds
399 0.58% <= 43 milliseconds
400 0.74% <= 44 milliseconds
401 1.40% <= 45 milliseconds
402 4.51% <= 46 milliseconds
403 8.98% <= 47 milliseconds
404 13.34% <= 48 milliseconds
405 18.11% <= 49 milliseconds
406 23.27% <= 50 milliseconds
407 29.19% <= 51 milliseconds
408 34.92% <= 52 milliseconds
409 41.34% <= 53 milliseconds
410 48.28% <= 54 milliseconds
411 55.34% <= 55 milliseconds
412 62.15% <= 56 milliseconds
413 67.49% <= 57 milliseconds
414 71.73% <= 58 milliseconds
415 75.33% <= 59 milliseconds
416 78.47% <= 60 milliseconds
417 81.46% <= 61 milliseconds
418 84.14% <= 62 milliseconds
419 86.82% <= 63 milliseconds
420 89.05% <= 64 milliseconds
421 91.05% <= 65 milliseconds
422 93.09% <= 66 milliseconds
423 94.56% <= 67 milliseconds
424 95.60% <= 68 milliseconds
425 96.47% <= 69 milliseconds
426 97.07% <= 70 milliseconds
427 97.55% <= 71 milliseconds
428 97.98% <= 72 milliseconds
429 98.32% <= 73 milliseconds
430 98.57% <= 74 milliseconds
431 98.68% <= 75 milliseconds
432 98.82% <= 76 milliseconds
433 98.91% <= 77 milliseconds
434 99.02% <= 78 milliseconds
435 99.04% <= 79 milliseconds
436 99.05% <= 80 milliseconds
437 99.07% <= 81 milliseconds
438 99.09% <= 82 milliseconds
439 99.10% <= 83 milliseconds
440 99.10% <= 84 milliseconds
441 99.11% <= 85 milliseconds
442 99.12% <= 86 milliseconds
443 99.13% <= 87 milliseconds
444 99.14% <= 88 milliseconds
445 99.16% <= 89 milliseconds
446 99.17% <= 90 milliseconds
447 99.18% <= 91 milliseconds
448 99.20% <= 92 milliseconds
449 99.21% <= 93 milliseconds
450 99.23% <= 94 milliseconds
451 99.25% <= 95 milliseconds
452 99.27% <= 96 milliseconds
453 99.29% <= 97 milliseconds
454 99.30% <= 98 milliseconds
455 99.33% <= 99 milliseconds
456 99.36% <= 100 milliseconds
457 99.39% <= 101 milliseconds
458 99.41% <= 102 milliseconds
459 99.43% <= 103 milliseconds
460 99.46% <= 104 milliseconds
461 99.49% <= 105 milliseconds
462 99.51% <= 106 milliseconds
463 99.54% <= 107 milliseconds
464 99.56% <= 108 milliseconds
465 99.58% <= 109 milliseconds
466 99.61% <= 110 milliseconds
467 99.64% <= 111 milliseconds
468 99.66% <= 112 milliseconds
469 99.68% <= 113 milliseconds
470 99.71% <= 114 milliseconds
471 99.73% <= 115 milliseconds
472 99.76% <= 116 milliseconds
473 99.78% <= 117 milliseconds
474 99.79% <= 118 milliseconds
475 99.80% <= 119 milliseconds
476 99.81% <= 120 milliseconds
477 99.82% <= 121 milliseconds
478 99.83% <= 122 milliseconds
479 99.85% <= 123 milliseconds
480 99.86% <= 124 milliseconds
481 99.87% <= 125 milliseconds
482 99.88% <= 126 milliseconds
483 99.90% <= 127 milliseconds
484 99.92% <= 128 milliseconds
485 99.93% <= 129 milliseconds
486 99.94% <= 130 milliseconds
487 99.94% <= 131 milliseconds
488 99.94% <= 132 milliseconds
489 99.95% <= 133 milliseconds
490 99.95% <= 134 milliseconds
491 99.95% <= 135 milliseconds
492 99.95% <= 136 milliseconds
493 99.95% <= 137 milliseconds
494 99.96% <= 138 milliseconds
495 99.96% <= 139 milliseconds
496 99.96% <= 140 milliseconds
497 99.96% <= 141 milliseconds
498 99.96% <= 142 milliseconds
499 99.97% <= 143 milliseconds
500 99.97% <= 144 milliseconds
501 99.97% <= 145 milliseconds
502 99.99% <= 146 milliseconds
503 100.00% <= 146 milliseconds
504 9067.83 requests per second
505 
506 ====== MSET (10 keys) ======
507   100000 requests completed in 2.31 seconds
508   1000 parallel clients
509   3 bytes payload
510   keep alive: 1
511 
512 0.00% <= 9 milliseconds
513 0.16% <= 10 milliseconds
514 0.33% <= 11 milliseconds
515 0.58% <= 12 milliseconds
516 1.01% <= 13 milliseconds
517 1.33% <= 14 milliseconds
518 2.03% <= 15 milliseconds
519 2.50% <= 16 milliseconds
520 3.43% <= 17 milliseconds
521 4.79% <= 18 milliseconds
522 6.51% <= 19 milliseconds
523 20.35% <= 20 milliseconds
524 58.54% <= 21 milliseconds
525 69.83% <= 22 milliseconds
526 76.45% <= 23 milliseconds
527 80.71% <= 24 milliseconds
528 84.42% <= 25 milliseconds
529 88.26% <= 26 milliseconds
530 91.26% <= 27 milliseconds
531 92.21% <= 28 milliseconds
532 93.89% <= 29 milliseconds
533 95.65% <= 30 milliseconds
534 96.55% <= 31 milliseconds
535 96.96% <= 32 milliseconds
536 97.36% <= 33 milliseconds
537 97.61% <= 34 milliseconds
538 98.07% <= 35 milliseconds
539 98.18% <= 36 milliseconds
540 98.47% <= 37 milliseconds
541 98.84% <= 38 milliseconds
542 99.02% <= 39 milliseconds
543 99.45% <= 40 milliseconds
544 99.63% <= 41 milliseconds
545 99.83% <= 42 milliseconds
546 99.94% <= 47 milliseconds
547 99.97% <= 63 milliseconds
548 100.00% <= 63 milliseconds
549 43215.21 requests per second

 

参数介绍:

View Code

daemonize:是否以后台daemon方式运行

pidfile:pid文件位置

port:监听的端口号

timeout:请求超时时间

loglevel:log信息级别

logfile:log文件位置

databases:开启数据库的数量

save * *:保存快照的频率,第一个*表示多长时间,第三个*表示执行多少次写操作。在一定时间内执行一定数量的写操作时,自动保存快照。可设置多个条件。

rdbcompression:是否使用压缩

dbfilename:数据快照文件名(只是文件名,不包括目录)

dir:数据快照的保存目录(这个是目录)

appendonly:是否开启appendonlylog,开启的话每次写操作会记一条log,这会提高数据抗风险能力,但影响效率。

appendfsync:appendonlylog如何同步到磁盘(三个选项,分别是每次写都强制调用fsync、每秒启用一次fsync、不调用fsync等待系统自己同步)

  如果不知道怎么使用redis-benchmark就使用redis-benchmark
-help命令,它会告诉你它所有的本领!通过,上面的简单性能测试,你会发现redis简直是性能怪兽!这个数字可是在我的一台普通PC机器上测试的!貌似,比公司的数字大很多,具体原因以后分析。

设置开机自动启动服务

  

sudo chkconfig redis on

4. 启动redis

[root@winner etc]# cd /usr/local/bin
[root@winner bin]# ./redis-server /etc/redis.conf

5. 检查是否启动成功

[root@winner 桌面]# ps -ef | grep redis
root      6121     1  0 19:37 ?        00:00:02 ./redis-server *:6379         
root      6433  6422  0 19:58 pts/1    00:00:00 grep redis

6.客户端登录

[root@winner bin]# ./redis-cli -h 127.0.0.1 -p 6379
127.0.0.1:6379> 

配置防火墙打开对应的端口:

$vi /etc/sysconfig/iptables

-A INPUT -m state --state NEW -m tcp -p tcp --dport 6379 -j ACCEPT

重启防火墙

$service iptables restart

测试:

127.0.0.1:6379> set test "hello"
OK
127.0.0.1:6379> get test
"hello"

 关闭Redis:

[root@winner bin]# ./redis-cli -h 127.0.0.1 -p 6379 shutdown 

相关文章