Redis 官网上只提供了源码的安装方式,并非像 MySQL 那样有 dmg 安装包,手动下载源码包,也可以在终端中下载。
$ curl -O https://download.redis.io/releases/redis-6.2.5.tar.gz
$ tar -zxf redis-6.2.5.tar.gz
编译安装:
$ cd redis-6.2.5
$ sudo make
$ sudo make test
$ sudo make isntall
出现报错:
You need tcl 8.5 or newer in order to run the Redis test
make[1]: *** [test] Error 1
解决办法:
$ sudo apt install -y tcl-dev
$ make distclean
编译之后,你会发现 /usr/local/bin/
下会生成 redis 的执行文件:
❯ ls -l /usr/local/bin | grep redis
-rwxr-xr-x 1 root admin 427248 Aug 6 23:21 redis-benchmark
lrwxr-xr-x 1 root admin 12 Aug 6 23:21 redis-check-aof -> redis-server
lrwxr-xr-x 1 root admin 12 Aug 6 23:21 redis-check-rdb -> redis-server
-rwxr-xr-x 1 root admin 345360 Aug 6 23:21 redis-cli
lrwxr-xr-x 1 root admin 12 Aug 6 23:21 redis-sentinel -> redis-server
-rwxr-xr-x 1 root admin 1835440 Aug 6 23:21 redis-server
完成上述操作后,会在 redis-6.2.5 目录里找到一个 redis.conf
的配置文件,打开编辑此配置文件,找到 dir ./
这一行配置修改成:
dir /home/yumingmin/redisdb
然后将该文件复制到 /etc
目录下:
$ sudo cp redis.conf /etc
$ sudo chmod 777 /etc/redis.conf
启动:
$ redis-server /etc/redis.cnf
21313:C 07 Aug 2021 18:45:23.092 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
21313:C 07 Aug 2021 18:45:23.092 # Redis version=6.2.5, bits=64, commit=00000000, modified=0, pid=21313, just started
21313:C 07 Aug 2021 18:45:23.092 # Configuration loaded
21313:M 07 Aug 2021 18:45:23.093 * Increased maximum number of open files to 10032 (it was originally set to 256).
21313:M 07 Aug 2021 18:45:23.093 * monotonic clock: POSIX clock_gettime
_._
_.-``__ ''-._
_.-`` `. `_. ''-._ Redis 6.2.5 (00000000/0) 64 bit
.-`` .-```. ```\/ _.,_ ''-._
( ' , .-` | `, ) Running in standalone mode
|`-._`-...-` __...-.``-._|'` _.-'| Port: 6379
| `-._ `._ / _.-' | PID: 21313
`-._ `-._ `-./ _.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' | https://redis.io
`-._ `-._`-.__.-'_.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' |
`-._ `-._`-.__.-'_.-' _.-'
`-._ `-.__.-' _.-'
`-._ _.-'
`-.__.-'
21313:M 07 Aug 2021 18:45:23.103 # Server initialized
21313:M 07 Aug 2021 18:45:23.104 * Loading RDB produced by version 6.2.5
21313:M 07 Aug 2021 18:45:23.104 * RDB age 69238 seconds
21313:M 07 Aug 2021 18:45:23.104 * RDB memory usage when created 1.01 Mb
21313:M 07 Aug 2021 18:45:23.104 * DB loaded from disk: 0.001 seconds
21313:M 07 Aug 2021 18:45:23.104 * Ready to accept connections