下载安装编译: 代码: wget http://download.redis.io/releases/redis-stable.tar.gz tar xzf redis-stable.tar.gz cd redis-stable make make install 设置配置文件路径: 代码: mkdir -p /usr/local/redis/bin #命令目录 mkdir -p /usr/local/redis/etc #配置文件目录 mv ./redis.conf /usr/local/redis/etc/ cd src mv mkreleasehdr.sh redis-benchmark redis-check-aof redis-check-rdb redis-cli redis-sentinel redis-server redis-trib.rb /usr/local/redis/bin/ 修改配置文件: # vim /usr/local/redis/etc/redis.conf 修改为: daemonize yes 最后将其注册为系统服务 在/etc/init.d/目录下建立redis 文件 vim /etc/init.d/redis 代码: ########################### #!/bin/sh #chkconfig: 2345 10 90 #description:auto_run PATH=/usr/local/bin:/sbin:/usr/bin:/bin REDISPORT=6379 EXEC=/usr/local/redis/bin/redis-server REDIS_CLI=/usr/local/redis/bin/redis-cli PIDFILE=/var/run/redis_${REDISPORT}.pid CONF="/usr/local/redis/etc/redis.conf" case "$1" in start) if [ -f $PIDFILE ] then echo "$PIDFILE exists, process is already running or crashed" else echo "Starting Redis server..." $EXEC $CONF fi if [ "$?"="0" ] then echo "Redis is running..." fi ;; stop) if [ ! -f $PIDFILE ] then echo "$PIDFILE does not exist, process is not running" else PID=$(cat $PIDFILE) echo "Stopping ..." $REDIS_CLI -p $REDISPORT SHUTDOWN while [ -x ${PIDFILE} ] do echo "Waiting for Redis to shutdown ..." sleep 1 done echo "Redis stopped" fi ;; restart|force-reload) ${0} stop ${0} start ;; *) echo "Usage: /etc/init.d/redis {start|stop|restart|force-reload}" >&2 exit 1 esac ########################### 设置权限 chmod +x /etc/init.d/redis 设置自动启动: chkconfig redis on 启动Redis: # /usr/local/bin/redis-server /usr/local/redis/etc/redis.conf #关闭服务 redis-cli shutdown 或者在cli中执行shutdown redis 127.0.0.1:6379> shutdown 清除缓存 redis-cli flushall 查看状态 : # ps -ef | grep redis 下面介绍为PHP添加redis插件 从官网下载最新的拓展,地址:http://pecl.php.net/package/redis或者https://github.com/phpredis/phpredis 代码: wget http://pecl.php.net/get/redis-4.0.1.tgz tar xzf redis-4.0.1.tgz cd redis-4.0.1 /usr/local/php/bin/phpize ./configure --prefix=/usr/local/redis/ --enable-redis --with-php-config=/usr/local/php/bin/php-config #make && make install 把拓展添加至php.ini,重启php 代码: extension=redis.so session.save_handler = redis session.save_path = "tcp://localhost:6379"