Setting up replication using an SSL connection is similar to setting up a server and client using SSL. You will need to obtain (or create) a suitable security certificate that you can use on the master, and a similar certificate (from the same certificate authority) on each slave.
To use SSL for encrypting the transfer of the binary log required during replication you must first set up the master to support SSL network connections. If the master does not support SSL connections (because it has not been compiled or configured for SSL), then replication through an SSL connection will not be possible.
For more information on setting up a server and client for SSL connectivity, see Section 5.5.7.2, “Using SSL Connections”.
To enable SSL on the master you will need to create or obtain
suitable certificates and then add the following configuration
options to the master's configuration within the
mysqld
section:
ssl-ca=cacert.pem
ssl-cert=server-cert.pem
ssl-key=server-key.pem
You should use full path to specify the location of your certificate files.
The options are as follows:
ssl-ca
identifies the Certificate Authority
(CA) certificate.
ssl-cert
identifies the server public key.
This can be sent to the client and authenticated against the
CA certificate that it has.
ssl-key
identifies the server private key.
On the slave, you have two options available for setting the SSL
information. You can either add the slaves certificates to the
client
section of the slave configuration file,
or you can explicitly specify the SSL information using the
CHANGE MASTER TO
statement.
Using the former option, add the following lines to the
client
section of the slave configuration file:
[client] ssl-ca=cacert.pem
ssl-cert=server-cert.pem
ssl-key=server-key.pem
Restart the slave server, using the
--skip-slave
to prevent the slave from
connecting to the master. Use CHANGE MASTER
TO
to specify the master configuration, using the
master_ssl
option to enable SSL connectivity:
mysql> CHANGE MASTER TO \ MASTER_HOST='master_hostname', \ MASTER_USER='replicate', \ MASTER_PASSWORD='password', \ MASTER_SSL=1;
To specify the SSL certificate options during the
CHANGE MASTER TO
command, append
the SSL options:
CHANGE MASTER TO \ MASTER_HOST='master_hostname', \ MASTER_USER='replicate', \ MASTER_PASSWORD='password', \ MASTER_SSL=1, \ MASTER_SSL_CA = 'ca_file_name', \ MASTER_SSL_CAPATH = 'ca_directory_name', \ MASTER_SSL_CERT = 'cert_file_name', \ MASTER_SSL_KEY = 'key_file_name';
Once the master information has been updated, start the slave replication process:
mysql> START SLAVE;
You can use the SHOW SLAVE STATUS
to confirm that SSL connection has been completed.
For more information on the CHANGE MASTER
TO
syntax, see Section 12.6.2.1, “CHANGE MASTER TO
Syntax”.
If you want to enforce SSL connections to be used during
replication, then create a user with the
REPLICATION SLAVE
privilege and use
the REQUIRE_SSL
option for that user. For
example:
mysql> GRANT REPLICATION SLAVE ON *.* -> TO 'repl'@'%.mydomain.com' IDENTIFIED BY 'slavepass' REQUIRE SSL;
User Comments
Add your own comment.