MySQL master-slave replication uses SSL encryption

Source: Internet
Author: User

Environment:
CentOS7.4
CA host One
MySQL host two
Database: MariaDB-5.5 First, prepare the certificate file

1. Generate a CA self-signed certificate

mkdir /etc/my.cnf.d/sslcd /etc/my.cnf.d/sslopenssl genrsa 2048 > cakey.pemchmod 600 cakey.pemopenssl req -new -x509 -key cakey.pem -days 3650 -out cacert.pem


2. Generate Master private key and certificate request

openssl req -newkey rsa:2048 -days 365 -nodes -keyout master.key > master.csr

3. Issue a certificate to master

openssl x509  -req  -in master.csr -CA cacert.pem -CAkey cakey.pem  -set_serial 01 > master.crt

4. Generate slave private key and certificate request

openssl req -newkey rsa:2048 -days 365 -nodes -keyout slave.key > slave.csr


5. Issuing certificates to Slave

openssl x509  -req  -in slave.csr -CA cacert.pem -CAkey cakey.pem -set_serial 02 > slave.crt


6. Distribute the certificate files to master and slave separately
Master:


Slave:

Second, the main library configuration

#修改/etc/my.cnf
#添加ssl等配置信息

Create a copy user from the library and allow only encrypted connections over SSL:

mysql> grant replication slave on *.* to ‘repluser‘@‘192.168.1.%‘ identified by ‘mysql‘ require ssl;
Third, from the library configuration

#修改/etc/my.cnf
#添加ssl等配置信息

To configure the connection main Library information:

change master to master_host=‘192.168.1.2‘,master_user=‘repluser‘,master_password=‘mysql‘,master_log_file=‘mariadb-bin.000001‘,master_log_pos=245,master_ssl=1;start slave;show slave status\G

Iv. test master/Slave synchronization

MySQL master-slave replication uses SSL encryption

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.