linux离线安装redis

一、官网下载

https://redis.io/download
在这里插入图片描述

二、安装 Redis

1、解压

tar -xzvf redis-6.2.3.tar.gz 

2、安装gcc

#由于 redis 是用 C 语言开发,安装之前必先确认是否安装 gcc 环境(gcc -v)
gcc -v

在这里插入图片描述

若无安装gcc,参考我的文章linux离线升级openssh:七、安装gcc

3、编译并安装

cd redis-6.2.3
make
#安装并指定安装目录
make install PREFIX=/opt/redis

三、修改配置

cp /opt/redis-6.2.3/redis.conf /opt/redis/bin
cd /opt/redis/bin
vim redis.conf
#让redis启动后,在linux后台运行
daemonize yes
#绑定IP
bind IP
#添加密码
requirepass 密码
#修改redis的工作目录
dir 工作路径
#记得保存退出

配置文件详细参数:https://www.runoob.com/redis/redis-conf.html

四、启动

#后台启动
 ./redis-server redis.conf

五、设置开机自启

#创建脚本文件
vim /etc/init.d/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=/opt/redis/bin/redis-server
CLIEXEC=/opt/redis/bin/redis-cli

PIDFILE=/var/run/redis_${REDISPORT}.pid
CONF="/opt/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
        ;;
	restart)
        "$0" stop
        sleep 3
        "$0" start
        ;;
    *)
        echo "Please use start or stop as first argument"
        ;;
esac

#授权
chmod 775 /etc/init.d/redis 
#刷新配置
systemctl daemon-reload
#设置开机自启动    
systemctl enable redis
#查询redis状态  
systemctl status redis     
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

twdnote

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值