Mysql – Is it possible to have MySQL slave outside firewall

MySQLreplication

For various reasons I need one of the databases from intranet MySQL server to be made available to (insecure) online server. Due to the requirements it was decided that a db dump will be used via cron to transfer data as the firewall does not allow any connections to be initiated from outside. Then MySQL Master-Slave solution was suggested. From what I have understood, the slave should be able to connect to the master via (preferably insecure) TCP protocol. Such a solution is preferable, however, via secure TCP connections without permitting the slave to initiate (possibly lost) connections to the master.

I would like to know if it is possible to have Master-Slave replication via secure TCP where connections are always initiated by the Master to the slave. The use case does not require too much data transfer, and data base size is within 5GB on a 1GBPS intranet. It is acceptable that there could be some delay in updating to the slave.

Best Answer

Rather than exposing your database's ports to the public network at all, I would recommend arranging for the services to be able to see each other by more secure means.

The SSH tunnel option already mentioned will work, though for reliability you'd want to look into making sure that the tunnel remained active after a network blip or other event (look into autossh, or hooking your SSH tunnel into init/systemd).

I would instead recommend a "proper" VNP solution. OpenVPN is common (available in just about all Linux distributions' standard repositories) and easy enough to setup (IMO), though there are many other options. If you setup a point-to-point VPN between the two hosts (or a more general arrangement if more machines need to take part) then the database instances will be able to connect to each other securely over that without needing to be exposed to the outside world.