一、安装redis
下载安装redis,官网:https://redis.io/download
wget http://download.redis.io/releases/redis-3.2.8.tar.gz
tar xzf redis-3.2.8.tar.gz
cd redis-3.2.8
make
没有报错的话,redis 就安装好了。
配置环境变量
echo 'export PATH=$PATH:/usr/local/redis/bin' >> /etc/profile . /etc/profile
配置 redis.conf
cd redis-3.2.3
// 进入redis 源码包目录
mkdir /usr/local/redis/etc/
cp redis.conf /usr/local/redis/etc/
cd /usr.local/redis/etc/
vim redis.conf
//redis.conf daemonize yes //后台运行 pidfile /var/run/redis/redis.pid port 6379 tcp-backlog 128 // tcp队列长度,默认为512,CentOS系统默认为128,此值不应该大于操作系统的该值 logfile "/var/log/redis/redis.log" dir /var/redisdb // redis数据存储目录 // 其他参数目前就不需要了 配置redis的服务脚本 useradd -r -s /sbin/nologin -M redis mkdir /var/run/redis mkdir /var/log/redis mkdir /var/redisdb chown redis:redis /var/run/redis chown redis:redis /var/log/redis chown redis:redis /var/redisdb #!/bin/sh #chkconfig: 35 84 16 #Simple Redis init.d script conceived to work on Linux systems #as it does use of the /proc filesystem. . /etc/rc.d/init.d/functions . /etc/sysconfig/network [ "$NETWORKING" = "no" ] && exit 0 REDISPORT=6379 BASEDIR=/usr/local/redis EXEC=$BASEDIR/bin/redis-server CLIEXEC=$BASEDIR/bin/redis-cli PIDFILE=/var/run/redis/redis.pid CONF="$BASEDIR/etc/redis.conf" function start() { if [ -f $PIDFILE ] then echo "$PIDFILE exists,process is already running or crashed" else echo -n "Starting Redis server..." daemon --user=redis --pidfile=$PIDFILE $EXEC $CONF #$EXEC $CONF echo fi } function stop() { if [ ! -f $PIDFILE ] then echo "$PIDFILE does not exist,process is not running" else PID=$(cat $PIDFILE) echo "Stopping ..." #$CLIEXEC -p $REDISPORT shutdown killproc -p $PIDFILE $EXEC -INT echo -n "Waiting for Redis saving data & shutdown ." while [ -x /proc/${PID} ] do sleep 1 echo -n "." done echo -e "\nRedis stopped" fi } case "$1" in start) start ;; stop) stop ;; status) status -p $PIDFILE $EXEC ;; restart) stop start ;; *) echo "Please use start or stop as first argument" ;; esac
后面的参数是我们要的模块,但是随着工作的需要,我们还要在加些模块,又不想重新编译PHP,这些我们就可以
用PHPize了。
1.下载PHPredis
#wget下载github上的文件
wget https://github.com/nicolasff/phpredis/archive/master.zip
2.开始编译PHPredis扩展
A #unzip master.zip
B #解压后进入 cd PHPredis-master
(#PHPize 执行此命令
//I,先find / -name 'PHPize',如果找到就完成命令执行如
// /opt/app/PHP/bin/PHPize
//或者
//检查PHP扩展,出错的话:bash: PHPize: command not found
//yum install PHP-devel
//我是安装PHP56u的所以:yum install PHP56u-devel
)
C #PHPize
Configuring for:
PHP Api Version: 20041225 Zend Module Api No: 20050922 Zend Extension Api No: 220051025 D config配置 #./configure --with-PHP-config=/usr/local/bin/PHP-config (此目录为PHP安装的PHP-config,find找下) make make install 成功后出现: Installing shared extensions: /usr/lib/PHP/modules/ #ls /usr/lib/PHP/modules/ dbase.so ldap.so pdo.so pdo_sqlite.so PHPcups.so redis.so snmp.so 有需要的模块名称说明安装完毕
vim /etc/PHP.ini (找到PHP安装目录下这个配置文件) extention="redis.so" //添加这一行扩展配置
4,重启PHP-fpm服务
service PHP-fpm restart
5 .测试扩展库是否正常运行
//在git clone下来的PHPredis文件夹 PHP tests/TestRedis.PHP --class Redis