在Centos-linux上下载安装redis

sili-future / 2023-08-11 / 原文

一、下载

参考redis官网提供的操作指南。官网地址https://redis.io/download

创建目录下载压缩包

wget https://download.redis.io/releases/redis-7.0.7.tar.gz

解压

tar xzf redis-7.0.7.tar.gz

二、安装

进入文件夹目录,进行编译(注意:此目录下有redis说明文件“README.md”,有时间了解一下)

cd redis-7.0.7

1.编译

make

编译成功直接启动服务进行验证。

注意:这个如果如果未安装编译工具会报错,需要安装编译工具,在删除redis编译产生的错误文件。安装编译工具的方法

yum install gcc

删除

make distclean

2.验证编译
前往“src”目录下,运行“redis-server”文件

cd src

./redis-server

三、设置系统启动
1.安装redis
路径可以自定义,如果不携带“PREFIX”参数,redis会安装在"/usr/local/bin"目录下。

make install PREFIX=/opt/redis

2.设置环境变量

vi /etc/profile

在末尾追加环境变量,目录与安装redis设置的目录相同。

export REDIS_HONE=/opt/redis
export PATH=$PATH:$REDIS_HOME/bin

CentOS如何配置redis?

使环境变量生效

source /etc/profile

3.创建redis实例
一台服务器可以创建多个端口号不同的redis进程。

cd ../

进入到“utils”目录下(在解压缩的redis目录中)。
使用redis提供的脚本文件,创建redis实例

cd utils
./install_server.sh

注意:

以下错误,通过修改“install_server.sh”文件进行解决。

This systems seems to use systemd.
Please take a look at the provided example service unit files in this directory, and adapt and install them. Sorry!

CentOS如何安装配置redis

vi install_server.sh
注释掉以下区域(7.0.7版本,在76行左右)
#bail if this system is managed by systemd
#_pid_1_exe="$(readlink -f /proc/1/exe)"
#if [ "${_pid_1_exe##*/}" = systemd ]
#then
#       echo "This systems seems to use systemd."
#       echo "Please take a look at the provided example service unit files in this directory, and adapt and install them. Sorry!"
#       exit 1
#fi

创建实例成功,在对应的目录下能看到该实例对应的信息。可以创建多个实例,但是端口号不能相同。