安裝redis和phpredis模塊

安裝redis

#yum install tclphp



#tar -zxf redis-3.0.3.tar.gz

#cp -r /usr/local/src/redis-3.0.3 /usr/local/redis-3git

#cd /usr/local/redis-3
#make && make install
github


# vim redis.conf
daemonize yes

#cp redis-server /usr/local/bin/
#cp redis-cli /usr/local/bin/


redis啓動腳本

#vim /etc/init.d/redisredis


#!/bin/bash
#
# Init file for redis
#
# chkconfig: - 80 12
# description: redis daemon
#
# processname: redis
# config: /etc/redis.conf
# pidfile: /var/run/redis.pid
source /etc/init.d/functions
#BIN="/usr/local/bin"
BIN="/usr/local/bin"
CONFIG="/usr/local/redis-3/redis.conf"
PIDFILE="/var/run/redis.pid"
### Read configuration
[ -r "$SYSCONFIG" ] && source "$SYSCONFIG"
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
}
#!/bin/bash
#
# Init file for redis
#
# chkconfig: - 80 12
# description: redis daemon
#
# processname: redis
# config: /etc/redis.conf
# pidfile: /var/run/redis.pid
source /etc/init.d/functions
#BIN="/usr/local/bin"
BIN="/usr/local/bin"
CONFIG="/usr/local/redis-3/redis.conf"
PIDFILE="/var/run/redis.pid"
### Read configuration
[ -r "$SYSCONFIG" ] && source "$SYSCONFIG"
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
        ;;
  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
esac
exit $RETVAL




#chmod +x /etc/init.d/redisvim

啓動redis,最好先在配置文件裏設置後臺運行,不然啓動的話是前臺運行,會一直佔用終端
bash

# /etc/init.d/redis restart測試





報錯(分三部分,三個WARNING)

4347:M 29 Sep 21:31:55.388 # Server started, Redis version 3.0.3ui



4347:M 29 Sep 21:31:55.388 # WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect.



4347:M 29 Sep 21:31:55.388 # WARNING you have Transparent Huge Pages (THP) support enabled in your kernel. This will create latency and memory usage issues with Redis. To fix this issue run the command 'echo never > /sys/kernel/mm/transparent_hugepage/enabled' as root, and add it to your /etc/rc.local in order to retain the setting after a reboot. Redis must be restarted after THP is disabled.this



4347:M 29 Sep 21:31:55.388 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.spa

4347:M 29 Sep 21:31:55.388 * The server is now ready to accept connections on port 6379

(1)
解決方法
#vim /etc/sysctl.conf
加入
vm.overcommit_memory = 1
或者
#echo "vm.overcommit_memory=1" >> /etc/sysctl.conf

刷新生效
#sysctl -p

(2)
#echo never > /sys/kernel/mm/transparent_hugepage/enabled
#vim /etc/rc.local
加入
echo never > /sys/kernel/mm/transparent_hugepage/enabled

(3)
#echo 511 > /proc/sys/net/core/somaxconn



再啓動一次,應該就沒問題了

# /etc/init.d/redis restart



測試

# redis-cli
127.0.0.1:6379> set foo bar
OK
127.0.0.1:6379> bar
(error) ERR unknown command 'bar'
127.0.0.1:6379> get foo
"bar"
127.0.0.1:6379> quit




安裝php擴展https://github.com/nicolasff/phpredis/archive/2.2.4.tar.gz#tar -zxf phpredis-2.2.4.tar.gz#phpize ./#./configure --with-php-config=/usr/local/php/bin/php-config #make && make install# vim /usr/local/php/etc/php.ini加入[redis]extension=/usr/local/php/lib/php/extensions/no-debug-non-zts-20100525/redis.so
相關文章
相關標籤/搜索