首页 > 代码库 > Linux下redis的安装

Linux下redis的安装

redis是当前比较热门的NOSQL数据库之一,它是一个key-value存储系统。和Memcached类似,但很大程度补偿了memcached的不足,它支持存储的value类型相对更多,包括string、list、set、zset和hash。这些数据类型都支持push/pop、add/remove及取交集并集和差集及更丰富的操作。在此基础上,redis支持各种不同方式的排序。Redis数据都是缓存在计算机内存中,并且会周期性的把更新的数据写入磁盘或者把修改操作写入追加的记录文件。

下面我们在CentOS上安装redis

下载源码,解压缩后编译源码。

[root@localhost temp]# wget http://download.redis.io/releases/redis-2.8.3.tar.gz

[root@localhost temp]# tar zxvf redis-2.8.3.tar.gz 

[root@localhost temp]# cd redis-2.8.3

[root@localhost redis-2.8.3]#make

注意,没有make install

安装目录是/usr/local/software/redis-2.8.3

1、查看安装目录下的文件

[root@localhost redis-2.8.3]# ll
total 108......
-rw-rw-r--. 1 root root  4401 Dec 11  2013 README
-rw-rw-r--. 1 root root 29593 Dec 11  2013 redis.conf
-rwxrwxr-x. 1 root root   271 Dec 11  2013 runtest
-rw-rw-r--. 1 root root  5661 Dec 11  2013 sentinel.conf
drwxrwxr-x. 2 root root  4096 Mar  5 13:27 src
drwxrwxr-x. 8 root root  4096 Dec 11  2013 tests
drwxrwxr-x. 2 root root  4096 Dec 11  2013 utils
redis.conf:redis的主配置文件,配置连接、密码、端口、是否持久化等的参数~

2.编译完成后,在src目录下,有几个可执行文件redis-server、redis-benchmark、redis-cli

[root@localhost redis-2.8.3]# cd src/
[root@localhost src]# ll
total 23856
-rw-rw-r--. 1 root root    9930 Dec 11  2013 adlist.c
.....
-rw-rw-r--. 1 root root    2274 Dec 11  2013 redisassert.h
-rwxr-xr-x. 1 root root 4170559 Mar  5 13:27 redis-benchmark
-rw-rw-r--. 1 root root   27418 Dec 11  2013 redis-benchmark.c
-rw-r--r--. 1 root root   60456 Mar  5 13:27 redis-benchmark.o
-rw-rw-r--. 1 root root  118700 Dec 11  2013 redis.c
-rwxr-xr-x. 1 root root   22193 Mar  5 13:27 redis-check-aof
-rw-rw-r--. 1 root root    6328 Dec 11  2013 redis-check-aof.c
-rw-r--r--. 1 root root   20688 Mar  5 13:27 redis-check-aof.o
-rwxr-xr-x. 1 root root   45427 Mar  5 13:27 redis-check-dump
-rw-rw-r--. 1 root root   22155 Dec 11  2013 redis-check-dump.c
-rw-r--r--. 1 root root   45432 Mar  5 13:27 redis-check-dump.o
-rwxr-xr-x. 1 root root 4243011 Mar  5 13:27 redis-cli
-rw-rw-r--. 1 root root   51412 Dec 11  2013 redis-cli.c
-rw-r--r--. 1 root root  144704 Mar  5 13:27 redis-cli.o
-rw-rw-r--. 1 root root   60143 Dec 11  2013 redis.h
-rw-r--r--. 1 root root  210400 Mar  5 13:27 redis.o
-rwxr-xr-x. 1 root root 5641122 Mar  5 13:27 redis-sentinel
-rwxr-xr-x. 1 root root 5641122 Mar  5 13:27 redis-server
-rw-rw-r--. 1 root root    2164 Mar  5 13:27 release.c
.....
-rw-r--r--. 1 root root   30176 Mar  5 13:27 zmalloc.o
[root@localhost src]# 

redis-server:Redis服务器的daemon启动程序。
redis-cli:Redis命令行操作工具。当然,你也可以用telnet根据其纯文本协议来操作。
redis-benchmark:Redis性能测试工具,测试Redis在你的系统及你的配置下的读写性能。

3.启动Redis服务。

1)执行./usr/redis/redis-2.8.13/src/redis-server

[root@localhost src]# ./redis-server ../redis.conf 
[34597] 05 Mar 13:39:43.338 * Max number of open files set to 10032
                _._                                                  
           _.-``__ ‘‘-._                                             
      _.-``    `.  `_.  ‘‘-._           Redis 2.8.3 (00000000/0) 64 bit
  .-`` .-```.  ```\/    _.,_ ‘‘-._                                   
 (    ‘      ,       .-`  | `,    )     Running in stand alone mode
 |`-._`-...-` __...-.``-._|‘` _.-‘|     Port: 6379
 |    `-._   `._    /     _.-‘    |     PID: 34597
  `-._    `-._  `-./  _.-‘    _.-‘                                   
 |`-._`-._    `-.__.-‘    _.-‘_.-‘|                                  
 |    `-._`-._        _.-‘_.-‘    |           http://redis.io        
  `-._    `-._`-.__.-‘_.-‘    _.-‘                                   
 |`-._`-._    `-.__.-‘    _.-‘_.-‘|                                  
 |    `-._`-._        _.-‘_.-‘    |                                  
  `-._    `-._`-.__.-‘_.-‘    _.-‘                                   
      `-._    `-.__.-‘    _.-‘                                       
          `-._        _.-‘                                           
              `-.__.-‘                                               

[34597] 05 Mar 13:39:43.346 # Server started, Redis version 2.8.3
[34597] 05 Mar 13:39:43.347 # 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. [34597] 05 Mar 13:39:43.347 * The server is now ready to accept connections on port 6379

2)查看进程

[root@localhost ~]# ps aux|grep redis
root      34597  0.0  0.7 137344  7640 pts/0    Sl+  13:39   0:00 ./redis-server *:6379       
root      34608  0.0  0.0 103308   860 pts/1    S+   13:41   0:00 grep redis

3)然后用客户端测试一下是否启动成功。

[root@localhost src]# ./redis-cli 
127.0.0.1:6379> set greet hello
OK
127.0.0.1:6379> get greet
"hello"
127.0.0.1:6379> 

注意,此时Redis服务不能在后台运行,Ctrl+C会结束Redis服务

需要配置Redis 服务在后台运行,略麻烦,我们就不配了

Linux下redis的安装