search
HomeDatabaseRedisHow to set up php environment redis

一、下载

1、http://download.redis.io/releases/redis-6.0.9.tar.gz下载到本地,文件传输上传到 /usr/local/src/
2、wget -P /usr/local/src/ http://download.redis.io/releases/redis-6.0.9.tar.gz

二、解压,编译,安装

> cd /usr/local/src
> tar xzf tar xzf redis-6.0.9.tar.gz
> cd redis-6.0.9
> make

编译完会默认将软件安装在当前目录,这里将整个解压缩文件移至local目录

mv /usr/local/src/redis-6.0.9 /usr/local/redis-6.0.9

三、更改配置 /usr/local/redis-6.0.9/redis.conf
1、更改默认端口为16379
2、设置redis服务以守护进程运行
3、设置redis可供远程访问
4、设置密码

> vim /usr/local/redis-6.0.9/redis.conf # 打开redis服务启动配置文件,
# vim中命令模式下输入“/关键字”    
# 类似于windows的文件中查询,字符n代表下一个,N代表上一个。
# 设置参数值 no 为 yes 并在命令模式下输入 “:wq” 代表保存并退出
> /port # 匹配到端口 改为16379,该配置是用来限制端口访问的
> /pid  #匹配pid文件,改为redis_16379,该配置是用来存储pid信息,主要是为了命名风格统一,与端口一致,如果不改默认端口,这里也不用改
> /daemonize # 匹配到守护进程配置,设置yes会以守护进程模型常驻
> /bind 127.0.0.1 #注释掉该行,或者注释掉所有的bind配置,改为bind 0.0.0.0,意味着允许任何ip访问,该配置是用来限制IP访问的
> /protected-mode yes #把yes改为no
> /requirepass #去除前面的#打开注释,并更改默认的密码为自定义密码【最好复杂点,以免暴力破解】

redis在开放远程访问,又不设置密码的情况下,相当于谁都可以访问redis服务器,且非常容易被服务器探针攻击,被注入挖矿木马或者勒索木马,如果服务器没有备份基本GG,所以
开放远程访问,一定要更改默认密码,即requirepass参数后面的字符串
开放远程访问,一定要更改默认密码,即requirepass参数后面的字符串
开放远程访问,一定要更改默认密码,即requirepass参数后面的字符串

四、设置开机自启动

vim /etc/init.d/redis

将如下配置复制粘贴保存

#!/bin/sh
#
# Simple Redis init.d script conceived to work on Linux systems
# as it does use of the /proc filesystem.
#chkconfig: 2345 80 90
#description:auto_run
REDISPORT=16379
EXEC=/usr/local/redis-6.0.9/src/redis-server
CLIEXEC=/usr/local/redis-6.0.9/src/redis-cli

PIDFILE=/var/run/redis_${REDISPORT}.pid
CONF="/usr/local/redis-6.0.9/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
                # 有设置密码要加 -a “密码”  参数,如下
                # $CLIEXEC -a "自定义的密码" -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 -R 0777 /etc/init.d/redis

检验自启动脚本

> service redis start # 检验服务启动
> service redis stop # 检验服务关闭
// 均正常提示
> chkconfig redis on # 设置开机自动执行redis开机自启动脚本
> reboot # 重启,ssh重连
# 重启后
> netstat -ntlp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    
tcp        0      0 0.0.0.0:16379           0.0.0.0:*               LISTEN      839/redis-server 0. 
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      1056/sshd

验证开机自启动成功
安装完毕

五、服务器上使用

> /usr/local/redis-6.0.9/src/redis-cli -p 16379 -a "配置文件里设置的密码"

The above is the detailed content of How to set up php environment redis. For more information, please follow other related articles on the PHP Chinese website!

Statement
This article is reproduced at:亿速云. If there is any infringement, please contact admin@php.cn delete
Redis's Role: Exploring the Data Storage and Management CapabilitiesRedis's Role: Exploring the Data Storage and Management CapabilitiesApr 22, 2025 am 12:10 AM

Redis plays a key role in data storage and management, and has become the core of modern applications through its multiple data structures and persistence mechanisms. 1) Redis supports data structures such as strings, lists, collections, ordered collections and hash tables, and is suitable for cache and complex business logic. 2) Through two persistence methods, RDB and AOF, Redis ensures reliable storage and rapid recovery of data.

Redis: Understanding NoSQL ConceptsRedis: Understanding NoSQL ConceptsApr 21, 2025 am 12:04 AM

Redis is a NoSQL database suitable for efficient storage and access of large-scale data. 1.Redis is an open source memory data structure storage system that supports multiple data structures. 2. It provides extremely fast read and write speeds, suitable for caching, session management, etc. 3.Redis supports persistence and ensures data security through RDB and AOF. 4. Usage examples include basic key-value pair operations and advanced collection deduplication functions. 5. Common errors include connection problems, data type mismatch and memory overflow, so you need to pay attention to debugging. 6. Performance optimization suggestions include selecting the appropriate data structure and setting up memory elimination strategies.

Redis: Real-World Use Cases and ExamplesRedis: Real-World Use Cases and ExamplesApr 20, 2025 am 12:06 AM

The applications of Redis in the real world include: 1. As a cache system, accelerate database query, 2. To store the session data of web applications, 3. To implement real-time rankings, 4. To simplify message delivery as a message queue. Redis's versatility and high performance make it shine in these scenarios.

Redis: Exploring Its Features and FunctionalityRedis: Exploring Its Features and FunctionalityApr 19, 2025 am 12:04 AM

Redis stands out because of its high speed, versatility and rich data structure. 1) Redis supports data structures such as strings, lists, collections, hashs and ordered collections. 2) It stores data through memory and supports RDB and AOF persistence. 3) Starting from Redis 6.0, multi-threaded I/O operations have been introduced, which has improved performance in high concurrency scenarios.

Is Redis a SQL or NoSQL Database? The Answer ExplainedIs Redis a SQL or NoSQL Database? The Answer ExplainedApr 18, 2025 am 12:11 AM

RedisisclassifiedasaNoSQLdatabasebecauseitusesakey-valuedatamodelinsteadofthetraditionalrelationaldatabasemodel.Itoffersspeedandflexibility,makingitidealforreal-timeapplicationsandcaching,butitmaynotbesuitableforscenariosrequiringstrictdataintegrityo

Redis: Improving Application Performance and ScalabilityRedis: Improving Application Performance and ScalabilityApr 17, 2025 am 12:16 AM

Redis improves application performance and scalability by caching data, implementing distributed locking and data persistence. 1) Cache data: Use Redis to cache frequently accessed data to improve data access speed. 2) Distributed lock: Use Redis to implement distributed locks to ensure the security of operation in a distributed environment. 3) Data persistence: Ensure data security through RDB and AOF mechanisms to prevent data loss.

Redis: Exploring Its Data Model and StructureRedis: Exploring Its Data Model and StructureApr 16, 2025 am 12:09 AM

Redis's data model and structure include five main types: 1. String: used to store text or binary data, and supports atomic operations. 2. List: Ordered elements collection, suitable for queues and stacks. 3. Set: Unordered unique elements set, supporting set operation. 4. Ordered Set (SortedSet): A unique set of elements with scores, suitable for rankings. 5. Hash table (Hash): a collection of key-value pairs, suitable for storing objects.

Redis: Classifying Its Database ApproachRedis: Classifying Its Database ApproachApr 15, 2025 am 12:06 AM

Redis's database methods include in-memory databases and key-value storage. 1) Redis stores data in memory, and reads and writes fast. 2) It uses key-value pairs to store data, supports complex data structures such as lists, collections, hash tables and ordered collections, suitable for caches and NoSQL databases.

See all articles

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

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software