本環境基於mysql5.6配置,經過openssl生成證書進行配置node
一、查看數據庫版本mysql
mysql> select version();sql
+-----------+數據庫
| version() |服務器
+-----------+ide
| 5.6.36 |測試
+-----------+ui
二、查看數據庫是否支持ssl配置3d
mysql> show variables like 'have%ssl%';rest
+---------------+----------+
| Variable_name | Value |
+---------------+----------+
| have_openssl | DISABLED |
| have_ssl | DISABLED |
+---------------+----------+
2 rows in set (0.00 sec)
三、查看數據庫端口號
mysql> show variables like 'port';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| port | 3306 |
+---------------+-------+
1 row in set (0.00 sec)
四、查看數據庫數據存放路徑
mysql> show variables like 'datadir';
+---------------+-------------------+
| Variable_name | Value |
+---------------+-------------------+
| datadir | /data/mysql/data/ |
+---------------+-------------------+
1 row in set (0.00 sec)
經過openssl 製做生成 SSL 證書(有效期99999)
一、生成一個 CA 私鑰
[root@itop ~]#openssl genrsa 2048 > ca-key.pem
二、經過 CA 私鑰生成數字證書
[root@itop ~]# openssl req -new -x509 -nodes -days 99999 -key ca-key.pem -out ca.pem
三、建立 MySQL 服務器 私鑰和請求證書
[root@itop ~]# openssl req -newkey rsa:2048 -days 99999 -nodes -keyout server-key.pem -out server-req.pem
四、將生成的私鑰轉換爲 RSA 私鑰文件格式
[root@itop ~]# openssl rsa -in server-key.pem -out server-key.pem
五、用CA 證書來生成一個服務器端的數字證書
[root@itop ~]# openssl x509 -req -in server-req.pem -days 99999 -CA ca.pem -CAkey ca-key.pem -set_serial 01 -out server-cert.pem
六、建立客戶端的 RSA 私鑰和數字證書
[root@itop ~]# openssl req -newkey rsa:2048 -days 99999 -nodes -keyout client-key.pem -out client-req.pem
七、將生成的私鑰轉換爲 RSA 私鑰文件格式
[root@itop ~]# openssl rsa -in client-key.pem -out client-key.pem
八、用CA 證書來生成一個客戶端的數字證書
[root@itop ~]# openssl x509 -req -in client-req.pem -days 99999 -CA ca.pem -CAkey ca-key.pem -set_serial 01 -out client-cert.pem
九、查看全部生成的SSL文件
[root@itop ~]# ll *.pem
一、複製 CA 證書和服務端SSL文件至MySQL 數據目錄
[root@itop ~]# cp ca.pem server-*.pem /data/mysql/data –v
二、修改 MySQL 數據目錄的CA 證書和服務端 SSL 文件所屬用戶與組
[root@itop ~]# chown -v mysql.mysql /data/mysql/data/{ca,server*}.pem
三、修改MYSQL配置文件,添加SSL調用配置【/etc/my.cnf】
vi /etc/my.cnf
四、重啓MYSQL服務,並檢查數據庫SSL是否開啓狀態
注:have_openssl 與 have_ssl 值都爲YES表示ssl開啓成功
[root@itop ~]# /etc/init.d/mysqld restart
mysql> show variables like 'have%ssl%';
一、建立用戶並指定SSL鏈接
mysql> grant all on . to 'test'@'%' identified by 'p@ssw0rd' require SSL;
二、經過密碼鏈接測試
[root@itop ~]# mysql -utest -pp@ssw0rd -h 192.168.1.110
三、經過客戶端密鑰與證書SSL + 密碼鏈接測試,並查看屬性
[root@itop ~]# mysql -utest -pp@ssw0rd -h 192.168.1.110 --ssl-cert=client-cert.pem --ssl-key=client-key.pem
mysql> \s