search
HomeDatabaseRedisHow to install and run Redis as a non-root user under CentOS7

1、基本环境信息

1.1、环境信息

序号 ID 版本
1 操作系统 CentOS7
2 redis 5.0.12



1.2、redis下载地址

redis下载地址:

我们这里使用的是5.0.12


2、安装

2.1、新建redis普通用户

1)、使用root登录我们的系统

2)、新建组:groupadd redisgroup

3)、新建用户:useradd -g redisgroup redis

4)、设置密码:passwd redis 自己输入密码即可

groupadd redisgroupuseradd -g redisgroup redispasswd redis

How to install and run Redis as a non-root user under CentOS7

2.2、上传安装包并解压

1)、使用root用户,新建目录:mkdir -p /usr/local/src/redis

2)、解压压缩包:tar -zxvf redis-5.0.12.tar.gz

如下:

mkdir -p /usr/local/src/redistar -zxvf redis-5.0.12.tar.gz

How to install and run Redis as a non-root user under CentOS7

2.3、新建目录

切换到redis用户并在其目录下创建一个名为redis的文件夹

mkdir rediscd redismkdir datamkdir etc

2.4、编译并安装

使用root用户操作

1)、编译:cd redis-5.0.12

make

2)、安装:

make install PREFIX=/home/redis/redis

How to install and run Redis as a non-root user under CentOS7

3、配置

3.1、将配置文件复制到redis用户下面

1)、将/usr/local/src/redis/redis-5.0.12下的redis.conf文件复制到/home/redis/redis/etc目录下

2)、如果复制不了就用root赋权限,chmod 777 redis.conf

3)、复制过来之后,改一下文件的所属组和用户

chown redis redis.confchgrp redisgroup redis.conf

3.2、配置Redis的配置文件

修改配置文件我们主要修改三个地方:

1)、修改为后台运行

2)、修改支持其他机器连接

下面的三个键值,直接在配置文件中修改即可

# yes-后台模式运行,no-前台模式运行,默认daemonize yes# 下面的这里给注释掉,默认是放开的#bind 127.0.0.1# 下面的这个值改为no,默认是yesprotected-mode no

4、编写启动脚本,并启动

4.1、编写管理脚本

1)、使用redis用户登录,我们在用户目录下新建一个目录bin

2)、在bin目录下新建一个redctl脚本,并授予可执行的权限,chmod a+x redisctl

3)、将~/bin目录加到用户的环境变量中去

修改用户目录下的.bash_profile文件,在倒数第二行增加

PATH=$PATH:~/bin

完整内容如下:

# .bash_profile# Get the aliases and functionsif [ -f ~/.bashrc ]; then. ~/.bashrcfi# User specific environment and startup programsPATH=$PATH:$HOME/.local/bin:$HOME/bin

PATH=$PATH:~/binexport PATH

编写的redctl脚本,支持redis启动,停止,重启以及状态查看,详细内容如下:

  • redctl

#!/bin/bash#check paramif [ $# -lt 1 ]; thenecho "USAGE: redctl start|stop|restart|status"exit 8fipid=0
ACTION=$1REDIS_HOME=$HOME/redis# Here define some functiongetpid(){pid=`ps -ef | grep redis-server | grep -v grep |awk '{print $2}'`}start(){getpidif [ ! -n "$pid" ]; thencd $REDIS_HOME/bin
        ./redis-server ../etc/redis.conf
        getpidif [ ! -n "$pid" ]; thenecho "redis-server start failed, please check your commond"elseecho "redis-server start success, PID: $pid"fielseecho "redis-server is running PID: $pid"fi}stop(){getpidif [ ! -n "$pid" ]; thenecho "redis-server is not running"elsekill -9 $pidecho "redis-server has been stopped"fi}restart(){stopsleep 1s
    start}status(){getpidif [ ! -n "$pid" ]; thenecho "redis-server is not running"elseecho "redis-server is running PID: $pid"fi}case $ACTION instart) start;;stop) stop;;restart) restart;;status) status;;*) echo "require start|stop|restart|status" ;;esac

4.2、启动服务并验证

依次执行,启动,查看状态,重启,停止,命令如下:

redctl start

redctl status

redctl restart

redctl stop

How to install and run Redis as a non-root user under CentOS7

我们再次执行一下启动命令,将redis服务启动起来,

使用redis-cli连接上,尝试设置一些值,并查看所设置的值,如下:

表示成功

How to install and run Redis as a non-root user under CentOS7

5、可能遇到的问题

5.1、未安装gcc g++包

未安装gcc g++包的话,请自行安装

yum install -y gcc g++

The above is the detailed content of How to install and run Redis as a non-root user under CentOS7. 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 vs databases: performance comparisonsRedis vs databases: performance comparisonsMay 14, 2025 am 12:11 AM

Redisoutperformstraditionaldatabasesinspeedforread/writeoperationsduetoitsin-memorynature,whiletraditionaldatabasesexcelincomplexqueriesanddataintegrity.1)Redisisidealforreal-timeanalyticsandcaching,offeringphenomenalperformance.2)Traditionaldatabase

When Should I Use Redis Instead of a Traditional Database?When Should I Use Redis Instead of a Traditional Database?May 13, 2025 pm 04:01 PM

UseRedisinsteadofatraditionaldatabasewhenyourapplicationrequiresspeedandreal-timedataprocessing,suchasforcaching,sessionmanagement,orreal-timeanalytics.Redisexcelsin:1)Caching,reducingloadonprimarydatabases;2)Sessionmanagement,simplifyingdatahandling

Redis: Beyond SQL - The NoSQL PerspectiveRedis: Beyond SQL - The NoSQL PerspectiveMay 08, 2025 am 12:25 AM

Redis goes beyond SQL databases because of its high performance and flexibility. 1) Redis achieves extremely fast read and write speed through memory storage. 2) It supports a variety of data structures, such as lists and collections, suitable for complex data processing. 3) Single-threaded model simplifies development, but high concurrency may become a bottleneck.

Redis: A Comparison to Traditional Database ServersRedis: A Comparison to Traditional Database ServersMay 07, 2025 am 12:09 AM

Redis is superior to traditional databases in high concurrency and low latency scenarios, but is not suitable for complex queries and transaction processing. 1.Redis uses memory storage, fast read and write speed, suitable for high concurrency and low latency requirements. 2. Traditional databases are based on disk, support complex queries and transaction processing, and have strong data consistency and persistence. 3. Redis is suitable as a supplement or substitute for traditional databases, but it needs to be selected according to specific business needs.

Redis: Introduction to a Powerful In-Memory Data StoreRedis: Introduction to a Powerful In-Memory Data StoreMay 06, 2025 am 12:08 AM

Redisisahigh-performancein-memorydatastructurestorethatexcelsinspeedandversatility.1)Itsupportsvariousdatastructureslikestrings,lists,andsets.2)Redisisanin-memorydatabasewithpersistenceoptions,ensuringfastperformanceanddatasafety.3)Itoffersatomicoper

Is Redis Primarily a Database?Is Redis Primarily a Database?May 05, 2025 am 12:07 AM

Redis is primarily a database, but it is more than just a database. 1. As a database, Redis supports persistence and is suitable for high-performance needs. 2. As a cache, Redis improves application response speed. 3. As a message broker, Redis supports publish-subscribe mode, suitable for real-time communication.

Redis: Database, Server, or Something Else?Redis: Database, Server, or Something Else?May 04, 2025 am 12:08 AM

Redisisamultifacetedtoolthatservesasadatabase,server,andmore.Itfunctionsasanin-memorydatastructurestore,supportsvariousdatastructures,andcanbeusedasacache,messagebroker,sessionstorage,andfordistributedlocking.

Redis: Unveiling Its Purpose and Key ApplicationsRedis: Unveiling Its Purpose and Key ApplicationsMay 03, 2025 am 12:11 AM

Redisisanopen-source,in-memorydatastructurestoreusedasadatabase,cache,andmessagebroker,excellinginspeedandversatility.Itiswidelyusedforcaching,real-timeanalytics,sessionmanagement,andleaderboardsduetoitssupportforvariousdatastructuresandfastdataacces

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 Article

Hot Tools

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),