一、安装扩展
1.下载并编译安装
wget https://github.com/phpredis/phpredis/archive/3.0.0.tar.gz
tar zxvf 3.0.0.tar.gz
cd phpredis-3.0.0/
phpize
./configure --with-php-config=/usr/local/php/bin/php-config
make
make install
2.在配置文件/usr/local/php/etc/php.ini中加入
extension="redis.so"
3.重启PHP服务 nginx、apache 或 php-fpm
二、安装Redis
wget http://download.redis.io/releases/redis-3.2.5.tar.gz
tar zxvf redis-3.2.5.tar.gz
cd redis-3.2.5
make
make install
make install 之后,会在/usr/local/bin下面生成几个文件 redis-benchmark redis-check-aof redis-check-rdb redis-cli redis-server
移动文件,便于管理:(所有源代码安装的软件都安装在/usr/local下)
创建两个文件夹,bin用于存放命令,etc用于存放配置文件。
mkdir -p /usr/local/redis/bin
mkdir -p /usr/local/redis/etc
将redis-3.2.5文件夹下的redis.conf复制到/usr/local/redis/etc/
修改配置文件中的 daemonize no 改为 daemonize yes,可以在后台运行redis
配置启动项 utils 文件夹下面的 redis_init_script 文件
cp redis_init_script /etc/init.d/redisd
#!/bin/bash
# chkconfig: 2345 90 10
# Simple Redis init.d script conceived to work on Linux systems
# as it does use of the /proc filesystem.
REDISPORT=6379
EXEC=/usr/local/redis/bin/redis-server
CLIEXEC=/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
echo "Redis started"
fi
;;
stop)
if [ ! -f $PIDFILE ]
then
echo "$PIDFILE does not exist, process is not running"
else
PID=$(cat $PIDFILE)
echo "Stopping ..."
$CLIEXEC -p $REDISPORT shutdown
while [ -x /proc/${PID} ]
do
echo "Waiting for Redis to shutdown ..."
sleep 1
done
echo "Redis stopped"
fi
;;
status)
if netstat -tnpl | grep -q redis-server; then
PID=`pidof redis-server`
echo "Redis (pid $PID) is running..."
else
echo "Redis is stopped"
exit 0
fi
;;
restart)
$0 stop
sleep 1
$0 start
;;
*)
echo "Please use start or stop as first argument"
;;
esac
chkconfig redisd on