linux安装redis

背景

项目需要 安装redis,不使用root用户,假设使用redis用户。

root准备

安装依赖

shell 复制代码
yum  install gcc

安装目录

shell 复制代码
mkdir /usr/local/redis

授权安装目录

注意,先要新建用户

shell 复制代码
chown -R redis:redis /usr/local/redis 

安装

切换用户

下载

下载包地址 https://redis.io/download/

也可使用wget下载tar.gz源码包

安装

shell 复制代码
tar -zxvf redis-6.0.8.tar.gz
cd redis-6.0.8
make PREFIX=/usr/local/redis
make install

拷贝配置文件

shell 复制代码
cp /home/redis-6.2.13/redis.conf /usr/local/redis/bin/redis.conf

修改 配置

复制代码
bind 0.0.0.0
daemonize yes
requirepass 123456

启动

shell 复制代码
cd /usr/local/redis/bin
./redis-server ./redis.conf

开机自启动

拷贝文件

启动脚本在源码文件包里 /redis7.0.2/utils/redis_init_script

shell 复制代码
cp redis_init_script /etc/init.d/redis

修改文件

shell 复制代码
vi /etc/init.d/redis
shell 复制代码
···
EXEC=/usr/local/redis/bin/redis-server
CLIEXEC=/usr/local/redis/bin/redis-cli

PIDFILE=/var/run/redis_${REDISPORT}.pid
CONF="/usr/local/redis/bin/redis.conf"
···

修改文件的可执行权:

复制代码
chmod 755 /etc/init.d/redis

redis启动文件

shell 复制代码
#!/bin/sh
#
# Simple Redis init.d script conceived to work on Linux systems
# as it does use of the /proc filesystem.

### BEGIN INIT INFO
# Provides:     redis_6379
# Default-Start:        2 3 4 5
# Default-Stop:         0 1 6
# Short-Description:    Redis data structure server
# Description:          Redis data structure server. See https://redis.io
### END INIT INFO

REDISPORT=6379
EXEC=/usr/local/redis/bin/redis-server
CLIEXEC=/usr/local/redis/bin/redis-cli

PIDFILE=/var/run/redis_${REDISPORT}.pid
CONF="/usr/local/redis/bin/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
                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
相关推荐
Fu2067217 小时前
第一阶段项目
linux·服务器·网络
Flynn Liang11 小时前
AI Agent Redis 生产踩坑实录:13 类故障的根因、复现与调优
数据库·人工智能·redis·缓存·ai agent·故障分析
女神下凡15 小时前
芯参谋(119):凌阳(Sunplus)_开发指南
linux·arm开发·stm32·单片机·嵌入式硬件
落羽的落羽17 小时前
【C++】现代容器: tuple、optional、variant、any、string_view
linux·开发语言·数据结构·c++·人工智能·计算机网络·算法
木子欢儿17 小时前
Ubuntu 26.04 LTS 安装Python 3.12
linux·运维·服务器·python·ubuntu
Flynn Liang18 小时前
RAG 检索性能提升:Redis 向量 + 全文 + 元数据过滤的混合检索实战
数据库·人工智能·redis·缓存·rag·ai agent·智能体
时间的拾荒人18 小时前
Linux 库的制作与使用(下):链接、加载与动态链接原理
linux·运维·动态库·静态库
FlightYe19 小时前
音视频修炼之容器与协议(六):HTTP 协议
android·linux·网络·网络协议·算法·http·音视频
-梅20 小时前
linux(番外)线程,锁,条件变量封装;日志与线程池
linux·c语言·前端·c++