官方安装文档
https://redis.io/docs/getting-started/installation/install-redis-from-source/
1 下载对应版本的redis源码包
redis-6.2.3.tar.gz
链接:https://pan.baidu.com/s/1ep0L4LCsmL4bmRL28ax_zA?pwd=5vd2
提取码:5vd2
2 上传到服务器
上传到usr/local/下
tar -zxvf redis-6.2.3.tar.gz
3 编译安装redis
cd redis-6.2.3
make
make install
[root@iZ8vbdcrmm49bxv7sirrv3Z redis-6.2.3] make install
cd src && make install
make[1]: Entering directory `/usr/local/redis-6.2.3/src'
CC Makefile.dep
make[1]: Leaving directory `/usr/local/redis-6.2.3/src'
make[1]: Entering directory `/usr/local/redis-6.2.3/src'
Hint: It's a good idea to run 'make test' ;)
INSTALL redis-server
INSTALL redis-benchmark
INSTALL redis-cli
make[1]: Leaving directory `/usr/local/redis-6.2.3/src'
4 编辑redis配置文件
先备份原有文件
mv redis.conf redis.conf.bak
再创建一个新的
vim redis.conf
# 启动端口
port 8391
# 密码
requirepass admin
# RDB持久化
save 900 1
save 300 10
save 60 10000
# 持久化压缩
rdbcompression yes
# RDB持久化文件
dbfilename dump.rdb
# 开启AOF
appendonly yes
# 文件名
appendfilename "appendonly.aof"
# 每秒持久化一次(推荐)
appendfsync everysec
5 按照配置文件启动redis
在/usr/local/redis-6.2.3下执行
[root@shanghai redis-6.2.3]# ./src/redis-server ./redis.conf
19181:C 07 Dec 2022 14:51:47.660 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
19181:C 07 Dec 2022 14:51:47.660 # Redis version=6.2.3, bits=64, commit=00000000, modified=0, pid=19181, just started
19181:C 07 Dec 2022 14:51:47.660 # Configuration loaded
19181:M 07 Dec 2022 14:51:47.661 * monotonic clock: POSIX clock_gettime
_._
_.-``__ ''-._
_.-`` `. `_. ''-._ Redis 6.2.3 (00000000/0) 64 bit
.-`` .-```. ```\/ _.,_ ''-._
( ' , .-` | `, ) Running in standalone mode
|`-._`-...-` __...-.``-._|'` _.-'| Port: 8391
| `-._ `._ / _.-' | PID: 19181
`-._ `-._ `-./ _.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' | https://redis.io
`-._ `-._`-.__.-'_.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' |
`-._ `-._`-.__.-'_.-' _.-'
`-._ `-.__.-' _.-'
`-._ _.-'
`-.__.-'
19181:M 07 Dec 2022 14:51:47.662 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
19181:M 07 Dec 2022 14:51:47.662 # Server initialized
19181:M 07 Dec 2022 14:51:47.662 * DB loaded from append only file: 0.000 seconds
19181:M 07 Dec 2022 14:51:47.662 * Ready to accept connections
6 在不同端口启动多个redis
只需要复制redis-6.2.3文件,然后改变配置文件中的端口,分别启动即可
7 外界无法访问问题解决
redis默认安装只能本机连接,外网无法使用,修改配置文件
1、注释掉bind 允许所有ip连接redis
# bind 0.0.0.0
2、注释redis保护模式
# protected-mode yes
3、设置reids密码
requirepass 123456
重启即可