Loading... <p> <span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:13px;line-height:19.5px;white-space:normal;background-color:#FEFEF2;">telnet 数据库发现不通后 查看vps的端口开放</span> </p> <p> <span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:13px;line-height:19.5px;white-space:normal;background-color:#FEFEF2;"> </span> </p> <pre class="prettyprint lang-js linenums">netstat -antp | grep 3306</pre> <br /> <p> 确认是0.0.0.0监听即可,若是127.0.0.1需要修改mysql配置 </p> <br /> <p> Solution:进入到mysql的配置文件所在目录(/etc/mysql/my.cnf) </p> <p> 找到文件中如下内容: </p> <p> <br /> </p> <pre class="prettyprint lang-js linenums"># Instead of skip-networking the default is now to listen only on # localhost which is more compatible and is not less secure. bind-address = 127.0.0.1 </pre> <pre class="prettyprint lang-js linenums"><span style="font-family:"line-height:1.5;"> 将bind-address注释掉,或者改成客户端主机IP</span></pre> <p> <br /> </p> <p> <br /> </p> <p> 如果是0.0.0.0需要修改防火墙 </p> <p> <span style="font-family:Arial;font-size:14px;line-height:26px;white-space:normal;background-color:#FFFFFF;">添加规则,打开3306端口</span> </p> <ol start="1" class="dp-xml" style="padding:0px;border:none;color:#5C5C5C;font-family:Consolas, "line-height:26px;white-space:normal;margin:0px 0px 1px 45px !important;background-color:#FFFFFF;"> <li class="alt" style="border-left-width:3px;border-style:none none none solid;border-left-color:#6CE26C;list-style:decimal-leading-zero outside;color:inherit;line-height:18px;margin:0px !important;padding:0px 3px 0px 10px !important;"> <span style="margin:0px;padding:0px;border:none;color:black;background-color:inherit;"><span style="margin:0px;padding:0px;border:none;background-color:inherit;">iptables -I INPUT -p tcp -m state --state NEW -m tcp --dport 3306 -j ACCEPT </span></span> </li> </ol> <p> <br /> </p> <p> <span style="font-family:Arial;font-size:14px;line-height:26px;white-space:normal;background-color:#FFFFFF;">查看规则是否生效</span> </p> <ol start="1" class="dp-xml" style="padding:0px;border:none;color:#5C5C5C;font-family:Consolas, "line-height:26px;white-space:normal;margin:0px 0px 1px 45px !important;background-color:#FFFFFF;"> <li class="alt" style="border-left-width:3px;border-style:none none none solid;border-left-color:#6CE26C;list-style:decimal-leading-zero outside;color:inherit;line-height:18px;margin:0px !important;padding:0px 3px 0px 10px !important;"> <span style="margin:0px;padding:0px;border:none;color:black;background-color:inherit;"><span style="margin:0px;padding:0px;border:none;background-color:inherit;">iptables -L -n </span></span> </li> </ol> <p> <br /> </p> <p> <span style="font-family:Arial;font-size:14px;line-height:26px;white-space:normal;background-color:#FFFFFF;">上面使用iptables添加/删除规则都是临时的,如果需要重启也生效,就要保存修改</span> </p> <p> <span style="font-family:Arial;font-size:14px;line-height:26px;white-space:normal;background-color:#FFFFFF;"> </span> </p> <ol start="1" class="dp-xml" style="padding:0px;border:none;color:#5C5C5C;font-family:Consolas, "line-height:26px;white-space:normal;margin:0px 0px 1px 45px !important;background-color:#FFFFFF;"> <li class="alt" style="border-left-width:3px;border-style:none none none solid;border-left-color:#6CE26C;list-style:decimal-leading-zero outside;color:inherit;line-height:18px;margin:0px !important;padding:0px 3px 0px 10px !important;"> <span style="margin:0px;padding:0px;border:none;color:black;background-color:inherit;"><span style="margin:0px;padding:0px;border:none;background-color:inherit;">service iptables save //或者 /etc/init.d/iptables save </span></span> </li> </ol> <span style="font-family:Arial;font-size:14px;line-height:26px;white-space:normal;background-color:#FFFFFF;"> <p> <span style="font-family:Arial;font-size:14px;line-height:26px;white-space:normal;background-color:#FFFFFF;"><span style="font-family:Arial;font-size:14px;line-height:26px;white-space:normal;background-color:#FFFFFF;"><br /> </span></span> </p> <p> <span style="font-family:Arial;font-size:14px;line-height:26px;white-space:normal;background-color:#FFFFFF;"><span style="font-family:Arial;font-size:14px;line-height:26px;white-space:normal;background-color:#FFFFFF;"><br /> </span></span> </p> 例外一种方式也可以实现:</span> <p> <br /> </p> <p> <span style="font-family:Arial;"><span style="font-size:14px;line-height:26px;"> </span></span> </p> <ol start="1" class="dp-xml" style="padding:0px;border:none;color:#5C5C5C;font-family:Consolas, "line-height:26px;white-space:normal;margin:0px 0px 1px 45px !important;background-color:#FFFFFF;"> <li class="alt" style="border-left-width:3px;border-style:none none none solid;border-left-color:#6CE26C;list-style:decimal-leading-zero outside;color:inherit;line-height:18px;margin:0px !important;padding:0px 3px 0px 10px !important;"> <span style="margin:0px;padding:0px;border:none;color:black;background-color:inherit;"><span style="margin:0px;padding:0px;border:none;background-color:inherit;">vi /etc/sysconfig/iptables //打开配置文件 </span></span> </li> </ol> <p> <br /> </p> <p> <span style="font-family:Arial;"><span style="font-size:14px;line-height:26px;"> </span></span> </p> <ol start="1" class="dp-xml" style="padding:0px;border:none;color:#5C5C5C;font-family:Consolas, "line-height:26px;white-space:normal;margin:0px 0px 1px 45px !important;background-color:#FFFFFF;"> <li class="alt" style="border-left-width:3px;border-style:none none none solid;border-left-color:#6CE26C;list-style:decimal-leading-zero outside;color:inherit;line-height:18px;margin:0px !important;padding:0px 3px 0px 10px !important;"> <span style="margin:0px;padding:0px;border:none;color:black;background-color:inherit;"><span style="margin:0px;padding:0px;border:none;background-color:inherit;">-A INPUT -p tcp -m state --state NEW -m tcp --dport 3306 -j ACCEPT //添加这条规则</span></span> </li> </ol> 然后qw <p> <br /> </p> <p> <span style="font-family:Arial;"><span style="font-size:14px;line-height:26px;"> </span></span> </p> <ol start="1" class="dp-xml" style="font-size:14px;line-height:26px;white-space:normal;padding:0px;border:none;font-family:Consolas, "margin:0px 0px 1px 45px !important;background-color:#FFFFFF;"> <li class="alt" style="border-left-width:3px;border-style:none none none solid;border-left-color:#6CE26C;list-style:decimal-leading-zero outside;line-height:18px;margin:0px !important;padding:0px 3px 0px 10px !important;"> service <span style="font-family:Consolas, "line-height:26px;white-space:normal;margin:0px 0px 1px 45px !important;background-color:#FFFFFF;font-size:14px;">ipta</span><span style="font-family:Consolas, "line-height:26px;white-space:normal;margin:0px 0px 1px 45px !important;background-color:#FFFFFF;font-size:14px;">bles restart//重启</span> </li> </ol> <br /> <span style="font-family:Arial;font-size:14px;line-height:26px;white-space:normal;background-color:#FFFFFF;"> <p> <span style="font-family:Arial;font-size:14px;line-height:26px;white-space:normal;background-color:#FFFFFF;"><br /> </span> </p> <br /> </span> <p> <br /> </p> <p> <br /> </p> 最后修改:1970 年 01 月 01 日 © 允许规范转载 打赏 赞赏作者 赞 如果觉得我的文章对你有用,请随意赞赏