zl程序教程

您现在的位置是:首页 >  其他

当前栏目

Redis5.0.5 安装与配置

安装配置 Redis5.0
2023-06-13 09:13:42 时间

哎, 本来想的是10.1 回家呢, 结果突然本地多了一例的疫情, 所以只能把票都退了,已经将近一年都没有回家, 思念如泉~, 只能静下心来继续学习, 路漫漫其修远兮吾将上下而求索!

Redis的安装与配置

官网

https://redis.io

下载

访问官网

点击releases page查看全部版本

找到一样的版本下载~

基于Linux安装Redis5.0.5

将安装包上传到Linux

# 安装gcc-c++依赖
yum install gcc-c++
# 解压压缩包
tar -zxvf redis-5.0.5.tar.gz
# 进入目录
cd redis-5.0.5/
# 编译与安装
make && make install
# 创建配置文件目录
mkdir /usr/local/redis -p
# 创建工作空间
mkdir /usr/local/redis/working -p
# 拷贝配置文件
cp redis.conf /usr/local/redis/
# 进入工具目录
cd utils/
# 拷贝初始化脚本
cp redis_init_script /etc/init.d/
# 修改配置文件
vi /usr/local/redis/redis.conf

修改redis.conf

# 修改为守护进程运行
daemonize yes
# 配置工作空间
dir /usr/local/redis/working
# 配置可以被外界访问
bind 0.0.0.0
# 配置密码
requirepass 123456

修改初始化文件

# 进入目录
cd /etc/init.d/
# 修改文件
vi redis_init_script

配置文件

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

# 开机自启动
#chkconfig: 22345 10 90
#description: start and stop redis

# 端口号
REDISPORT=6379
# server执行文件
EXEC=/usr/local/bin/redis-server
# cli执行文件
CLIEXEC=/usr/local/bin/redis-cli
# PID位置
PIDFILE=/var/run/redis_${REDISPORT}.pid
# 配置文件
CONF="/usr/local/redis/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 -a 123456 -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

启动

# 启动
[root@localhost init.d]# ./redis_init_script start
Starting Redis server...
66453:C 06 Sep 2022 23:50:08.712 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
66453:C 06 Sep 2022 23:50:08.712 # Redis version=5.0.5, bits=64, commit=00000000, modified=0, pid=66453, just started
66453:C 06 Sep 2022 23:50:08.712 # Configuration loaded
# 查看服务 已经在6379端口运行了
[root@localhost init.d]# ps -ef|grep redis
root      66454      1  0 23:50 ?        00:00:00 /usr/local/bin/redis-server 0.0.0.0:6379
root      66460  61679  0 23:50 pts/1    00:00:00 grep --color=auto redis
[root@localhost init.d]#

设置开机自启动

# 设置开机自己动
chkconfig redis_init_script on