Table of Contents
安装前准备
下载源码包以及解压
编译安装
配置前准备
配置
修改配置文件
启动服务
停止
将redis做成服务
复制脚本到/etc/rc.d/init.d目录
如果这时添加注册服务:
将报以下错误:
更改redis脚本
注册redis服务
启动redis服务
将redis加入环境变量
测试启动redis客户端
Home Backend Development PHP Tutorial How to compile and install php redis service

How to compile and install php redis service

Jul 06, 2018 pm 02:11 PM
centos7 linux php redis

这篇文章主要介绍了关于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!

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

PHP and Python: Different Paradigms Explained PHP and Python: Different Paradigms Explained Apr 18, 2025 am 12:26 AM

PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.

Choosing Between PHP and Python: A Guide Choosing Between PHP and Python: A Guide Apr 18, 2025 am 12:24 AM

PHP is suitable for web development and rapid prototyping, and Python is suitable for data science and machine learning. 1.PHP is used for dynamic web development, with simple syntax and suitable for rapid development. 2. Python has concise syntax, is suitable for multiple fields, and has a strong library ecosystem.

PHP vs. Python: Use Cases and Applications PHP vs. Python: Use Cases and Applications Apr 17, 2025 am 12:23 AM

PHP is suitable for web development and content management systems, and Python is suitable for data science, machine learning and automation scripts. 1.PHP performs well in building fast and scalable websites and applications and is commonly used in CMS such as WordPress. 2. Python has performed outstandingly in the fields of data science and machine learning, with rich libraries such as NumPy and TensorFlow.

PHP and Python: A Deep Dive into Their History PHP and Python: A Deep Dive into Their History Apr 18, 2025 am 12:25 AM

PHP originated in 1994 and was developed by RasmusLerdorf. It was originally used to track website visitors and gradually evolved into a server-side scripting language and was widely used in web development. Python was developed by Guidovan Rossum in the late 1980s and was first released in 1991. It emphasizes code readability and simplicity, and is suitable for scientific computing, data analysis and other fields.

Linux Architecture: Unveiling the 5 Basic Components Linux Architecture: Unveiling the 5 Basic Components Apr 20, 2025 am 12:04 AM

The five basic components of the Linux system are: 1. Kernel, 2. System library, 3. System utilities, 4. Graphical user interface, 5. Applications. The kernel manages hardware resources, the system library provides precompiled functions, system utilities are used for system management, the GUI provides visual interaction, and applications use these components to implement functions.

How to run java code in notepad How to run java code in notepad Apr 16, 2025 pm 07:39 PM

Although Notepad cannot run Java code directly, it can be achieved by using other tools: using the command line compiler (javac) to generate a bytecode file (filename.class). Use the Java interpreter (java) to interpret bytecode, execute the code, and output the result.

PHP's Impact: Web Development and Beyond PHP's Impact: Web Development and Beyond Apr 18, 2025 am 12:10 AM

PHPhassignificantlyimpactedwebdevelopmentandextendsbeyondit.1)ItpowersmajorplatformslikeWordPressandexcelsindatabaseinteractions.2)PHP'sadaptabilityallowsittoscaleforlargeapplicationsusingframeworkslikeLaravel.3)Beyondweb,PHPisusedincommand-linescrip

How to check the warehouse address of git How to check the warehouse address of git Apr 17, 2025 pm 01:54 PM

To view the Git repository address, perform the following steps: 1. Open the command line and navigate to the repository directory; 2. Run the "git remote -v" command; 3. View the repository name in the output and its corresponding address.

See all articles