CentOS8安装Redis Server及PHPRedis

Written by

in

,

1.从https://redis.io/下载最新版redis,解压缩

wget https://download.redis.io/releases/redis-6.2.5.tar.gz
tar xvzf redis-6.2.5.tar.gz

2.安装依赖及编译软件

yum install gcc tcl -y

3.编译

cd redis-6.2.5
make PREFIX=/usr/local/redis install

4.生产配置文件,以及生产目录

mkdir /usr/local/redis/conf
cp redis.conf /usr/local/redis/conf
mkdir -p /usr/local/redis/data
mkdir -p /usr/local/redis/data/logs
mkdir -p /usr/local/redis/data/data

5.修改配置文件

#daemonize no
#bind 0.0.0.0
daemonize yes
protected-mode yes
#requirepass 123456
logfile "/usr/local/redis/data/logs/redis.log"
dir "/usr/local/redis/data/"
maxmemory 128MB

6.生产配置service文件

vi /lib/systemd/system/redis.service
#输入如下内容
[Unit]
Description=Redis
After=network.target

[Service]
Type=forking
PIDFile=/var/run/redis_6379.pid
ExecStart=/usr/local/redis/bin/redis-server /usr/local/redis/conf/redis.conf
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true

[Install]
WantedBy=multi-user.target

6.设置service及测试

systemctl daemon-reload 
systemctl start redis
systemctl status redis
systemctl enable redis
ln -s /usr/local/redis/bin/redis-cli /usr/bin/redis
redis -v

7.安装phpredis

#在http://pecl.php.net/package/redis下载最新版本PHPredis扩展
wget http://pecl.php.net/get/redis-5.3.4.tgz
tar xvzf redis-5.3.4.tgz
cd redis-5.3.4
/usr/local/php/bin/phpize
./configure --with-php-config=/usr/local/php/bin/php-config
make && make install
vim /usr/local/php/etc/php.d/04-redis.ini
extension=redis.so
service php-fpm restart

Comments

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注