https://yijiebuyi.com/blog/d8ab4b444c16f42cefe30df738a42518.html

1. brew方式安装

2. 源码编译

2.1 下载源码包

Redis 官网上只提供了源码的安装方式,并非像 MySQL 那样有 dmg 安装包,手动下载源码包,也可以在终端中下载。

  1. $ curl -O https://download.redis.io/releases/redis-6.2.5.tar.gz
  2. $ tar -zxf redis-6.2.5.tar.gz

2.2 编译安装

  1. $ cd redis-6.2.5
  2. $ sudo make
  3. $ sudo make test
  4. $ sudo make isntall

出现报错:

  1. You need tcl 8.5 or newer in order to run the Redis test
  2. make[1]: *** [test] Error 1

解决办法:

  1. $ yum install -y tcl-devel
  2. $ make distclean

编译之后,你会发现 /usr/local/bin/ 下会生成 redis 的执行文件:

  1. ls -l /usr/local/bin | grep redis
  2. -rwxr-xr-x 1 root admin 427248 Aug 6 23:21 redis-benchmark
  3. lrwxr-xr-x 1 root admin 12 Aug 6 23:21 redis-check-aof -> redis-server
  4. lrwxr-xr-x 1 root admin 12 Aug 6 23:21 redis-check-rdb -> redis-server
  5. -rwxr-xr-x 1 root admin 345360 Aug 6 23:21 redis-cli
  6. lrwxr-xr-x 1 root admin 12 Aug 6 23:21 redis-sentinel -> redis-server
  7. -rwxr-xr-x 1 root admin 1835440 Aug 6 23:21 redis-server

完成上述操作后,会在 redis-6.2.5 目录里找到一个 redis.conf 的配置文件,打开编辑此配置文件,找到 dir ./ 这一行配置修改成:

  1. dir /opt/redis

然后将该文件复制到 /etc 目录下:

  1. $ sudo cp redis.conf /etc
  2. $ sudo chmod 777 /etc/redis.conf

3. 启动

  1. $ redis-server /etc/redis.cnf
  2. 21313:C 07 Aug 2021 18:45:23.092 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
  3. 21313:C 07 Aug 2021 18:45:23.092 # Redis version=6.2.5, bits=64, commit=00000000, modified=0, pid=21313, just started
  4. 21313:C 07 Aug 2021 18:45:23.092 # Configuration loaded
  5. 21313:M 07 Aug 2021 18:45:23.093 * Increased maximum number of open files to 10032 (it was originally set to 256).
  6. 21313:M 07 Aug 2021 18:45:23.093 * monotonic clock: POSIX clock_gettime
  7. _._
  8. _.-``__ ''-._
  9. _.-`` `. `_. ''-._ Redis 6.2.5 (00000000/0) 64 bit
  10. .-`` .-```. ```\/ _.,_ ''-._
  11. ( ' , .-` | `, ) Running in standalone mode
  12. |`-._`-...-` __...-.``-._|'` _.-'| Port: 6379
  13. | `-._ `._ / _.-' | PID: 21313
  14. `-._ `-._ `-./ _.-' _.-'
  15. |`-._`-._ `-.__.-' _.-'_.-'|
  16. | `-._`-._ _.-'_.-' | https://redis.io
  17. `-._ `-._`-.__.-'_.-' _.-'
  18. |`-._`-._ `-.__.-' _.-'_.-'|
  19. | `-._`-._ _.-'_.-' |
  20. `-._ `-._`-.__.-'_.-' _.-'
  21. `-._ `-.__.-' _.-'
  22. `-._ _.-'
  23. `-.__.-'
  24. 21313:M 07 Aug 2021 18:45:23.103 # Server initialized
  25. 21313:M 07 Aug 2021 18:45:23.104 * Loading RDB produced by version 6.2.5
  26. 21313:M 07 Aug 2021 18:45:23.104 * RDB age 69238 seconds
  27. 21313:M 07 Aug 2021 18:45:23.104 * RDB memory usage when created 1.01 Mb
  28. 21313:M 07 Aug 2021 18:45:23.104 * DB loaded from disk: 0.001 seconds
  29. 21313:M 07 Aug 2021 18:45:23.104 * Ready to accept connections