編譯安裝redis

1、版本說明

CentOS版本

 

[plain]view plaincopyprint? 在CODE上查看代碼片 派生到個人代碼片
 
  1. [root@localhost ~]# uname  php

  2. Linux  c++

  3. [root@localhost ~]# uname -r  git

  4. 2.6.32-431.el6.i686  github

  5. [root@localhost ~]# uname -a  redis

  6. Linux localhost 2.6.32-431.el6.i686 #1 SMP Fri Nov 22 00:26:36 UTC 2013 i686 i686 i386 GNU/Linux  數據庫

  7. [root@localhost ~]# cat /etc/centos-release  centos

  8. CentOS release 6.5 (Final)  服務器

 

 

Redis的版本

 

請到redis的官網下載最新的 http://redis.io/downloadide

這裏咱們下載不是最新的穩定版的2.8.6,3.0.0由於是Beta版本因此不推薦生產環境使用,開發環境嚐鮮仍是能夠的。工具

 

phpredis的版本

這裏經過 redis官網的 http://redis.io/clients 找到PhpRedis 去github上就能找到啦 https://github.com/nicolasff/phpredis ,這裏顯示的版本是2.2.4 。

 

2、安裝

1.安裝redis

安裝教程在redis的官網上就有,這裏詳細講一下。

wget

下載網上的資源須要用到wget工具,有的同窗的服務器多是新裝的尚未來得及裝(好比我。。。)

 

[plain]view plaincopyprint? 在CODE上查看代碼片 派生到個人代碼片
 
  1. #安裝wget  

  2. yum install wget  


ok,而後開始安裝redis,順便說一句,鏈接外國網站真是慢的不得了,兩三次下載都卡住了 = =

 

 

[plain]view plaincopyprint? 在CODE上查看代碼片 派生到個人代碼片
 
  1. $ wget http://download.redis.io/releases/redis-2.8.6.tar.gz  

  2. $ tar xzf redis-2.8.6.tar.gz  

  3. $ cd redis-2.8.6  

  4. $ make  

 

 

make錯誤

而後。QAQ,make的時候又出現了錯誤

 

[plain]view plaincopyprint? 在CODE上查看代碼片 派生到個人代碼片
 
  1. make[3]: gcc:命令未找到  

 

 

安裝gcc

 

看來沒有安裝gcc....

 

[plain]view plaincopyprint? 在CODE上查看代碼片 派生到個人代碼片
 
  1. #安裝gcc  

  2. yum install gcc gcc-c++ kernel-devel  

 

 

再次make錯誤

而後安裝的時候又發現出現了錯誤

 

[plain]view plaincopyprint? 在CODE上查看代碼片 派生到個人代碼片
 
  1. zmalloc.h:50:31: 錯誤:jemalloc/jemalloc.h:沒有那個文件或目錄  

  2. zmalloc.h:55:2: 錯誤:#error "Newer version of jemalloc required"  


而後去百度了,解決方案爲

 

 

[plain]view plaincopyprint? 在CODE上查看代碼片 派生到個人代碼片
 
  1. make MALLOC=libc  

 

 

make完成

接下來就是耐心等待,下面是我看到的結果。

 

[plain]view plaincopyprint? 在CODE上查看代碼片 派生到個人代碼片
 
  1. Hint: To run 'make test' is a good idea ;)  

  2.  

  3. make[1]: Leaving directory `/root/redis-2.8.6/src'  


這樣就算安裝完成了。

 

啓動redis服務

請注意,若是你在make的時候出現上述的問題,那麼,在啓動redis服務的時候就要注意了

 

[plain]view plaincopyprint? 在CODE上查看代碼片 派生到個人代碼片
 
  1. #官方網站提示這樣啓動服務  

  2. src/redis-server  

  3. #可是出現了上面的問題後,請用下面的方式啓動redis服務  

  4. nohup src/redis-server redis.conf &  


啓動redis服務完成。

 

簡單測試

下面是簡單測試。

 

[plain]view plaincopyprint? 在CODE上查看代碼片 派生到個人代碼片
 
  1. [root@localhost redis-2.8.6]# src/redis-cli  

  2. 127.0.0.1:6379> ping  

  3. PONG  

 

 

2.安裝PhpRedis

 

phpize

phpredis屬於php擴展,因此須要phpize,若是你的服務器沒有安裝phpize,要先安裝

 

[plain]view plaincopyprint? 在CODE上查看代碼片 派生到個人代碼片
 
  1. #安裝phpize  

  2. yum install php-devel  

 

 

下載源碼包

 

直接用wget好了

 

[plain]view plaincopyprint? 在CODE上查看代碼片 派生到個人代碼片
 
  1. #wget下載github上的文件  

  2. wget https://github.com/nicolasff/phpredis/archive/master.zip  

 

 

unzip

下面要解壓zip文件,首先,你,要,有個,unzip....

 

[plain]view plaincopyprint? 在CODE上查看代碼片 派生到個人代碼片
 
  1. #安裝了這麼多的軟件,想一想也該知道怎麼裝這個東西了吧  

  2. yum install unzip  

 

[plain]view plaincopyprint? 在CODE上查看代碼片 派生到個人代碼片
 
  1. #解壓  

  2. unzip master.zip  

 

 

編譯

下面正式開始編譯php擴展

 

[plain]view plaincopyprint? 在CODE上查看代碼片 派生到個人代碼片
 
  1. #1.準備phpize編譯環境  

  2. [root@localhost phpredis-master]# phpize  

  3. Configuring for:  

  4. PHP Api Version:         20090626  

  5. Zend Module Api No:      20090626  

  6. Zend Extension Api No:   220090626  


再次ls就會發現文件夾中多了幾個配置文件

 

 

[plain]view plaincopyprint? 在CODE上查看代碼片 派生到個人代碼片
 
  1. #2.配置環境  

  2. ./configure  


這個步驟會將上一步準備好的配置文件進行執行

 

 

[plain]view plaincopyprint? 在CODE上查看代碼片 派生到個人代碼片
 
  1. #3.編譯  

  2. make && make install  


balabala...........

 

 

[plain]view plaincopyprint? 在CODE上查看代碼片 派生到個人代碼片
 
  1. #編譯完成  

  2. Build complete.  

  3. Don't forget to run 'make test'.  

  4.  

  5. Installing shared extensions:     /usr/lib/php/modules/  

 

進入/usr/lib/php/modules 文件夾,發現redis.so的擴展。

 

修改php.ini

 

[plain]view plaincopyprint? 在CODE上查看代碼片 派生到個人代碼片
 
  1. [root@localhost phpredis-master]# vi /etc/php.ini  

 

 

添加下面的擴展

 

[plain]view plaincopyprint? 在CODE上查看代碼片 派生到個人代碼片
 
  1. extension=redis.so  

 

 

重啓服務器

 

 

[plain]view plaincopyprint? 在CODE上查看代碼片 派生到個人代碼片
 
  1. [root@localhost modules]# service httpd restart  

  2. 中止 httpd:                                               [肯定]  

  3. 正在啓動 httpd:                                           [肯定]  

 

 

查看phpinfo

 

 

3、總結

借用《七日七數據庫》中的一句話,redis就像是無處不在的潤滑油。

簡單,快速。

咱們從小到大,正是由於經歷了足夠多的事情纔會成長。

相關文章
相關標籤/搜索