* 用CA 证书来生成一个服务器端的数字证书
[root@MySQL ~]# openssl x509 -req -in server-req.pem -days 3600 \
> -CA ca.pem -CAkey ca-key.pem -set_serial 01 -out server-cert.pem
Signature ok
subject=/C=XX/L=Default City/O=Default Company Ltd
Getting CA Private Key
* 创建客户端的 RSA 私钥和数字证书
[root@MySQL ~]# openssl req -newkey rsa:2048 -days 3600 \
> -nodes -keyout client-key.pem -out client-req.pem
Generating a 2048 bit RSA private key
..........................................................+++
.................+++
writing new private key to 'client-key.pem'
-----
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [XX]:
State or Province Name (full name) []:
Locality Name (eg, city) [Default City]:
Organization Name (eg, company) [Default Company Ltd]:
Organizational Unit Name (eg, section) []:
Common Name (eg, your name or your server's hostname) []:
Email Address []:
Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:
An optional company name []:
* 将生成的私钥转换为 RSA 私钥文件格式
[root@MySQL ~]# openssl rsa -in client-key.pem -out client-key.pem
writing RSA key
* 用CA 证书来生成一个客户端的数字证书
[root@MySQL ~]# openssl x509 -req -in client-req.pem -days 3600 \
> -CA ca.pem -CAkey ca-key.pem -set_serial 01 -out client-cert.pem
Signature ok
subject=/C=XX/L=Default City/O=Default Company Ltd
Getting CA Private Key
* 查看所有生成的SSL文件
[root@MySQL ~]# ls -l *.pem
-rw-r--r-- 1 root root 1675 Jun 24 14:16 ca-key.pem
-rw-r--r-- 1 root root 1220 Jun 24 14:19 ca.pem
-rw-r--r-- 1 root root 1090 Jun 24 14:29 client-cert.pem
-rw-r--r-- 1 root root 1679 Jun 24 14:28 client-key.pem
-rw-r--r-- 1 root root 952 Jun 24 14:28 client-req.pem
-rw-r--r-- 1 root root 1090 Jun 24 14:24 server-cert.pem
-rw-r--r-- 1 root root 1679 Jun 24 14:23 server-key.pem
-rw-r--r-- 1 root root 952 Jun 24 14:20 server-req.pem
6. MySQL 配置启动 SSL
* 复制 CA 证书和服务端SSL文件至MySQL 数据目录
[root@MySQL ~]# cp ca.pem server-*.pem /data/mysql_data -v
`ca.pem' -> `/data/mysql_data/ca.pem'
`server-cert.pem' -> `/data/mysql_data/server-cert.pem'
`server-key.pem' -> `/data/mysql_data/server-key.pem'
`server-req.pem' -> `/data/mysql_data/server-req.pem'
* 修改 MySQL 数据目录的CA 证书和服务端 SSL 文件所属用户与组
[root@MySQL ~]# chown -v mysql.mysql /data/mysql_data/{ca,server*}.pem
changed ownership of `/data/mysql_data/ca.pem' to mysql:mysql
changed ownership of `/data/mysql_data/server-cert.pem' to mysql:mysql
changed ownership of `/data/mysql_data/server-key.pem' to mysql:mysql
changed ownership of `/data/mysql_data/server-req.pem' to mysql:mysql
* 配置 MySQL 服务的配置文件 [/etc/my.cnf]
[mysqld]
ssl-ca=/data/mysql_data/ca.pem
ssl-cert=/data/mysql_data/server-cert.pem
ssl-key=/data/mysql_data/server-key.pem
* 重启MySQL服务
[root@MySQL ~]# /etc/init.d/mysqld restart
Shutting down MySQL.. SUCCESS!
Starting MySQL. SUCCESS!
* 登陆查看SSL开启状态
have_openssl 与 have_ssl 值都为YES表示ssl开启成功
mysql> show variables like 'have%ssl%';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| have_openssl | YES |
| have_ssl | YES |
+---------------+-------+
2 rows in set (0.01 sec)