本篇文章给大家主要讲的是关于什么是mysql基于ssl的主从复制的内容,感兴趣的话就一起来看看这篇文章吧,相信看完什么是MysqL基于ssl的主从复制对大家多少有点参考价值吧。
当MysqL/mariadb跨越互联网进行复制时别人可以窃取到MysqL/mariadb的复制信息, 这些信息是明文的, 因此存在不安全性, 这里通过ssl对复制的信息进行加密
1. 创建证书中心
在主云服务器上创建证书中心
cd /etc/pki/CA 生成私钥 (umask 077;openssl genrsa -out private/cakey.pem 2048) 生成自签名证书 openssl req -new -x509 -key /etc/pki/CA/private/cakey.pem -out /etc/pki/CA/cacert.pem -days 7300 创建证书编号 mkdir certs crl newcerts touch index.txt echo 00 > serial
2. 为主云服务器创建证书
云服务器的名称必须固定, 在申请证书时要输入云服务器名称, 这书和云服务器名称对应;
创建私钥 mkdir /usr/lcoal/MysqL/ssl cd /usr/local/MysqL/ssl (umask 077;openssl genrsa -out /etc/MysqL/ssl/master.key 2048) 生成证书申请 openssl req -new -key master.key -out master.csr 在证书云服务器上对master的证书进行签发 openssl ca -in master.csr -out master.crt -days 365
3. 创建从云服务器证书
(umask 077;openssl genrsa -out /etc/MysqL/ssl/slave.key 2048) openssl req -new -key slave.key -out slave.csr 将从云服务器的证书申请文件复制到证书云服务器上进行签发 openssl ca -in slave.csr -out slave.crt -days 365
将证书的公钥cacert.pem复制到主从云服务器的目录下 cd /etc/MysqL/ssl cp /etc/pki/CA/cacert.pem ./ chown -R MysqL.MysqL master.crt master.key cacert.pem chmod 600 master.crt master.key cacert.pem vim /etc/my.cnf log-bin=master-log server-id=1 skip_name_resolve = ON innodb_file_per_table = ON ssl ssl_ca = /etc/MysqL/ssl/cacert.pem ssl_cert = /etc/MysqL/ssl/master.crt ssl_key = /etc/MysqL/ssl/master.key 修改从云服务器配置 cd /etc/MysqL/ssl cp /etc/pki/CA/cacert.pem ./ chown -R MysqL.MysqL slave.crt slave.key cacert.pem chmod 600 slave.crt slave.key cacert.pem vim /etc/my.cnf relay-log=relay-log server-id=2 skip_name_resolve = ON innodb_file_per_table = ON ssl ssl_ca = /etc/MysqL/ssl/cacert.pem ssl_cert = /etc/MysqL/ssl/slave.crt ssl_key = /etc/MysqL/ssl/slave.key
5. 在主服务上创建复制用户
MariaDB [(none)]> GTANT REPLICATION SLAVE,REPLICATION CLIENT ON *.* TO 'repluser'@'10.1.52.%' IDENTIFIED BY 'replpass' REQUIRE SSL; MariaDB [(none)]> FLUSH PRIVILEGES; 查看主云服务器当前二进制位置 MariaDB [(none)]> SHOW MASTER STATUS; +-------------------+----------+--------------+------------------+ | File | Position | binlog_Do_DB | binlog_Ignore_DB | +-------------------+----------+--------------+------------------+ | master-log.000005 | 7918 | | | +-------------------+----------+--------------+------------------+ 1 row in set (0.00 sec)
6. 在从云服务器上开始复制
MariaDB [(none)]> CHANGE MASTER TO -> MASTER_HOST='10.1.52.11', -> MASTER_USER='repluser', -> MASTER_PASSWORD='replpass', -> MASTER_LOG_FILE='master-log.000001', -> MASTER_LOG_POS=495, -> MASTER_SSL=1, -> MASTER_SSL_CA='/etc/MysqL/ssl/cacert.pem', -> MASTER_SSL_CERT='/etc/MysqL/ssl/slave.crt', -> MASTER_SSL_KEY='/etc/MysqL/ssl/slave.key'; MariaDB [(none)]> START SLAVE;
7. 查看从云服务器的状态
MariaDB [(none)]> SHOW SLAVE STATUS\G *************************** 1. row *************************** Slave_IO_State: Waiting for master to send event Master_Host: 10.1.52.11 Master_User: repluser Master_Port: 3306 Connect_Retry: 60 Master_Log_File: master-log.000005 Read_Master_Log_Pos: 7918 Relay_Log_File: relay-log.000002 Relay_Log_Pos: 7940 Relay_Master_Log_File: master-log.000005 Slave_IO_Running: Yes Slave_sql_Running: Yes Replicate_Do_DB: Replicate_Ignore_DB: Replicate_Do_Table: Replicate_Ignore_Table: Replicate_Wild_Do_Table: Replicate_Wild_Ignore_Table: Last_Errno: 0 Last_Error: Skip_Counter: 0 Exec_Master_Log_Pos: 7918 Relay_Log_Space: 8228 Until_Condition: None Until_Log_File: Until_Log_Pos: 0 Master_SSL_Allowed: Yes Master_SSL_CA_File: /etc/MysqL/ssl/cacert.pem Master_SSL_CA_Path: Master_SSL_Cert: /etc/MysqL/ssl/slave.crt Master_SSL_Cipher: Master_SSL_Key: /etc/MysqL/ssl/slave.key Seconds_Behind_Master: 0 Master_SSL_Verify_Server_Cert: No Last_IO_Errno: 0 Last_IO_Error: Last_sql_Errno: 0 Last_sql_Error: Replicate_Ignore_Server_Ids: Master_Server_Id: 1 1 row in set (0.00 sec)
以上关于什么是MysqL基于ssl的主从复制详细内容,对大家有帮助吗?如果想要了解更多相关,可以继续关注我们的行业资讯板块。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。