CentOS下配置redis允许远程连接 日期:2024-09-23 人气:472 ### 配置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的安全性) 将 requirepass foobared 注释去掉,foobared为密码,也可修改为别的值(可选,建议设置) ### 设置iptables规则,允许外部访问6379端口 iptables -I INPUT 1 -p tcp -m state --state NEW -m tcp --dport 6379 -j ACCEPT 临时生效,重启后失效。 #### iptables永久生效 1. 添加iptables规则 ``` iptables -I INPUT 1 -p tcp -m state --state NEW -m tcp --dport 6379 -j ACCEPT ``` 2. 保存 ``` 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 命令即可保存成功。 3. 配置iptables开机自启 保存后重启依然没有生效,后百度得知,需要设置iptables开机自启才可使配置生效。 执行如下命令(老版本命令为:service iptables on),设置iptables开机自启 ``` systemctl enable iptables.service ``` >注意 需关闭firewalld防火墙 systemctl stop firewalld.service systemctl disable firewalld.service ### 启动redis,并指定配置文件 ./redis-server ../redis.conf 标签: iptables redis firewalld 上一篇:vscode使用Community Server Connector运行JDK1.8项目报错 下一篇:龙舌兰酒 随便看看 2025-07-04 vscode使用Community Server Connector运行JDK1.8项目报错 2025-07-03 vscode中为maven项目指定java版本 2025-06-27 利用puppeteer将网页保存为pdf 2025-06-27 一天二十四时辰表 2025-06-27 家谱中儿子和父母的关系有哪些? 留言