Linux离线安装Redis,执行过程详细记录

本文聚焦Linux离线环境下Redis安装,详细阐述准备工作、安装包获取、解压编译、配置启动等全流程,助你顺利完成Redis离线部署。

1. 下载

下载页面见官网
下载程序压缩包:redis-7.4.2.tar.gz

2. 解压编译

解压

1
tar -zxvf redis-7.4.2.tar.gz

进入redis解压目录,执行编译

1
2
cd redis-7.4.2/
make

执行一堆编译过程

1
2
3
.... ....
Hint: It's a good idea to run 'make test' ;)
make[1]: Leaving directory `/chatgis/redis/redis-7.4.2/src'

3. 安装

1
make PREFIX=/chatgis/redis/742 install

执行过程

1
2
3
4
5
Hint: It's a good idea to run 'make test' ;)

INSTALL redis-server
INSTALL redis-benchmark
INSTALL redis-cli

安装后, 在742文件夹多了一个bin文件夹,里面是执行程序, 目录如下:

1
2
3
4
-- redis
---- redis-7.4.2
---- 742
------ bin

4. 配置

复制配置文件:将目录redis-7.4.2 的配置文件redis.conf复制到安装目录。
修改配置文件:使用vim编辑配置文件,进行必要的修改。例如,

  • daemonize选项设置为yes,使 Redis 以守护进程模式运行;
  • bind选项设置为0.0.0.0,允许远程访问;
  • 关闭保护模式,将protected-mode选项设置为no;
  • 设置连接密码,找到requirepass your_password并放开注释,然后设置密码;

5. 启动服务端

1
./bin/redis-server redis.conf

6. 客户端测试

  • 连接
    1
    ./bin/redis-cli -h 127.0.0.1 -p 6379 -a your_password
  • 测试
    1
    2
    3
    4
    5
    6
    7
    8
    127.0.0.1:6379> set name ChatGIS
    OK
    127.0.0.1:6379> get name
    "ChatGIS"
    127.0.0.1:6379> del name
    (integer) 1
    127.0.0.1:6379> get name
    (nil)