1、下载

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

2、解压

tar -zxvf redis-6.2.4.tar.gz

3、进入目录

cd redis-6.2.4

4、查看README.md,看安装步骤

5、编译

make

这时候如果没有安装c语言的编译环境,就会报错,需要安装一下c的编译环境

Linux下面c的编译使用的是gcc

安装gcc

yum install gcc -y

6、make ,这一步依然会报错,因为刚刚的make已经有了一个编译文件

使用make distclean命令清除刚刚的文件

然后再使用make命令编译

7、把redis安装到指定目录

make install PREFIX=/opt/soft/redis6.0

这时候,我们就能在/opt/soft/redis6.0下面看到一个bin目录,redis的可执行文件都被复制到这里了

8、把redis执行文件加入到path中

vi /etc/profile

在最后一行加入

export REDIS_HOME=/opt/soft/redis6.0

export $PATH=$PATH:$REDIS_HOME/bin

保存退出

:wq

刷新profile文件

source /etc/profile

使用echo $PATH就可以看到redis可执行文件的运行目录

9、安装redis的配置

cd /usr/local/redis-6.2.4/utils

./install_server.sh

这个地方可能会报错

Welcome to the redis service installer

This script will help you easily set up a running redis server

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!

如果出现了这个错误

vi install_server.sh

注释掉下面几行

#_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

保存退出,即可解决问题

继续执行

./install_server.sh

Please select the redis port for this instance: [6379] 让我们选择端口号,我们选择默认,回车继续

一个物理机上面可以启动多个redis,根据端口号区分

Please select the redis config file name [/etc/redis/6379.conf] 让我们选择配置文件地址,我们也选择默认,回车继续,配置文件根据端口号区分

Please select the redis log file name [/var/log/redis_6379.log] 让我们选择日志文件路径,我们也选择默认,回车继续,日志也根据端口号区分

Please select the data directory for this instance [/var/lib/redis/6379] 让我们选择数据目录,我们也选择默认,回车继续,数据目录页是根据端口号区分,虽然redis是内存数据库,但是redis需要持久化,数据就必须要保存到磁盘上面

Please select the redis executable path [/usr/local/bin/redis-server] 选择执行文件,回车继续

Selected config:

Port : 6379

Config file : /etc/redis/6379.conf

Log file : /var/log/redis_6379.log

Data dir : /var/lib/redis/6379

Executable : /usr/local/bin/redis-server

Cli Executable : /usr/local/bin/redis-cli

Is this ok? Then press ENTER to go on or Ctrl-C to abort.

回车继续,或者ctrl+c退出

这里配置完了会自动启动

cd /etc/init.d

ls

这里可以看到一个脚本文件 redis_6379

vi redis_6379可以查看到刚刚设置的目录,端口号,日志等信息

这样就可以在任意位置启动redis了

service redis_6379 status查看端口号是6379的redis状态

Redis is running (28920) 已经启动了,进程号是28920

service redis_6379 start 启动redis,端口6379

service redis_6379 stop 停止端口号为6379 的redis

10、启动多个redis的时候,进入/usr/local/redis-6.2.4/utils

./install_server.sh

选择不同的端口和配置信息就可以了

Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐