1,环境
虚拟机:CentOS 8 (Core)
redis:5.x
防火墙:iptables
2,配置
配置redis.conf
将 bind 127.0.0.1 使用#注释掉,改为# bind 127.0.0.1(bind配置的是允许连接的ip,默认只允许本机连接;若远程连接需注释掉,或改为0.0.0.0)
将 protected-mode yes 改为 protected-mode no(3.2之后加入的新特性,目的是禁止公网访问redis cache,增强redis的安全性)
3,添加iptables规则
iptables -I INPUT 1 -p tcp -m state --state NEW -m tcp --dport 6379 -j ACCEPT
4, 保存
service iptables save
执行这个命令的时候有时候可能会报错:The service command supports only basic LSB actions (start, stop, restart, try-restart, reload, force-reload, status). For other actions, please try to use systemctl.
这是因为没有安装iptables服务,直接使用yum安装iptables服务即可.
yum install iptables-services
安装完成后,重新执行 service iptables save 命令即可保存成功。
5, 配置iptables开机自启
执行如下命令(老版本命令为:service iptables on),设置iptables开机自启
systemctl enable iptables.service
6,重启程序reboot