参考:http://redis.io/download#installationnode
1、安装必要的软件redis
yum -y install gcc automake autoconf libtool make服务器
2、下载redis:并发
$ wget http://download.redis.io/releases/redis-3.0.1.tar.gz $ tar xzf redis-3.0.1.tar.gz $ cd redis-3.0.1 $ make $ make test
node : 解压后 cd redis-3.0.1,而后可查看 README 文件,里面介绍了redis安装等相关内容;app
3、修改配置文件 dom
建立目录:工具
mkdir /home/data/redis/ 性能
mkdir /home/data/redis/data/ 测试
mkdir /home/data/redis/conf/ui
mkdir /home/data/redis/logs/
touch /home/data/redis/logs/redis.log
源码目录中有一个默认配置文件,复制到:
cp redis-3.0.1/redis.conf /home/data/redis/conf/
修改配置文件:
0、若是要让本机之外的服务器访问redis服务,要注释掉下来这一句
#bind 127.0.0.1
一、daemonize yes //能够后台运行
二、pidfile /home/data/redis/redis.pid
三、port 6379
四、logfile "/home/data/redis/logs/redis.log"
五、dir /home/data/redis/data //数据文件目录
六、注释掉如下,保证数据会当即写入磁盘
#save 900 1
#save 300 10
#save 60 10000
七、开启写入硬盘参数,使用操做命令能够被写入到硬盘,达到持 久化的目的
appendonly yes
若是对数据的准确性要求较高,还须要修改:
appendfsync always
这里配置的是写入命令到磁盘的策略,always表示写入到磁盘后才会返回到写入的客户端,
默认是 everysec ,即一秒写入一次到磁盘
八、最大使用内存,根据状况设置,单位bytes
# maxmemory <bytes>
# current 2G
maxmemory 2147483648
九、数据剔除策略,根据状况设置:
maxmemory-policy volatile-lru
可选的有:
#volatile-lru -> remove the key with an expire set using an LRU algorithm
# allkeys-lru -> remove any key according to the LRU algorithm
# volatile-random -> remove a random key with an expire set
# allkeys-random -> remove a random key, any key
# volatile-ttl -> remove the key with the nearest expire time (minor TTL)
# noeviction -> don't expire at all, just return an error on write operations
十、完整的配置文件在 http://my.oschina.net/u/1045177/blog/413676
十一、若是要配置密码认证,修改:
requirepass myRedis
链接客户端命令:
redis-3.0.1/src/redis-cli -h localhost -p 6379 -a myRedis
4、make install会将生成的可执行程序复制到/usr/local/bin目录中
主要包括:
/user/local/bin/redis-benchmark //Redis性能测试工具 参考:http://blog.csdn.net/jiangguilong2000/article/details/24143721 //redis-benchmark -h 127.0.0.1 -p 6379 -c 5000 -n 100000 //5000个并发链接,100000个请求,检测host为127.0.0.1 端口为6379的redis服务器性能 /user/local/bin/redis-cli //客户端工具 /user/local/bin/ redis-server //服务端
5、启动redis:
$ redis-server /home/data/redis/conf/redis.conf
能够设置成开机启动:
chmod +x /etc/rc.d/rc.local echo "redis-server /home/data/redis/conf/redis.conf">>/etc/rc.local
6、测试:
$ redis-3.0.1/src/redis-cli redis> set foo bar OK redis> get foo "bar"
7、中止redis
redis-3.0.1/src/redis-cli shutdown 或者 redis-3.0.1/src/redis-cli -h localhost -p 6379 shutdown 或者 redis-cli -h localhost -p 16379 -a jcbzw315 shutdown