[英]Droplet cannot connect to external MySQL, Connection refused in Digital Ocean
[英]Digital Ocean connect one droplet to the MySQL DB of another droplet
我有2个液滴,两个液滴都带有LAMP堆栈(Ubuntu 16.04)。 两者均已安装PHPMyAdmin,运行PHP应用程序,并具有自动重定向到https的自签名SSH证书。
我想做的是从Droplet 2上的应用程序连接到Droplet 1上的MySQL数据库。我知道您可以通过在Droplet 1上运行MySQL服务器来做到这一点,但是在这种情况下,两者都需要运行完整的PHP应用程序。
这是我已经完成并尝试的操作:
sudo ufw allow 3306/tcp
将端口3306添加到防火墙, sudo ufw allow 3306/tcp
和sudo service ufw restart
我的PHP应用程序连接设置(CodeIgniter 3.1.7)
$db['remotedb'] = array(
'dsn' => '',
'hostname' => 'PRIVATE IP OF DROPLET HERE', // in the format xx.xx.xx.xx so without https:// in front of it
'port' => 3306,
'username' => 'user',
'password' => 'password',
'database' => 'database',
'dbdriver' => 'mysqli',
'dbprefix' => '',
'pconnect' => FALSE,
'dbdebug' => FALSE,
'cacheon' => FALSE,
'cachedir' => '',
'charset' => 'utf8',
'dbcollat' => 'utf8generalci',
'swappre' => '',
'encrypt' => FALSE,
'compress' => FALSE,
'stricton' => FALSE,
'failover' => array(),
'savequeries' => TRUE
);
当前,Droplet 2上的应用程序无法连接到在Droplet 1上运行的数据库。我缺少什么?
几个问题:
mysql_secure_installation
我已经运行了mysql_secure_installation
。 如果我没有记错的话,那会禁止对mysql数据库的远程访问,但是不确定。 我也不知道如何再次启用它(如果需要)。 编辑运行netstat -nltp
给出
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:22 0.0.0.0:* LISTEN -
tcp 0 0 0.0.0.0:25 0.0.0.0:* LISTEN -
tcp 0 0 127.0.0.1:3306 0.0.0.0:* LISTEN -
tcp6 0 0 :::22 :::* LISTEN -
tcp6 0 0 :::25 :::* LISTEN -
tcp6 0 0 :::443 :::* LISTEN -
tcp6 0 0 :::80 :::* LISTEN -
确保您的my.cnf
文件中具有正确的绑定地址。
bind-address = << private IP here >>
请注意,MySQL仅支持绑定到服务器上的0、1或所有IP地址,因此,如果您不想侦听私有和公共IP,则必须使用私有IP和PHP应用程序的设置在Droplet上连接而不是127.0.0.1
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.