centos6.4中安裝redis與phpredis

WBOY
發布: 2016-07-25 08:57:39
原創
1022 人瀏覽過
  1. $ wget http://download.redis.io/releases/redis-2.6.16.tar.gz
  2. $ tar xzf redis-2.6.16.tar.gz
  3. $ tar xzf redis-2.6.16. tar.gz
  4. $ cd redis-2.6.16
  5. $ make install
複製程式碼

2.配置
  1. $ mkdir /etc/redis
  2. $ cp redis.conf /etc/redis/redis.conf
  3. $ gedit /etc/ctltl. conf$ sysctl -p
複製程式碼

註:sysctl.conf檔案尾部加上vm.overcommit_memory=1

3.啟動測試
  1. $ /usr/local/bin/redis-server /etc/redis/redis.conf
  2. $ /usr/local/bin/redis- cli
  3. $ set test xjx
  4. $ get test
複製程式碼

4.開機啟動
  1. $ gedit /etc/redis/redis.conf

  2. 設定daemonize yes
  3. $ gedit /var/run/redis.pid

  4. 直接儲存,主要是建立該檔案
  5. gedit /etc/init.d/redis

  6. 編輯腳本,也可以自行下載或輸入以下內容
  7. #!/bin/bash
  8. #
  9. # redis - this script starts and stops the redis-server daemon
  10. #
  11. # chkconfig: - 80 12
  12. #
  13. # chkconfig: - 80 12
  14. # description: Redis is a persistent key-value database
  15. # processname: redis-server
  16. # config: /etc/redis/redis.conf
  17. # pidfile: /var/run/redis.pid
  18. source /etc/init.d/functions

  19. BIN="/usr/local/bin"

  20. CONFIG="/etc/redis/redis.conf "
  21. PIDFILE="/var/run/redis.pid"
  22. ### Read configuration

  23. [ -r "$SYSCONFIG" ] && source "$SYSCONFIG" p>
  24. RETVAL=0

  25. prog="redis-server"
  26. desc="Redis Server"
  27. start() {

  28. if [ -e $PIDFILE ];then

  29. echo "$desc already running...."
  30. exit 1
  31. fi
  32. echo -n $ "Starting $desc: "

  33. daemon $BIN/$prog $CONFIG
  34. RETVAL=$?

  35. echo
  36. [ $RETVAL -eq 0 ] && touch /var/ lock/subsys/$prog
  37. return $RETVAL
  38. }
  39. stop() {

  40. echo -n $"Stop $desc: "
  41. killproc $prog
  42. RETVAL=$?
  43. echo
  44. [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/$prog $PIDFILE
  45. return $RETVAL
  46. }
  47. restart() {

  48. stop
  49. start
  50. }
  51. case "$1" in

  52. start)
  53. start

    case "$1" in

  54. start)
  55. start
  56. ;;
  57. stop)
  58. stop
  59. ;;
  60. restart)
  61. restart
  62. ;;
  63. condrestart)
  64. [ -e /var/lock/subsys/$prog ] &&& restart
  65. RETVAL=$?
  66. ;;
  67. status)
  68. status $prog
  69. RETVAL=$?
  70. ;;
  71. *)
echo $"Usage: $0 {start|stop|restart|condrestart|status}"
RETVAL=1esac

exit $RETVAL

複製程式碼
  1. 改變檔案權限:
$ chmod 755 /etc/init.d/redis

複製代碼
  1. 添加開機啟動:
$ chkconfig --add redis$ chkconfig --level 345 redis on
$ chkconfig --list redis

複製程式碼

之後重新啟動伺服器,$ service redis status 檢視是否正確設定

接下來介紹phpredis的安裝與設定方法。

二、phpredis
1.自行下載解壓縮 https://github.com/nicolasff/phpredis/archive/master.zip
  1. 2.安裝
$ cd /root/phpredis-master
$ /usr/local/php/bin/phpize$ ./configure --with -php-config=/usr/local/php/bin/php-config$ make && make install

複製程式碼

註:路徑根據實際情況修改 3.php擴展 $ gedit /usr/local/php/etc/php.ini 加入extension=redis.so,然後重新啟動php-fpm(非nginx)
  1. 4.測試
$redis = new Redis();
$redis->connect('127.0.0.1',6379);$redis- >set('test','hello world!');echo $redis->get('test');
複製程式碼

三、phpredisadmin http://down.admin5.com/php/75024.html 下載解壓縮至www目錄即可,這裡提供大家,最好不用官方最新版本,個中原由,你用了就明白啦。



來源:php.cn
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!