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
相关推荐
曦夜日长2 小时前
Git系统篇,Git本地使用(一):从“究极进化版“到三个区域的底层原理
大数据·linux·git·elasticsearch
shimly1234562 小时前
给断网无 sudo ubuntu22.04 机器安装 nodejs
linux
行百里er3 小时前
Redis 完结篇——Redis 热点问题在 Spring Boot 项目中实战
redis·后端
别动我齐刘海4 小时前
Linux 系统调试学习1
linux·运维·服务器·c++·学习·机器学习·机器人
Lsetea4 小时前
OpenSSL报certificate chain too long:error 22与verify_depth深度排查
linux·https·ssl证书·openssl·证书链
不像程序员的程序媛5 小时前
linux常见文本操作命令
linux·运维·服务器
wangbing11255 小时前
开发指南149-IotDB-常用命令
linux·运维·iotdb
看着博客敲代码5 小时前
WorkBuddy 接上 Kali MCP 做自动化渗透:信息收集到初步验证的落地记录
linux·人工智能·安全·网络安全·自动化
小HANN7 小时前
华为云企业网站上云实战|从零搭建高可用WordPress全站架构(ECS+RDS+ELB+弹性伸缩+云监控闭环)
linux·运维·服务器·经验分享
星恒随风7 小时前
Linux库的底层原理:ELF文件格式、静态链接、程序加载、虚拟地址空间与GOT/PLT详解
linux·运维·笔记·学习·状态模式