我无法连接到远程服务器上的 mysql

我无法连接到远程服务器上的 mysql

我正在尝试使用 mysql 从 Ubuntu 服务器连接到 RHEL6 服务器。我尝试telnet进入服务器并尝试连接 mysql。我尝试注释掉 bind-address,但也没有成功。我没有收到错误代码或任何内容telnet。它在一分钟左右后就失败了。使用 mysql,我收到此错误代码ERROR 2003 (HY000): Can't connect to MySQL server on 'SERVER_IP' (111)。“SERVER_IP”当然是一个占位符,实际错误会给出实际 IP。

我已经包含了我的 my.cnf 以及来自目标服务器的 iptables。

在目标服务器上...

我的.cnf:

[mysqld]
bind-address=0.0.0.0
tmp_table_size=512M
max_heap_table_size=512M
sort_buffer_size=32M
read_buffer_size=128K
read_rnd_buffer_size=256K
table_cache=2048
key_buffer_size=512M
thread_cache_size=50
query_cache_type=1
query_cache_size=256M
query_cache_limit=24M
#query_alloc_block_size=128
#query_cache_min_res_unit=128
innodb_log_buffer_size=16M
innodb_flush_log_at_trx_commit=2
innodb_file_per_table
innodb_log_files_in_group=2
innodb_buffer_pool_size=32G
innodb_log_file_size=512M
innodb_additional_mem_pool_size=20M
join_buffer_size=128K

max_allowed_packet=100M
max_connections=256
wait_timeout=28800
interactive_timeout=3600

# modify isolation method for faster inserting.
# Do not uncomment the line below unless you understand what this does.
# transaction-isolation = READ-COMMITTED
# do not reverse lookup clients
skip-name-resolve

#long_query_time=6
#log_slow_queries=/var/log/mysqld-slow.log
#log_queries_not_using_indexes=On
#log_slow_admin_statements=On

datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
user=mysql
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0

#Added by Magento ECG
long_query_time=1
slow_query_log

[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid

iptables:

:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
-A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
-A INPUT -p icmp -j ACCEPT
-A INPUT -i lo -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 225 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp -i eth1 --dport 11211 -j ACCEPT
-A INPUT -j REJECT --reject-with icmp-host-prohibited
-A FORWARD -j REJECT --reject-with icmp-host-prohibited
COMMIT

命令netstat -ntpl

Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address               Foreign Address             State       PID/Program name
tcp        0      0 0.0.0.0:3306                0.0.0.0:*                   LISTEN      -
tcp        0      0 0.0.0.0:11211               0.0.0.0:*                   LISTEN      -
tcp        0      0 0.0.0.0:2123                0.0.0.0:*                   LISTEN      -
tcp        0      0 0.0.0.0:1581                0.0.0.0:*                   LISTEN      -
tcp        0      0 0.0.0.0:22                  0.0.0.0:*                   LISTEN      -
tcp        0      0 127.0.0.1:25                0.0.0.0:*                   LISTEN      -
tcp        0      0 :::11211                    :::*                        LISTEN      -
tcp        0      0 :::22                       :::*                        LISTEN      -
tcp        0      0 :::225                      :::*                        LISTEN      -

sshd_配置:

Protocol 2
SyslogFacility AUTHPRIV
PasswordAuthentication yes
ChallengeResponseAuthentication no
GSSAPIAuthentication yes
GSSAPICleanupCredentials yes
UsePAM yes
AcceptEnv LANG LC_CTYPE LC_NUMERIC LC_TIME LC_COLLATE LC_MONETARY LC_MESSAGES
AcceptEnv LC_PAPER LC_NAME LC_ADDRESS LC_TELEPHONE LC_MEASUREMENT
AcceptEnv LC_IDENTIFICATION LC_ALL LANGUAGE
AcceptEnv XMODIFIERS
X11Forwarding yes
Subsystem       sftp    /usr/libexec/openssh/sftp-server

答案1

应该可以正常工作。我要检查的第一件事是确保您的本地计算机(尝试连接到 MySQL 框的计算机)可以通过该端口与任何计算机建立出站连接。

这些是本地的吗?还是在不同的网络上?它们之间有防火墙吗?

看起来像是需要更多信息的那种问题。

答案2

首先,您需要确保您自己的 iptables 不会对此问题负责。尝试将日志记录添加到您的 iptables 脚本中:

-A INPUT -m state --state NEW -m tcp -p tcp -i eth1 --dport 11211 -j ACCEPT
-A INPUT -j LOG --log-prefix "DROPPED BY MY IPTABLES"
-A INPUT -j REJECT --reject-with icmp-host-prohibited

这样,您将获得哪些数据包被丢弃以及哪些数据包被接受的日志,您将知道是否是您的防火墙造成的。

编辑:改为双引号以避免错误

相关内容