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
相关推荐
zhixingheyi_tian2 分钟前
Linux/Windows 免密登录
linux·运维·服务器
Arthas2178 分钟前
互联网大厂Java面试实录:谢飞机的电商微服务之旅 - Spring Boot/Cloud/Redis/Kafka实战
spring boot·redis·spring cloud·微服务·kafka·java面试·电商
IAtlantiscsdn10 分钟前
Redis面试题总结
数据库·redis·缓存
尤老师FPGA23 分钟前
petalinux制作linux系统flash+sd卡启动
linux·运维·服务器
蓝天居士28 分钟前
Linux实用功能代码集(4) —— 线程间消息队列(2)
linux
Name_NaN_None43 分钟前
Linux 使用 Remmina 连接 Windows 远程桌面 ——「小白教程」
linux·网络·电脑·远程工作
shepherd11144 分钟前
别再无脑 cat 了!后端排查 GB 级生产日志的实战命令
linux·后端
剪刀石头布Cheers1 小时前
Ubuntu安装向日葵远程黑屏
linux·运维·ubuntu
Vect__1 小时前
基于CSAPP深刻理解编译链接过程
linux·c++