可参考:
https://blog.vini123.com/107
###
wget http://download.redis.io/releases/redis-5.0.8.tar.gz
tar -xzvf redis-5.0.8.tar.gz
cd redis-5.0.8
# 安装依赖
yum install tcl
# 继续
make
make test
# 没有问题就安装
make install PREFIX=/alidata/service/redis
# 配置并启动redis
mkdir /alidata/service/redis/etc/
cp /usr/local/src/redis/redis-5.0.8/redis.conf /alidata/service/redis/etc/
vim /alidata/service/redis/etc/redis.conf #编辑redis.conf
daemonize yes #将此行对应的no改成yes。
# 启动
/alidata/service/redis/bin/redis-server /alidata/service/redis/etc/redis.conf
# 连接 redis
/alidata/service/redis/bin/redis-cli
配置开机自启动
# 开机自启动
cp /usr/local/src/redis/redis-5.0.8/utils/redis_init_script /etc/init.d/redis
vim /etc/init.d/redis
# 然后修改EXEC、REDIS_CLI、CONF对应的值。分别对应服务端位置、客户端位置、配置文件位置。保存,退出。修改后的脚本如下;
# 修改
#!/bin/sh
#
# Simple Redis init.d script conceived to work on Linux systems
# as it does use of the /proc filesystem.
### BEGIN INIT INFO
# Provides: redis_6379
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Redis data structure server
# Description: Redis data structure server. See https://redis.io
### END INIT INFO
REDISPORT=6379
EXEC=/alidata/service/redis/bin/redis-server
CLIEXEC=/alidata/service/redis/bin/redis-cli
PIDFILE=/var/run/redis_${REDISPORT}.pid
CONF=/alidata/service/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
;;
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
;;
*)
echo "Please use start or stop as first argument"
;;
esac
执行权限,并开启服务重启自启动
chmod +x /etc/init.d/redis #执行权限
chkconfig redis on #系统服务中启动redis服务
chkconfig --list #系统服务启动列表
/etc/init.d/redis start #启动redis
安装 php redis 扩展
cd /usr/local/src
mkdir php-redis
cd php-redis
wget http://pecl.php.net/get/redis-5.2.1.tgz
tar -xizvf redis-5.2.1.tgz
cd redis-5.2.1
# 编译安装
phpize
./configure
make && make install
# 配置
vim /alidata/service/php/etc/php.ini
在末尾加上 extension=redis.so 保存。
# 重启
/etc/init.d/php-fpm restart
# 查看
php -m | grep redis