Linux 下编译 redis 和 phpredis

来源:互联网 发布:淘宝如何设置运费险 编辑:程序博客网 时间:2024/05/29 14:44

1、准备工作

下载软件:http://pan.baidu.com/share/link?shareid=319813&uk=1997289381

操作系统:CentOS 5.5

redis 版本:redis-2.6.9

2、编译安装

[plain] view plaincopy
  1. tar zxvf redis-2.6.9.tar.gz //解压  

[plain] view plaincopy
  1. cd redis-2.6.9  

[plain] view plaincopy
  1. make   //编译  

如果出现如下错误:

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

解决方法:

[plain] view plaincopy
  1. make CFLAGS="-march=i686"  

当看见“Hint: To run 'make test' is a good idea ;)” 说明编译成功。

[plain] view plaincopy
  1. make install    //安装  

说明:其实 make install 就是:

cp -p redis-server /usr/local/bin

cp -p redis-benchmark /usr/local/bin

cp -p redis-cli /usr/local/bin

cp -p redis-check-dump /usr/local/bin

cp -p redis-check-aof /usr/local/bin

这样,redis 就安装成功了。

接下来就是启动Redis了, 上面编译后生成的那些可执行文件拷贝到了/usr/local/bin目录下面, 他们的作用分别是:

redis-server:Redis服务器的daemon启动程序

redis-cli:Redis命令行操作工具。当然,你也可以用 telnet 根据其纯文本协议来操作

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

启动 Redis 进程只需要执行这个 /usr/local/bin/redis-server /path-to/redis.conf

启动的时候后面要跟上 redis 的配置文件, 这样Redis就顺利启动了.

3、启动 redis 会出现的问题

Warning: 32 bit instance detected but no memory limit set. Setting 3 GB maxmemory limit with 'noeviction' policy now.

解决方法:修改配置文件 redis.conf  将 maxmemory 设置为 maxmemory 1024000000 #分配256M内存

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.

解决方法:警告:过量使用内存设置为0!在低内存环境下,后台保存可能失败。为了修正这个问题,请在/etc/sysctl.conf 添加一项 'vm.overcommit_memory = 1' ,然后重启(或者运行命令'sysctl vm.overcommit_memory=1' )使其生效。

当启动的时候没有任何信息,表明启动成功。也可以使用 "netstat -tnl" 查看6379端口是否启动。

4、开启和关闭 redis

redis-server /usr/local/redis-2.6.9/redis.conf 开启,注:需要指定 redis 的配置文件

pkill redis-server 停止 redis

redis-cli shutdown 停止 redis

5、redis.conf 的参数信息

http://kgd1120.iteye.com/blog/1221002

6、编译 phpredis

unzip phpredis-master.zip

cd phpredis-master

/usr/local/php/bin/phpize
./configure –with-php-config=/usr/local/php/bin/php-config
make && make install

修改 php.ini 文件。加载 redis.so 模块,重启 Apache !


两篇不错的文章:

http://blog.csdn.net/zdrjlamp/article/details/7846028

http://skirt.sinaapp.com/?p=114

转自:http://blog.csdn.net/liruxing1715/article/details/8556671
0 0
原创粉丝点击