Mysql配置ssl證書


本環境基於mysql5.6配置,通過openssl生成證書進行配置

一、確認環境信息

1、查看數據庫版本

mysql> select version();

+-----------+

| version() |

+-----------+

| 5.6.36 |

+-----------+

 

2、查看數據庫是否支持ssl配置

mysql> show variables like 'have%ssl%';

+---------------+----------+

| Variable_name | Value |

+---------------+----------+

| have_openssl | DISABLED |

| have_ssl | DISABLED |

+---------------+----------+

2 rows in set (0.00 sec)

 

3、查看數據庫端口號

mysql> show variables like 'port';

+---------------+-------+

| Variable_name | Value |

+---------------+-------+

| port | 3306 |

+---------------+-------+

1 row in set (0.00 sec)

 

4、查看數據庫數據存放路徑

mysql> show variables like 'datadir';

+---------------+-------------------+

| Variable_name | Value |

+---------------+-------------------+

| datadir | /data/mysql/data/ |

+---------------+-------------------+

1 row in set (0.00 sec)

 

二、證書配置

通過openssl 制作生成 SSL 證書(有效期99999)

1、生成一個 CA 私鑰

[root@itop ~]#openssl genrsa 2048 > ca-key.pem

 

2、通過 CA 私鑰生成數字證書

[root@itop ~]# openssl req -new -x509 -nodes -days 99999 -key ca-key.pem -out ca.pem

 

3、創建 MySQL 服務器 私鑰和請求證書

[root@itop ~]# openssl req -newkey rsa:2048 -days 99999 -nodes -keyout server-key.pem -out server-req.pem

 

4、將生成的私鑰轉換為 RSA 私鑰文件格式

[root@itop ~]# openssl rsa -in server-key.pem -out server-key.pem

 

5、用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

 

6、創建客戶端的 RSA 私鑰和數字證書

[root@itop ~]# openssl req -newkey rsa:2048 -days 99999 -nodes -keyout client-key.pem -out client-req.pem

 

7、將生成的私鑰轉換為 RSA 私鑰文件格式

[root@itop ~]# openssl rsa -in client-key.pem -out client-key.pem

 

8、用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

 

9、查看所有生成的SSL文件

[root@itop ~]# ll *.pem

 

三、數據庫配置SSL證書

1、復制 CA 證書和服務端SSL文件至MySQL 數據目錄

[root@itop ~]# cp ca.pem server-*.pem /data/mysql/data –v

2、修改 MySQL 數據目錄的CA 證書和服務端 SSL 文件所屬用戶與組

[root@itop ~]# chown -v mysql.mysql /data/mysql/data/{ca,server*}.pem

3、修改MYSQL配置文件,添加SSL調用配置【/etc/my.cnf】

vi /etc/my.cnf

4、重啟MYSQL服務,並檢查數據庫SSL是否開啟狀態

注:have_openssl 與 have_ssl 值都為YES表示ssl開啟成功

[root@itop ~]# /etc/init.d/mysqld restart

mysql> show variables like 'have%ssl%';

 

 

四、測試SSL可用性

1、創建用戶並指定SSL連接

mysql> grant all on *.* to 'test'@'%' identified by 'p@ssw0rd' require SSL;

 

2、通過密碼連接測試

[root@itop ~]# mysql -utest -pp@ssw0rd -h 192.168.1.110

 

3、通過客戶端密鑰與證書SSL + 密碼連接測試,並查看屬性

[root@itop ~]# mysql -utest -pp@ssw0rd -h 192.168.1.110 --ssl-cert=client-cert.pem --ssl-key=client-key.pem

mysql> \s


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM