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
相关推荐
深紫色的三北六号6 小时前
Linux 服务器磁盘扩容与目录迁移:rsync + bind mount 实现服务无感迁移(无需修改配置)
linux·扩容·服务迁移
SudosuBash10 小时前
[CS:APP 3e] 关于对 第 12 章 读/写者的一点思考和题解 (作业 12.19,12.20,12.21)
linux·并发·操作系统(os)
哈基咪怎么可能是AI20 小时前
为什么我就想要「线性历史 + Signed Commits」GitHub 却把我当猴耍 🤬🎙️
linux·github
十日十行2 天前
Linux和window共享文件夹
linux
木心月转码ing2 天前
WSL+Cpp开发环境配置
linux
崔小汤呀3 天前
最全的docker安装笔记,包含CentOS和Ubuntu
linux·后端
何中应3 天前
vi编辑器使用
linux·后端·操作系统
何中应3 天前
Linux进程无法被kill
linux·后端·操作系统
何中应3 天前
rm-rf /命令操作介绍
linux·后端·操作系统
何中应3 天前
Linux常用命令
linux·操作系统