Redis安装
#1.安装
sudo dnf install redis -y#2.启动 + 开机自启
sudo systemctl enable --now redis#3. 查看状态
systemctl status redis#4. 测试 Redis 是否运行
redis-cli
set hello world
get hello
配置文件
#修改配置文件
vi /etc/redis.conf
#修改如下,protected-mode保护模式开启时无法远程连接,
protected-mode no
bind 0.0.0.0
requirepass <强密码>#重启redis服务
sudo systemctl restart redis#查看密码
cat /etc/redis.conf | grep requirepass
| 配置项 | 含义 |
|---|---|
| bind 127.0.0.1 | 只允许本地访问(生产慎改) |
| protected-mode yes | 开保护模式 |
| requirepass xxx | 设置密码 |
| daemonize yes | 后台运行(systemd 下一般不用动) |
当满足以下任意条件时,Redis 会自动启用protected-mode保护机制:
1. 没有设置密码(requirepass)
2. 没有绑定到 localhost(比如用了 bind 0.0.0.0)
3. 实例可能被外部访问
放行6379端口
#放行端口
sudo firewall-cmd --add-port=6379/tcp --permanent
sudo firewall-cmd --reload