-
- $ wget http://download.redis.io/releases/redis-2.6.16.tar.gz
- $ tar xzf redis-2.6.16.tar.gz
- $ tar xzf redis-2.6.16. tar.gz
- $ cd redis-2.6.16
- $ make install
複製程式碼
2.配置
-
-
- $ mkdir /etc/redis
- $ cp redis.conf /etc/redis/redis.conf
- $ gedit /etc/ctltl. conf$ sysctl -p
複製程式碼
註:sysctl.conf檔案尾部加上vm.overcommit_memory=1
3.啟動測試
-
-
- $ /usr/local/bin/redis-server /etc/redis/redis.conf
- $ /usr/local/bin/redis- cli
- $ set test xjx
- $ get test
複製程式碼
4.開機啟動
-
-
-
$ gedit /etc/redis/redis.conf
- 設定daemonize yes
$ gedit /var/run/redis.pid
- 直接儲存,主要是建立該檔案
gedit /etc/init.d/redis
- 編輯腳本,也可以自行下載或輸入以下內容
- #!/bin/bash
- #
- # redis - this script starts and stops the redis-server daemon
- #
- # chkconfig: - 80 12
- #
- # chkconfig: - 80 12
- # description: Redis is a persistent key-value database
- # processname: redis-server
- # config: /etc/redis/redis.conf
- # pidfile: /var/run/redis.pid
source /etc/init.d/functions
BIN="/usr/local/bin"
- CONFIG="/etc/redis/redis.conf "
- PIDFILE="/var/run/redis.pid"
### Read configuration
- [ -r "$SYSCONFIG" ] && source "$SYSCONFIG" p>
RETVAL=0
- prog="redis-server"
- desc="Redis Server"
start() {
if [ -e $PIDFILE ];then
- echo "$desc already running...."
- exit 1
- fi
echo -n $ "Starting $desc: "
- daemon $BIN/$prog $CONFIG
RETVAL=$?
- echo
- [ $RETVAL -eq 0 ] && touch /var/ lock/subsys/$prog
- return $RETVAL
- }
stop() {
- echo -n $"Stop $desc: "
- killproc $prog
- RETVAL=$?
- echo
- [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/$prog $PIDFILE
- return $RETVAL
- }
restart() {
- stop
- start
- }
case "$1" in
- start)
- start
case "$1" in
- start)
- start
- ;;
- stop)
- stop
- ;;
- restart)
- restart
- ;;
- condrestart)
- [ -e /var/lock/subsys/$prog ] &&& restart
- RETVAL=$?
- ;;
- status)
- status $prog
- RETVAL=$?
- ;;
- *)
echo $"Usage: $0 {start|stop|restart|condrestart|status}" RETVAL=1 esacexit $RETVAL
$ chmod 755 /etc/init.d/redis
複製代碼
$ 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
- 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)
- 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目錄即可,這裡提供大家,最好不用官方最新版本,個中原由,你用了就明白啦。
|