ubuntu安装lnmp后开启mysql,redis远程访问

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_21682469/article/details/80367003

lnmp集成安装后,即使关闭了服务器防火墙,mysql依然不能远程连接。因为lnmp默认添加了iptables规则,禁止了远程访问3306,6379端口。

root@iZjr5oba73m1ygZ:/usr/local/nginx/conf# iptables -L -n
Chain INPUT (policy ACCEPT)
target     prot opt source               destination
ACCEPT     all  --  0.0.0.0/0            0.0.0.0/0
ACCEPT     all  --  0.0.0.0/0            0.0.0.0/0            state RELATED,ESTABLISHED
ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0            tcp dpt:22
ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0            tcp dpt:80
ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0            tcp dpt:443
DROP       tcp  --  0.0.0.0/0            0.0.0.0/0            tcp dpt:3306
ACCEPT     icmp --  0.0.0.0/0            0.0.0.0/0            icmptype 8
DROP       tcp  --  0.0.0.0/0            0.0.0.0/0            tcp dpt:6379

通过命令可以看出,3306,6379端口的target状态是DROP的。如果需要开启远程访问,则需要将该状态设为ACCEPT,然后重启防火墙。

因为在ubuntu中我使用service iptables restart找不到服务。因此我大胆的使用了iptables --flush命令,删除了所有的iptables-rule;

root@iZjr5oba73m1ygZ:/usr/local/nginx/conf# iptables --flush
root@iZjr5oba73m1ygZ:/usr/local/nginx/conf# iptables -L -n
Chain INPUT (policy ACCEPT)
target     prot opt source               destination

Chain FORWARD (policy ACCEPT)
target     prot opt source               destination

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination

可见,iptables规则列表已经被我清空了,mysql也连接成功。

同样,redis也可以远程连接成功。

猜你喜欢

转载自blog.csdn.net/qq_21682469/article/details/80367003