Redis 是开源,BSD许可,高级的key-value存储系统,可以用来存储字符串,哈希结构,链表,集合,因此,常用来提供数据结构服务,相对于memcached它具有以下特点:
☞ redis可以用来做存储(storge)即redis的持久化”功能,而memccached是用来做缓存(cache)
☞ 存储的数据有”结构”,相对于memcached来说,存储的数据,只有1种类型--”字符串”, 而redis则可以存储字符串、链表、哈希结构、集合、有序集合。
一、 Redis下载安装
官方网站:redis.io
版本:Redis 3.2.1 is the latest stable version.
[root@centos ~] wget http://download.redis.io/releases/redis-3.2.1.tar.gz
[root@centos ~] tar xf redis-3.2.1.tar.gz
[root@centos ~] cd redis-3.2.1
[root@centos redis-3.2.1] make
[root@centos redis-3.2.1] make test
[root@centos redis-3.2.1] make PREFIX=/application/redis install
[root@centos redis-3.2.1] cp redis.conf /application/redis/
☞ Redis安装时不需要configure,直接make编译
☞ 编译成功后需执行make test检测有没有错误
☞ 执行make install时可指定软件安装位置PREFIX,注意PREFIX需要大写
☞ 安装完成需要拷贝redis配置文件至redis根目录下
二、 Redis目录文件介绍介绍
Redis安装成功后,目录结构非常简洁,在bin目录下共有以下文件:
redis-benchmark 性能测试工具
redis-check-aof aof日志文件检测工具(比如断电造成日志损坏,可以检测并修复)
redis-check-dump rbd快照文件检测工具,效果类上
redis-cli 客户端
redis-server 服务端
三、启动Redis服务进程
Redis 服务进程的启动需要指定redis的服务端路径和配置文件路径:
[root@template redis]# ./bin/redis-server ./redis.conf 6367:M 18 Jul 15:51:44.117 * Increased maximum number of open files to 10032 (it was originally set to 1024). _._ _.-``__ ''-._ _.-`` `. `_. ''-._ Redis 3.2.1 (00000000/0) 64 bit .-`` .-```. ```\/ _.,_ ''-._ ( ' , .-` | `, ) Running in standalone mode |`-._`-...-` __...-.``-._|'` _.-'| Port: 6379 | `-._ `._ / _.-' | PID: 6367 `-._ `-._ `-./ _.-' _.-' |`-._`-._ `-.__.-' _.-'_.-'| | `-._`-._ _.-'_.-' | http://redis.io `-._ `-._`-.__.-'_.-' _.-' |`-._`-._ `-.__.-' _.-'_.-'| | `-._`-._ _.-'_.-' | `-._ `-._`-.__.-'_.-' _.-' `-._ `-.__.-' _.-' `-._ _.-' `-.__.-'
Redis默认是不以后台进程的方式启动的,因此启动后,终端界面会被占用,并且ctrl+c后redis会退出,要想让redis以台进程的形式运行,需修改配置文件的daemonize为yes
[root@template redis]# vi redis.conf ################################# GENERAL ##################################### # 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
四、 连接Redis
[root@centos ~]# /application/redis/bin/redis-cli [-p 6379] # 若是多实例或者端口不是6379,需要加-p指定端口号 127.0.0.1:6379>
也可将Redis的安装目录加入环境变量,
echo PATH=$PATH:/application/redis/bin>> /etc/profile
source /etc/profile