How to compile and install php redis service

不言
Release: 2023-04-02 16:54:01
Original
1677 people have browsed it

这篇文章主要介绍了关于php redis服务编译安装的方法,有着一定的参考价值,现在分享给大家,有需要的朋友可以参考一下

安装前准备

yum install gcc yum install gcc-c++ mkdir -p /data/pkg cd /data/pkg
Copy after login

下载源码包以及解压

wget http://download.redis.io/releases/redis-4.0.10.tar.gz tar -zxf redis-4.0.10.tar.gz cd redis-4.0.10
Copy after login

编译安装

make make install
Copy after login

make install 后,会在/usr/local/bin目录底下生成多个可执行文件。

redis-cli redis命令行操作工具 redis-benchmark redis性能测试工具 redis-check-aof 数据修复 redis-check-dump 检查导出工具 redis-sentinel redis哨兵 redis-server redis服务启动
Copy after login

配置前准备

mkdir -p /usr/local/redis/bin mkdir -p /usr/local/redis/etc mv /usr/local/bin/redis-* /usr/local/redis/bin/ ln -s /usr/local/redis/bin/{redis-cli,redis-server} /usr/local/bin
Copy after login

配置

cp redis.conf /usr/local/redis/etc cp sentinel.conf /usr/local/redis/etc ln -s /usr/local/redis/etc/* /usr/local/etc
Copy after login

修改配置文件

vim /usr/local/redis/etc/redis.conf #修改Redis配置文件,使Redis以后台进程的形式启动 将daemonize no这行修改为daemonize yes 取消requirepass foobared前的#注释,修改自己设置的密码
Copy after login

启动服务

/usr/local/bin/redis-server /usr/local/redis/etc/redis.conf ps -ef | grep redis netstat -tunpl | grep 6379
Copy after login

停止

pkill redis-server 或者 /usr/local/bin/redis-cli shutdown
Copy after login

将redis做成服务

复制脚本到/etc/rc.d/init.d目录
pkill redis-server cp /data/pkg/redis-4.0.8/utils/redis_init_script /etc/rc.d/init.d/redis
Copy after login
如果这时添加注册服务:
chkconfig --add redis
Copy after login
Copy after login
将报以下错误:
redis服务不支持chkconfig
Copy after login

为此,我们需要更改redis脚本。

更改redis脚本
vim /etc/rc.d/init.d/redis
Copy after login

看到的配置文件

#!/bin/sh #chkconfig: 2345 80 90 # 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="/etc/redis/${REDISPORT}.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
Copy after login

和原配置文件相比:
1.原文件是没有以下第2行的内容的,

#chkconfig: 2345 80 90
Copy after login

2.原文件EXEC、CLIEXEC参数,也是有所更改。

EXEC=/work/redis/bin/redis-server CLIEXEC=/work/redis/bin/redis-cli
Copy after login

3.redis开启的命令,以后台运行的方式执行。

$EXEC $CONF &
Copy after login

4.将redis配置文件拷贝到/etc/redis/${REDISPORT}.conf

mkdir /etc/redis cp /usr/local/redis/etc/redis.conf /etc/redis/6379.conf
Copy after login
注册redis服务
chkconfig --add redis
Copy after login
Copy after login
启动redis服务
service redis start
Copy after login
将redis加入环境变量
vim /etc/profile export PATH="$PATH:/usr/local/redis/bin" source /etc/profile
Copy after login
测试启动redis客户端
redis-cli
Copy after login

以上就是本文的全部内容,希望对大家的学习有所帮助,更多相关内容请关注PHP中文网!

相关推荐:

php编译安装扩展redis及swoole的方法

The above is the detailed content of How to compile and install php redis service. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!