linux安裝redis(基於wdlinux面板)

1、安裝redisphp

a、下載redis:linux

  

wget   http://download.redis.io/redis-stable.tar.gznginx

  

tar  -zxvf redis-stable.tar.gzgit

  

cd  redis-stablegithub

  

makeweb

  

make  installredis

  
  

 

b、在redis安裝目錄下進入utils目錄,執行自動安裝腳本apache

  

cd  utils/vim

  

./install_server.sh服務器

  

一路回車都按照默認設置執行

  

//執行完腳本後,會出現如下提示:

  

Selected  config:

  

Port            : 6379

  

Config  file    : /etc/redis/6379.conf

  

Log  file       : /var/log/redis_6379.log

  

Data  dir       : /var/lib/redis/6379

  

Executable      : /usr/local/bin/redis-server

  

Cli  Executable : /usr/local/bin/redis-cli

  
  

 

c、添加redis開機自啓動

  

//修改文件權限

  

chmod  755 /etc/init.d/redis_6379

  

//添加自啓動

  

chkconfig  --add redis_6379

  

chkconfig  --level 345 redis_6379 on

  
  

 

d、檢查遠程服務器的6379端口是否被防火牆攔截。假如未開啓,則開添加

  

/sbin/iptables  -I INPUT -p tcp --dport 6379 -j ACCEPT

  

/etc/init.d/iptables  restart(視服務器狀況而定,若是不知道的話能夠選擇重啓服務器)

  

也能夠在wdcp的後臺系統管理--iptables添加規則

  

使用安騎士等防火牆軟件的自行添加6379端口訪問經過的規則

  
  

 

e、編輯redis配置文件,容許全部ip鏈接

  

vim  /etc/redis/6379.conf

  

//找到bind 127.0.0.1這一行,替換成下面這行內容

  

bind  0.0.0.0

  

保存退出

  

重啓使配置生效:/etc/init.d/redis_6379  restart

  
  

 

f、經過客戶端命令行鏈接redis

 

  

//在本地鏈接

  

redis-cli  -h 127.0.0.1 -p 6379

  
  

 

2、添加phpredis擴展

  

獲取並解壓安裝包

  

cd

  

wget   https://github.com/phpredis/phpredis/archive/develop.zip

  

unzip  develop.zip

  

注意:若提示未找到「unzip」命令

  

解決辦法:運行    yum install unzip -y

  

//進入目錄

  

cd  phpredis-develop

  

使用phpize命令添加擴展,phpize命令所在路徑根據實際狀況修改

  

/www/wdlinux/nginx_php/bin/phpize

  

注意:可能會有「Cannot find  autoconf. Please check your autoconf installation and the $PHP_AUTOCONF  environment variable. Then, rerun this script.」錯誤

  

解決辦法:運行 yum install  -y autoconf

  

再從新運行前面的phpize命令

  

出現相似下圖的提示,則表明成功

 

最後配置

配置。php-config命令所在路徑根據實際狀況修改

./configure  --with-php-config= /www/wdlinux/apache_php-5.4.38/bin/php-config

 出現相似下面的內容,說明此步驟沒問題

安裝

make

出現相似下圖,說明此步驟成功:

  

make install

  

出現相似下面的內容,說明成功:

   
  

表明生成redis.so成功,能夠進到該目錄去查看是否有生成。該路徑也是視實際狀況而定。

  

//php.ini中加入redis.so擴展

  

vim   /www/wdlinux/nginx_php/etc/php.ini

  

//加入這一行,保存退出。路徑要使用上面裝完redis生成redis.so的路徑

  

extension=/www/wdlinux/nginx_php /lib/php/extensions/no-debug-non-zts-20121212/redis.so

重啓web服務(重點是重啓php)

經過phpinfo查看是否添加了redis擴展

 

    檢測後臺進程是否存在

ps -ef |grep redis
  • 檢測6379端口是否在監聽
netstat -lntp | grep 6379
  • 使用redis-cli客戶端檢測鏈接是否正常
redis-cli
127.0.0.1:6379> keys *
(empty list or set)
127.0.0.1:6379> set key "hello world"
OK
127.0.0.1:6379> get key
"hello world"
相關文章
相關標籤/搜索