我使用以下脚本为MySQL配置了SSL。
#!/bin/bash
#
mkdir -p /root/abc/ssl_certs
cd /root/abc/ssl_certs
#
echo "--> 1. Create CA cert, private key"
openssl genrsa 2048 > ca-key.pem
echo "--> 2. Create CA cert, certificate"
openssl req -new -x509 -nodes -days 1000 -key ca-key.pem > ca-cert.pem
echo "--> 3. Create Server certificate, key"
openssl req -newkey rsa:2048 -days 1000 -nodes -keyout server-key.pem > server-req.pem
echo "--> 4. Create Server certificate, cert"
openssl x509 -req -in server-req.pem -days 1000 -CA ca-cert.pem -CAkey ca-key.pem -set_serial 01 > server-cert.pem
echo ""
echo
echo ""
echo "--> 5. Create client certificate, key. Use DIFFERENT common name then server!!!!"
echo ""
openssl req -newkey rsa:2048 -days 1000 -nodes -keyout client-key.pem > client-req.pem
echo "6. Create client certificate, cert"
openssl x509 -req -in client-req.pem -days 1000 -CA ca-cert.pem -CAkey ca-key.pem -set_serial 01 > client-cert.pem
exit 0
创建了以下文件:
ca-key.pem ca-cert.pem
server-req.pem server-key.pem server-cert.pem
client-req.pem client-key.pem client-cert.pem
然后,我将server-cert.pem和client-cert.pem合并到ca.pem中(我读了一篇文章来做..)
我在MySQL中创建了一个ssl用户:
GRANT ALL ON *.* to sslsuer@hostname IDENTIFIED BY 'pwd' REQUIRE SSL;
接下来,我在my.cnf中添加了以下内容
[mysqld]
ssl-ca = /root/abc/ssl_certs/ca.pem
ssl-cert = /root/abc/ssl_certs/server-cert.pem
ssl-key = /root/abc/ssl_certs/server-key.pem
重新启动服务器后,我连接到mysql,但仍未使用SSL :(
mysql -u ssluser -p
SSL: Not in use
甚至have_ssl参数仍然显示为禁用。.:(
mysql> show variables like '%ssl%';
+---------------+---------------------------------------------+
| Variable_name | Value |
+---------------+---------------------------------------------+
| have_openssl | DISABLED |
| have_ssl | DISABLED |
| ssl_ca | /root/abc/ssl_certs/ca.pem |
| ssl_capath | |
| ssl_cert | /root/abc/ssl_certs/server-cert.pem |
| ssl_cipher | |
| ssl_key | /root/abc/ssl_certs/server-key.pem |
+---------------+---------------------------------------------+
我错过了任何步骤,还是出了什么问题?
详细漏掉步骤的答案将不胜感激。
mysql --ssl --help
同样不要忘记对my.cnf进行这些修改后重新启动mysql
mysql --ssl -u ssluser -p
在客户端上强制使用SSL。之后,您可以确定为什么REQUIRE SSL无法使用。