linux安装redis

背景

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

root准备

安装依赖

yum  install gcc

安装目录

mkdir /usr/local/redis

授权安装目录

注意,先要新建用户

chown -R redis:redis /usr/local/redis 

安装

切换用户

下载

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

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

安装

tar -zxvf redis-6.0.8.tar.gz
cd redis-6.0.8
make PREFIX=/usr/local/redis
make install

拷贝配置文件

cp /home/redis-6.2.13/redis.conf /usr/local/redis/bin/redis.conf

修改 配置

bind 0.0.0.0
daemonize yes
requirepass 123456

启动

cd /usr/local/redis/bin
./redis-server ./redis.conf

开机自启动

拷贝文件

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

cp redis_init_script /etc/init.d/redis

修改文件

vi /etc/init.d/redis
···
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启动文件

#!/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

你可能感兴趣的:(Linux,运维,linux,redis)