关于redis:Redis的安装

3次阅读

共计 2485 个字符,预计需要花费 7 分钟才能阅读完成。

筹备 redis 安装包

进入 redis 官网,找到 redis 安装包下载地址,这里咱们抉择文本版本 6.2.4

https://download.redis.io/releases/redis-6.2.4.tar.gz?_ga=2.148749810.415473691.1623143846-237276233.1597318421

linux 零碎中(centos7),通过 wget 下载安装包,如果没有装置 wget 工具,先进行装置

yum install wget

创立 redis 包寄存目录(如 /opt/redis)并进入,执行 wget 下载 redis 安装包

wget https://download.redis.io/releases/redis-6.2.4.tar.gz?_ga=2.148749810.415473691.1623143846-237276233.1597318421

下载实现后进行解压

tar xf redis-6.2.4.tar.gz

解压完的文件中蕴含 redis 源码、工具和装置阐明等文件

编译

咱们首先要将 redis 源码编译成可执行文件能力运行。在上述解压的 readme.md 文件中有具体的编译及装置步骤。
最简略间接的形式是间接运行 make 命令,进入 redis-6.2.4 目录,执行

make

也能够依据须要加一些编译参数,如 make BUILD_TLS=yes 编译反对 tls,make 32bit 编译成 32 位 等,在 readme.md 中有具体阐明。
make 过程中可能会呈现谬误而终止,而后再从新执行 make 编译时须要革除一下编译缓存,保障从新开始

make distclean

编译实现后,会在 src 目录下生成可执行文件 redis-server,执行就能够启动了

./redis-server

redis 是 C 语言开发的,make 编译时应该确保零碎装置 c 语音编译器,如下装置

yum install gcc

make 命令是 linux 下的一个编译调用工具,他会找到当前目录下的 Makefile 文件,依据其内容进行编译。因而 make 之前要先保障生成 Makefile 文件,如果没有须要应用 configure 命令进行生成后再进行编译。

装置

将 redis 装置成零碎服务,后盾运行,缩小人工启动。装置的过程其实是将编译实现的程序 copy 到装置目录下,默认是装置到 /usr/local/bin 目录下,能够指定其余装置目录。进入 redis 源码编译目录,执行

make install PREFIX=/opt/jia/redis6.2.4


装置命令会将 redis 的编译文件 copy 到 /opt/jia/redis6.2.4/bin 目录下。咱们看一下具体的文件列表

这时能够应用 redis-server 脚步启动 redis 服务

./redis-server

应用 make install 命令只会进行二进制文件的装置,不会进行一些脚本初始化及配置之类的操作。在生产环境中咱们个别会将 redis 装置成服务,后盾运行。
redis 提供了 utils 工具来实现服务的装置配置。
执行前咱们先配置一下 Redis 环境变量,指定 redis-server 执行文件门路。

vi /etc/profile
#在最初一行退出 redis 环境变量
export REDIS_HOME=/opt/jia/redis6.2.4
export PATH=$PATH:$REDIS_HOME/bin
#保留文件而后失效配置文件
source /etc/profile

进入 src/utils 目录,执行 install_server.sh 脚本

cd utils
./install_server.sh


图片中咱们看到,装置过程中会为 redis 调配

  • 配置文件 6379.conf 放到 /etc/redis/ 目录下;
  • 日志文件 /var/log/redis_6379.log
  • 数据文件 /var/lib/redis/6379
  • redis 的执行程序指向咱们配置的环境变量目录
  • 设置零碎服务治理 redis。在 /etc/init.d 目录下生成 redis_6379 执行文件,并执行 chkconfig 命令设置服务启动

装置实现后,安装程序会将 redis 服务启动起来, 当初咱们能够应用 service redis 命令查看 redis 服务状态。

# 服务名字要和 init.d 下的文件名统一
service redis_6379 status

单机多实例装置

在一台主机上反对多个 redis 服务装置运行,各实例之间共享同一份安装文件(上文中装置目录 /opt/jia/6.2.4/bin),应用端口号辨别配置文件及数据文件。
运行 install_server.sh 脚本进行装置

Please select the redis port for this instance:[6379] 6380

输出 6380 回车,安装程序主动为新装置实例生成新的 6380 配置文件 / 日志文件 / 数据文件,实现后在 /etc/init.d 目录下会生成一个 redis_6380 可执行文件,应用 service redis_6380 start 启动新实例。

装置过程中呈现的谬误

装置中如果呈现以下谬误

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!

批改 install_server.sh 脚本

#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

从新执行,依照装置提醒回车即可。

正文完
 0