redis单机安装

源码安装

源码地址:

Index of /releases/http://download.redis.io/releases/

复制代码
# wget http://download.redis.io/releases/redis-6.0.8.tar.gz
如果服务没办法联网,则自己手动下载上传服务器也是一样的
# tar -xzvf redis-6.0.8.tar.gz
# cd redis-6.0.8
# make

执行完 make 命令后,redis-6.0.8 的 src 目录下会出现编译后的 redis 服务程序 redis-server,还有用于测试的客户端程序 redis-cli:

下面启动 redis 服务:

复制代码
# cd src
# ./redis-server

注意这种方式启动 redis 使用的是默认配置。也可以通过启动参数告诉 redis 使用指定配置文件使用下面命令启动。

复制代码
# cd src
# ./redis-server ../redis.conf

redis.conf 是一个默认的配置文件。我们可以根据需要使用自己的配置文件。

启动 redis 服务进程后,就可以使用测试客户端程序 redis-cli 和 redis 服务交互了。 比如:

复制代码
# cd src
# ./redis-cli
redis> set foo bar
OK
redis> get foo
"bar"

rpm安装

Redis 下载 (APK, DEB, PKG, RPM, TGZ, TXZ, XBPS, XZ, ZST)https://pkgs.org/download/redis

下载并上传rpm文件

cd到redis rpm文件目录,执行

rpm -ivh *.rpm

创建redis.conf文件

复制代码
daemonize yes
port 7000 
bind 10.11.76.41 
pidfile /opt/can/redis/redis.pid
dir /opt/can/redis/ 
masterauth can@123456
requirepass can@123456
appendonly yes   
protected-mode no
dbfilename dump-7000.rdb
rdbcompression yes
rdbchecksum yes
tcp-backlog 511
tcp-keepalive 60
repl-disable-tcp-nodelay yes
timeout 1300
loglevel notice
logfile /opt/can/redis/redis.log
maxmemory 2G
maxmemory-policy allkeys-lru 

#cluster-enabled yes
#cluster-config-file /opt/can/redis/nodes.conf
#cluster-node-timeout 15000
#cluster-require-full-coverage no
  1. daemonize yes:

    • 将 Redis 作为守护进程在后台运行。
  2. port 7000:

    • Redis 监听的端口号为 7000。
  3. bind 10.11.76.41:

    • 绑定到指定的 IP 地址(10.11.76.41),只接受来自该 IP 地址的连接。
  4. pidfile /opt/can/redis/redis.pid:

    • 指定保存 Redis 进程 ID (PID) 的文件路径。
  5. dir /opt/can/redis/:

    • 设置工作目录,即 Redis 存储持久化文件(如 RDB 快照和 AOF 日志)的目录。
  6. masterauth can@123456:

    • 设置主节点的认证密码,用于从节点连接主节点时进行身份验证。
  7. requirepass can@123456:

    • 设置客户端连接 Redis 时的认证密码。
  8. appendonly yes:

    • 启用 AOF(Append Only File)持久化方式,将每次写操作记录到文件中。
  9. protected-mode no:

    • 关闭受保护模式,允许没有设置密码的远程连接。
  10. dbfilename dump-7000.rdb:

    • 设置 RDB 快照文件的名称。
  11. rdbcompression yes:

    • 启用 RDB 文件压缩。
  12. rdbchecksum yes:

    • 启用 RDB 文件校验和,以确保数据完整性。
  13. tcp-backlog 511:

    • 设置 TCP 连接队列的最大长度。
  14. tcp-keepalive 60:

    • 设置 TCP keepalive 选项,以秒为单位。
  15. repl-disable-tcp-nodelay yes:

    • 禁用 Nagle 算法,减少延迟。
  16. timeout 1300:

    • 设置客户端连接超时时间,单位为秒。
  17. loglevel notice:

    • 设置日志级别为 notice。
  18. logfile /opt/can/redis/redis.log:

    • 指定日志文件的路径。
  19. maxmemory 2G:

    • 设置 Redis 使用的最大内存为 2GB。
  20. maxmemory-policy allkeys-lru:

    • 当达到最大内存限制时,使用 LRU(Least Recently Used)策略删除键值对。
  21. #cluster-enabled yes:

    • 启用集群模式(被注释掉,表示当前未启用)。
  22. #cluster-config-file /opt/can/redis/nodes.conf:

    • 指定集群配置文件的路径(被注释掉,表示当前未启用)。
  23. #cluster-node-timeout 15000:

    • 设置集群节点超时时间为 15000 毫秒(被注释掉,表示当前未启用)。
  24. #cluster-require-full-coverage no:

    • 设置是否要求集群中的所有主节点都有从节点(被注释掉,表示当前未启用)。

找到redis服务文件,默认在cd /etc/systemd/system/下

指定conf路径

使用sudo systemctl start redis启动服务

使用sudo systemctl enable redis 设置自启动

相关推荐
集成显卡1 小时前
PlayWright | 初识微软出品的 WEB 应用自动化测试框架
前端·chrome·测试工具·microsoft·自动化·edge浏览器
前端小趴菜052 小时前
React - 组件通信
前端·react.js·前端框架
Amy_cx2 小时前
在表单输入框按回车页面刷新的问题
前端·elementui
dancing9992 小时前
cocos3.X的oops框架oops-plugin-excel-to-json改进兼容多表单导出功能
前端·javascript·typescript·游戏程序
陈阿土i2 小时前
SpringAI 1.0.0 正式版——利用Redis存储会话(ChatMemory)
java·redis·ai·springai
后海 0_o3 小时前
2025前端微服务 - 无界 的实战应用
前端·微服务·架构
Scabbards_3 小时前
CPT304-2425-S2-Software Engineering II
前端
小满zs3 小时前
Zustand 第二章(状态处理)
前端·react.js
bing_1583 小时前
跨多个微服务使用 Redis 共享数据时,如何管理数据一致性?
redis·微服务·mybatis
程序猿小D3 小时前
第16节 Node.js 文件系统
linux·服务器·前端·node.js·编辑器·vim