无法连接到MariaDB

时间:2015-07-23 02:12:40

标签: python mysql amazon-web-services mysql-python mariadb

所以我有两个AWS服务器,一个是运行MariaDB,另一个是我的API服务器(基于python)。我可以在MariaDB服务器以及我的开发计算机上本地连接。我无法从API服务器连接,也无法连接第三台AWS服务器。

netstat输出

Proto Recv-Q Send-Q Local Address           Foreign Address         State        PID/Program name
tcp        0      0 *:mysql                 *:*                     LISTEN      1363/mysqld 
API服务器上的

ngrep显示

interface: eth0 (10.[api ip]/255.255.255.0)
filter: (ip or ip6) and ( port 3306 )
##########
Maria Server上的

ngrep

interface: eth0 ([maria ip]/255.255.255.0)
filter: (ip or ip6) and ( port 3306 )
####
T [maria ip]:3306 -> [dev ip]:2392 [AP]
[redacted]                                                                                           
##
T [dev ip]:2392 -> [maria ip]:3306 [AP]
[redacted]
##
T [maria ip]:3306 -> [dev ip]:2392 [AP]
[redacted]                                                                                                
#######################

最终我收到此错误

ERROR 2003 (HY000): Can't connect to MySQL server on '[maria ip]' (110 "Connection timed out")

或来自我的python脚本

Exception happened during processing of request from ('127.0.0.1', 50110)
Traceback (most recent call last):
  File "/usr/lib/python2.7/SocketServer.py", line 295, in _handle_request_noblock
self.process_request(request, client_address)
  File "/usr/lib/python2.7/SocketServer.py", line 321, in process_request
self.finish_request(request, client_address)
  File "/usr/lib/python2.7/SocketServer.py", line 334, in finish_request
self.RequestHandlerClass(request, client_address, self)
  File "/usr/lib/python2.7/SocketServer.py", line 651, in __init__
self.finish()
  File "/usr/lib/python2.7/SocketServer.py", line 710, in finish
self.wfile.close()
  File "/usr/lib/python2.7/socket.py", line 279, in close
self.flush()
  File "/usr/lib/python2.7/socket.py", line 303, in flush
self._sock.sendall(view[write_offset:write_offset+buffer_size])
error: [Errno 32] Broken pipe
----------------------------------------

在有人提到之前,我的IP表设置正确,AWS SecGrps也不是问题。

这不是Trying to connect to remote MySQL host (error 2003)的重复,因为(1)服务器之间没有(逻辑)设备,(2)我可以从我国家另一边的开发站连接,(3) )没有"修复"工作

此外,我可以从API脚本连接到我的maria服务器上运行的Redis Server。

1 个答案:

答案 0 :(得分:-1)

我认为您必须按照以下步骤操作:

  1. 允许在3306端口上的MariaDB AWS服务器上进行远程连接(取决于您的配置)
  2. 检查Maria AWS服务器上的防火墙(安全组 - >入站设置),此服务器必须允许通过3306端口从API服务器的IP地址进行访问。
  3. 检查API AWS服务器上的防火墙(安全组 - > Oubound设置。默认情况下,AWS服务器允许所有端口)。
  4. 参考@ http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/using-network-security.html