Linux下編譯redis和phpredis的方法
本文講述了Linux下編譯redis和phpredis的方法。分享給大家供大家參考,具體如下:
1、準(zhǔn)備工作
下載軟件:本站下載地址。
操作系統(tǒng):CentOS 5.5
redis 版本:redis-2.6.9
2、編譯安裝
tar zxvf redis-2.6.9.tar.gz //解壓 cd redis-2.6.9 make //編譯
如果出現(xiàn)如下錯(cuò)誤:
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
解決方法:
make CFLAGS="-march=i686"
當(dāng)看見“Hint: To run 'make test' is a good idea ;)” 說明編譯成功。
make install //安裝
說明:其實(shí) 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 就安裝成功了。
接下來就是啟動(dòng)Redis了, 上面編譯后生成的那些可執(zhí)行文件拷貝到了/usr/local/bin目錄下面, 他們的作用分別是:
redis-server:Redis服務(wù)器的daemon啟動(dòng)程序
redis-cli:Redis命令行操作工具。當(dāng)然,你也可以用 telnet 根據(jù)其純文本協(xié)議來操作
redis-benchmark:Redis性能測(cè)試工具,測(cè)試Redis在你的系統(tǒng)及你的配置下的讀寫性能
啟動(dòng) Redis 進(jìn)程只需要執(zhí)行這個(gè) /usr/local/bin/redis-server /path-to/redis.conf
啟動(dòng)的時(shí)候后面要跟上 redis 的配置文件, 這樣Redis就順利啟動(dòng)了.
3、啟動(dòng) redis 會(huì)出現(xiàn)的問題
Warning: 32 bit instance detected but no memory limit set. Setting 3 GB maxmemory limit with 'noeviction' policy now.
解決方法:修改配置文件 redis.conf 將 maxmemory 設(shè)置為 maxmemory 1024000000 #分配256M內(nèi)存
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.
解決方法:警告:過量使用內(nèi)存設(shè)置為0!在低內(nèi)存環(huán)境下,后臺(tái)保存可能失敗。為了修正這個(gè)問題,請(qǐng)?jiān)?etc/sysctl.conf 添加一項(xiàng) 'vm.overcommit_memory = 1' ,然后重啟(或者運(yùn)行命令'sysctl vm.overcommit_memory=1' )使其生效。
當(dāng)啟動(dòng)的時(shí)候沒有任何信息,表明啟動(dòng)成功。也可以使用 "netstat -tnl" 查看6379端口是否啟動(dòng)。
4、開啟和關(guān)閉 redis
redis-server /usr/local/redis-2.6.9/redis.conf 開啟,注:需要指定 redis 的配置文件
pkill redis-server 停止 redis
redis-cli shutdown 停止 redis
5、redis.conf 的參數(shù)信息
關(guān)于redis及其參數(shù)信息可參考本站《Redis基本知識(shí)、安裝、部署、配置筆記》
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 !
更多關(guān)于PHP相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《php curl用法總結(jié)》、《PHP運(yùn)算與運(yùn)算符用法總結(jié)》、《PHP網(wǎng)絡(luò)編程技巧總結(jié)》、《PHP基本語(yǔ)法入門教程》、《php操作office文檔技巧總結(jié)(包括word,excel,access,ppt)》、《php日期與時(shí)間用法總結(jié)》、《php面向?qū)ο蟪绦蛟O(shè)計(jì)入門教程》、《php字符串(string)用法總結(jié)》、《php+mysql數(shù)據(jù)庫(kù)操作入門教程》及《php常見數(shù)據(jù)庫(kù)操作技巧匯總》
希望本文所述對(duì)大家PHP程序設(shè)計(jì)有所幫助。
相關(guān)文章
PHP實(shí)現(xiàn)向關(guān)聯(lián)數(shù)組指定的Key之前插入元素的方法
這篇文章主要介紹了PHP實(shí)現(xiàn)向關(guān)聯(lián)數(shù)組指定的Key之前插入元素的方法,涉及php針對(duì)數(shù)組的遍歷、判斷、獲取、插入等相關(guān)操作技巧,需要的朋友可以參考下2017-06-06PHP 刪除文件與文件夾操作 unlink()與rmdir()這兩個(gè)函數(shù)的使用
有時(shí)候我們需要用PHP來刪除文件和文件夾,PHP本來也都有函數(shù)可以實(shí)現(xiàn),下面簡(jiǎn)單記錄一下代碼,方便以后信守拈來。2011-07-07使用git遷移Laravel項(xiàng)目至新開發(fā)環(huán)境的步驟詳解
這篇文章主要介紹了遷移Laravel項(xiàng)目至新開發(fā)環(huán)境的步驟詳解,需要的朋友可以參考下2020-04-04PHP實(shí)現(xiàn)對(duì)數(shù)組分頁(yè)處理實(shí)例詳解
這篇文章主要介紹了PHP實(shí)現(xiàn)對(duì)數(shù)組分頁(yè)處理,結(jié)合實(shí)例形式分析了php封裝的數(shù)組分頁(yè)類定義與使用技巧,需要的朋友可以參考下2017-02-02PHP自定義函數(shù)獲取搜索引擎來源關(guān)鍵字的方法
這篇文章主要介紹了PHP自定義函數(shù)獲取搜索引擎來源關(guān)鍵字的方法,涉及php針對(duì)來路頁(yè)面URL的分析與判斷技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下2016-07-07