redis的源码安装

wget http://download.redis.io/redis-stable.tar.gz
tar -zxvf redis-stable.tar.gz
cd redis-stable
make
make test
make install

可能出现:

You need tcl 8.5 or newer in order to run the Redis test
执行
yum install tcl

make时可能会报如下错误:

zmalloc.o: In function `zmalloc_used_memory':
/root/redis-stable/src/zmalloc.c:: undefined reference to `__sync_add_and_fetch_4'
collect2: ld returned exit status
make[]: *** [redis-server] Error
make[]: Leaving directory `/root/redis-stable/src'
make: *** [all] Error

解决办法:
编辑src/.make-settings里的OPT,改为OPT=-O2 -march=i686。

You need tcl 8.5 or newer in order to run the Redis test
make: *** [test] Error

redis命令介绍

Redis 由四个可执行文件:redis-benchmark、redis-cli、redis-server、redis-stat 这四个文件,加上一个redis.conf就构成了整个redis的最终可用包。它们的作用如下:

redis-server:Redis服务器的daemon启动程序
redis-cli:Redis命令行操作工具。当然,你也可以用telnet根据其纯文本协议来操作
redis-benchmark:Redis性能测试工具,测试Redis在你的系统及你的配置下的读写性能
redis-stat:Redis状态检测工具,可以检测Redis当前状态参数及延迟状况
现在就可以启动redis了,redis只有一个启动参数,就是他的配置文件路径。

启动redis

复制源码包里的redis.conf到/etc
# cd redis-stable
# cp redis.conf /etc/redis.conf

编辑/etc/redis.conf ,修改
daemaon no 为daemaon yes ,以守护进程方式启动进程。

# redis-server /etc/redis.conf

关闭redis
# redis-cli shutdown //关闭所有
关闭某个端口上的redis
# redis-cli -p 6397 shutdown //关闭6397端口的redis
说明:关闭以后缓存数据会自动dump到硬盘上,硬盘地址见redis.conf中的dbfilename dump.rdb

redis配置

注意,默认复制过去的redis.conf文件的daemonize参数为no,所以redis不会在后台运行,这时要测试,我们需要重新开一个终
端。修改为yes则为后台运行redis。另外配置文件中规定了pid文件,log文件和数据文件的地址,如果有需要先修改,默认log信息定向到
stdout.

下面是redis.conf的主要配置参数的意义:

daemonize:是否以后台daemon方式运行
pidfile:pid文件位置
port:监听的端口号
timeout:请求超时时间
loglevel:log信息级别
logfile:log文件位置
databases:开启数据库的数量
save * *:保存快照的频率,第一个*表示多长时间,第三个*表示执行多少次写操作。在一定时间内执行一定数量的写操作时,自动保存快照。可设置多个条件。
rdbcompression:是否使用压缩
dbfilename:数据快照文件名(只是文件名,不包括目录)
dir:数据快照的保存目录(这个是目录)
appendonly:是否开启appendonlylog,开启的话每次写操作会记一条log,这会提高数据抗风险能力,但影响效率。
appendfsync:appendonlylog如何同步到磁盘(三个选项,分别是每次写都强制调用fsync、每秒启用一次fsync、不调用fsync等待系统自己同步)
这时你可以打开一个终端进行测试了,配置文件中默认的监听端口是6379

redis开机自动启动

用这个脚本管理之前,需要先配置下面的内核参数,否则Redis脚本在重启或停止redis时,将会报错,并且不能自动在停止服务前同步数据到磁盘上:

# vi /etc/sysctl.conf

vm.overcommit_memory = 1

然后应用生效:

# sysctl –p

建立redis启动脚本:

# vim /etc/init.d/redis

#!/bin/bash
#
# Init file for redis
#
# chkconfig: -
# description: redis daemon
#
# processname: redis
# config: /etc/redis.conf
# pidfile: /var/run/redis.pid
source /etc/init.d/functions
#BIN="/usr/local/bin"
BIN="/usr/local/bin"
CONFIG="/etc/redis.conf"
PIDFILE="/var/run/redis.pid"
### Read configuration
[ -r "$SYSCONFIG" ] && source "$SYSCONFIG"
RETVAL=
prog="redis-server"
desc="Redis Server"
start() {
if [ -e $PIDFILE ];then
echo "$desc already running...."
exit
fi
echo -n $"Starting $desc: "
daemon $BIN/$prog $CONFIG
RETVAL=$?
echo
[ $RETVAL -eq ] && touch /var/lock/subsys/$prog
return $RETVAL
}
stop() {
echo -n $"Stop $desc: "
killproc $prog
RETVAL=$?
echo
[ $RETVAL -eq ] && rm -f /var/lock/subsys/$prog $PIDFILE
return $RETVAL
}
restart() {
stop
start
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
restart
;;
condrestart)
[ -e /var/lock/subsys/$prog ] && restart
RETVAL=$?
;;
status)
status $prog
RETVAL=$?
;;
*)
echo $"Usage: $0 {start|stop|restart|condrestart|status}"
RETVAL=
esac
exit $RETVAL

然后增加服务并开机自启动:

# chmod  /etc/init.d/redis
# chkconfig --add redis
# chkconfig --level redis on
# chkconfig --list redis

redis php扩展安装

wget https://github.com/nicolasff/phpredis/zipball/master -O php-redis.zip
unzip php-redis.zip
cd nicolasff-phpredis-2d0f29b/
/usr/local/php/bin/phpize
./configure --with-php-config=/usr/local/php/bin/php-config
make && make install

完成后redis.so被安装到
/usr/local/php/lib/php/extensions/no-debug-non-zts-20100525/

vi /usr/local/php/lib/php.ini

添加
extension=redis.so

重启php-fpm即可。

configure时可能会遇到,添加--with-php-config参数可以解决。

configure: error: Cannot find php-config. Please use --with-php-config=PATH

./configure --with-php-config=/usr/local/php/bin/php-config

最新文章

  1. IOS开发基础知识--碎片37
  2. Oracle表的几种连接方式
  3. Ubuntu 16.04 64位安装insight 6.8
  4. ASP.NET中控件命名规则
  5. 关于MyBatis mapper的insert, update, delete返回值
  6. mysql批量执行sql文件
  7. js将数组元素随机排序的方法
  8. Android开发5大布局方式详解
  9. python urllib和urllib3包使用
  10. 《java入门第一季》之面向对象(代码块一网打尽)
  11. RabbitMQ 入门【精+转】
  12. Linux进程管理专题
  13. Spring mybatis源码篇章-MapperScannerConfigurer关联dao接口
  14. shell编程之函数
  15. STM32F4 HAL Composite USB Device Example : CDC + MSC
  16. 主攻ASP.NET MVC4.0之重生:Asp.Net MVC WebApi OData
  17. 74HC125 74HCT125 74LV125 74LVC125
  18. StrongLoop
  19. Game 游戏开发
  20. java的IO流之字符流

热门文章

  1. Delphi 滚动条的使用
  2. ArrayList,LinkedList,Vector集合的认识
  3. [NOIP模拟13]题解
  4. springboot入门级笔记
  5. IIS身份验证和文件操作权限(二、匿名身份验证)
  6. Linux关闭端口
  7. spring 中 isolation 和 propagation 详解
  8. 错误 1 error C4996: 'getcwd': The POSIX name for this item is deprecated. Instead, use the ISO C++ conformant name: _getcwd. See online help for details.
  9. 【AI图像识别一】人脸识别测试探索
  10. 随笔-ansible-6