1. 程式人生 > >redis python-redis 安裝詳細步驟(整理中)

redis python-redis 安裝詳細步驟(整理中)

把redis安裝到 /opt/redis-2.8目錄中

  • wget http://download.redis.io/releases/redis-2.8.1.tar.gz
  • tar -zxfx redis-2.8.1.tar.gz
  • cd redis-2.8.1
  • make && make PREFIX=/opt/redis-2.8 install
  • cp redis.conf /opt/redis-2.8/

只是把redis當做佇列用,不需要儲存,所以編輯 /opt/redis-2.8/redis.conf

  • 設定 daemonize yes
  • 把3條 save .. 都註釋掉,這樣就關閉了硬碟儲存

啟動redis 非常簡單: /opt/redis-2.8/bin/redis-server /opt/redis-2.8/redis.conf

$REIDS_INSTALL_DIR/utils/redis_init_script 這個指令碼稍做修改就可以放到/etc/init.d 作為redis啟動指令碼用

安裝python

CentOS 自帶的python2.4,太舊了,升級到2.7

  • wget http://www.python.org/ftp/python/2.7.6/Python-2.7.6.tgz
  • tar -zvxf Python-2.7.6.tgz
  • cd Python-2.7.6
  • ./configure
  • make && make install
  • 替換系統預設的python: sudo ln -s /usr/local/bin/python2.7 /usr/bin/python
安裝python的redis模組
  • wget --no-check-certificate https://pypi.python.org/packages/source/r/redis/redis-2.8.0.tar.gz
  • tar -zvxf redis-2.8.0.tar.gz
  • mv redis-2.8.0 python-redis-2.8.0
  • cd python-redis-2.8.0
  • python setup.py install

部署成功,寫段程式碼驗證一下

import redis
client =  redis.StrictRedis(host='localhost', port=6379)
print client.ping()

True

執行成功