master 端
配置CA和证书
[root@baseos-1_192.168.31.140 ~ ]
[root@baseos-1_192.168.31.140 CA ]
***
[root@baseos-1_192.168.31.140 CA ]
***
Common Name (eg, your name or your server's hostname) []:master
***
[root@baseos-1_192.168.31.140 CA ]
[root@baseos-1_192.168.31.140 CA ]
[root@baseos-1_192.168.31.140 CA ]
[root@baseos-1_192.168.31.140 CA ]
[root@web4399_smsmq_121.14.36.73 ssl ]
Generating RSA private key, 2048 bit long modulus
.........+++
...........................................................................+++
e is 65537 (0x10001)
[root@baseos-1_192.168.31.140 ssl ]
***
Common Name (eg, your name or your server's hostname) []:master
***
[root@baseos-1_192.168.31.140 ssl ]
***
Sign the certificate? [y/n ]:y
***
1 out of 1 certificate requests certified, commit? [y/n ]y
Write out database with 1 new entries
Data Base Updated
[root@baseos-1_192.168.31.140 ssl ]
total 12
-rw-r--r-- 1 root root 3614 Jun 27 16 :22 master.crt
-rw-r--r-- 1 root root 623 Jun 27 16 :15 master.csr
-rw------- 1 root root 891 Jun 27 16 :15 master.key
[root@baseos-1_192.168.31.140 ssl ]
chown -R mysql:mysql /data/ssl/master*
[root@baseos-1_192.168.31.140 ssl ]
至此,证书生成完毕,如果签发证书时,遇到如下错误:
[root@baseos -1 _192.168 .31 .140 ssl]# openssl ca - in master.csr - out master.crt - days 3650
Using configuration from / etc/ pki/ tls/ openssl.cnf
Check that the request matches the signature
Signature ok
The mandatory stateOrProvinceName field was missing
修改openssl 配置文件:
[root@baseos-1 _192.168 .31 .140 ssl]# vim /etc/pki/tls/openssl.cnf
***
stateOrProvinceName = optional
organizationName = optional
***
配置mysql
[root@baseos-1_192.168 .31.140 ssl]# vim /etc/my.cnf
ssl
ssl -ca=/data /ssl/cacert.pem
ssl -cert=/data /ssl/master.crt
ssl -key=/data /ssl/master.key
重启MySQL之后,查看SSL是否生效
(root@localhost) [(none)] show variables like '%ssl%' ;
+---------------+----------------------+
| Variable_name | Value |
+---------------+----------------------+
| have_openssl | YES |
| have_ssl | YES |
| ssl_ca | /data/ssl/cacert.pem |
| ssl_capath | |
| ssl_cert | /data/ssl/master.crt |
| ssl_cipher | |
| ssl_crl | |
| ssl_crlpath | |
| ssl_key | /data/ssl/master.key |
+---------------+----------------------+
9 rows in set (0.07 sec)
将证书传递的slave端,并授权
[root@baseos-1_192.168.31.140 ssl ]# scp -P 22-o StrictHostKeyChecking=no -r cacert.pem master.crt master.key 192.168.31.130:/data/ssl/
[root@baseos-1_192.168.31.140 ssl ]# mysql -uroot -p
(root@localhost) [(none)] grant replication slave,replication client on *.* to 'slave_user' @'192.168.31.130' identified by 'slave12346' require X509;
Query OK, 0 rows affected (0.00 sec )
slave 端
[root@baseos-2_192.168 .31.130 ~]
[root@baseos-2_192.168 .31.130 ~]
(root@localhost) [(none)] stop slave;
Query OK, 0 rows affected (0 .00 sec)
(root@localhost) [(none)] CHANGE MASTER TO MASTER_LOG_FILE='mysql-bin.000022' , MASTER_LOG_POS=120 , MASTER_HOST = "192.168.31.140" , MASTER_USER = "slave_user" , master_password = "slave12346" ,
master_ssl=1 ,master_ssl_ca='/data/ssl/cacert.pem' , master_ssl_cert='/data/ssl/master.crt' , master_ssl_key='/data/ssl/master.key' ;
Query OK, 0 rows affected, 2 warnings (0 .01 sec)
(root@localhost) [(none)] start slave;
Query OK, 0 rows affected (0 .01 sec)
(root@localhost) [(none)] show slave status \G;
*************************** 1 . row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 192.168 .31.140
Master_User: slave_user
Master_Port: 3306
***
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
***
Master_SSL_Allowed: Yes
Master_SSL_CA_File: /data/ssl /cacert.pem
Master_SSL_CA_Path:
Master_SSL_Cert: /da ta/ssl/master.crt
Master_SSL_Cipher:
Master_SSL_Key: /data/ssl /master.key
***
1 row in set (0 .00 sec)
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
· DeepSeek在M芯片Mac上本地化部署
· 葡萄城 AI 搜索升级:DeepSeek 加持,客户体验更智能