redis安装

来源:互联网 发布:php namespace use 编辑:程序博客网 时间:2024/04/30 15:41

下载地址

http://redis.io/download

https://github.com/antirez/redis

安装编译

安装环境:sudo apt-get install make gcc

编译安装: sudo make MALLOC=libc

编译完后产生的工具(编译目录/src/)

redis-server:redis服务器的daemon程序

redis-cil:redis命令行工具(也可以使用telne纯文本协议操作)

redis-benchmark:redis性能测试工具,测试redis在你的系统及你的配置下的读写能力

redis-stat:redis状态检测工具,可以检测redis当前状态参数及延迟情况

redis-check-dump:redis dump数据文件的修复工具

redis-check-aof:redis aof日志文件修复工具

在install后会吧上面6个执行文件拷贝到/usr/local/bin下

配置文件修改

需要讲配置文件拷贝到/etc下(默认在安装目录下)

sudo cp redis.conf /etc/

配置文件相关参数:

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

pidfile:pid文件位置

port:监听端口号

timeout:客户端长时间无请求,将会被服务器关闭。

loglevel:log信息级别(debug,verbose,notice和warning默认为verbose)

logfile:log文件存储位置

databases:开启数据库的数量,使用select 库id方式切换各个数据库。

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

rdbcompression:是否使用压缩

dbfilename:数据快照文件名(只是文件名,不考扩目录)。默认为dump.rdb

dir:数据快照保存的目录

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

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

启动redis

直接启动:redis-server

指定配置文件的启动: redis-server /etc/redis.conf

启动的时候会有警告:

6948:M 03 Sep 10:58:19.469 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.第一个警告:The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.意思是:TCP  backlog设置值,511没有成功,因为 /proc/sys/net/core/somaxconn这个设置的是更小的128.临时解决方法:(即下次启动还需要修改此值)echo 511 > /proc/sys/net/core/somaxconn永久解决方法:(即以后启动还需要修改此值)将其写入/etc/rc.local文件中。baklog参数实际控制的是已经3次握手成功的还在accept queue的大小。[参考](http://blog.csdn.net/raintungli/article/details/37913765)6948:M 03 Sep 10:58:19.469 # Server initialized6948:M 03 Sep 10:58:19.469 # 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.意思是:overcommit_memory参数设置为0!在内存不足的情况下,后台程序save可能失败。建议在文件 /etc/sysctl.conf 中将overcommit_memory修改为1。临时解决方法:echo "vm.overcommit_memory=1" > /etc/sysctl.conf永久解决方法:将其写入/etc/sysctl.conf文件中。[参考](http://blog.csdn.net/whycold/article/details/21388455)6948:M 03 Sep 10:58:19.469 # WARNING you have Transparent Huge Pages (THP) support enabled in your kernel. This will create latency and memory usage issues with Redis. To fix this issue run the command 'echo never > /sys/kernel/mm/transparent_hugepage/enabled' as root, and add it to your /etc/rc.local in order to retain the setting after a reboot. Redis must be restarted after THP is disabled.意思是:你使用的是透明大页,可能导致redis延迟和内存使用问题。执行 echo never > /sys/kernel/mm/transparent_hugepage/enabled 修复该问题。临时解决方法:echo never > /sys/kernel/mm/transparent_hugepage/enabled。永久解决方法:将其写入/etc/rc.local文件中。[参考](http://www.cnblogs.com/kerrycode/archive/2015/07/23/4670931.html)
原创粉丝点击