MariaDB:SSL配置


參考文章:https://blog.csdn.net/johnhill_/article/details/72831932 ,謝謝!

1.安裝openssl

下載地址:http://slproweb.com/products/Win32OpenSSL.html

注意:安裝完成后,記得配置系統path路徑,指到bin目錄。

image

具體路徑請根據個人實際情況調整。

在cmd中,輸入openssl,看到下圖說明成功!

image

2.添加SSL支持

執行:

show variables like '%ssl%';

image

如果have_ssl不等於yes,說明還沒有支持SSL。

添加SSL支持,打開my.ini文件:

[mysqld]
datadir=D:/app/MariaDB 10.3/data
port=3306
innodb_buffer_pool_size=511M
character-set-server=utf8
event_scheduler=ON
max_connections=1000
ssl
ssl-ca=D:/cert/ca-cert.pem
ssl-cert=D:/cert/server-cert.pem
ssl-key=D:/cert/server-key.pem
[client]
port=3306
plugin-dir=D:/app/MariaDB 10.3/lib/plugin

只需要添加標紅行,重啟mariadb服務就行。

重啟之后再次執行看看have_ssl是否等於yes:

show variables like '%ssl%';

3.建立cert目錄

D:\>mkdir cert
D:\>cd cert

4.配置證書

###為注釋,藍色是執行腳本,之下是執行結果

###CA 私鑰
D:\cert>openssl genrsa 2048 > ca-key.pem
Generating RSA private key, 2048 bit long modulus
.........+++++
................................................................................
................................................................................
.........................................................+++++
e is 65537 (0x010001)

###數字證書
D:\cert>openssl req -sha1 -new -x509 -nodes -days 3650 -key ca-key.pem > ca-cert.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) [AU]:CN
State or Province Name (full name) [Some-State]:CN
Locality Name (eg, city) []:CN
Organization Name (eg, company) [Internet Widgits Pty Ltd]:test
Organizational Unit Name (eg, section) []:COM
Common Name (e.g. server FQDN or YOUR name) []:test.COM
Email Address []:test@test.COM

###服務器端的證書請求文件,A challenge password必須為空
D:\cert>openssl req -sha1 -newkey rsa:2048 -days 3650 -nodes -keyout server-key.pem > server-req.pem
Generating a 2048 bit RSA private key
................................................................................
+++++
.....+++++
writing new private key to 'server-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) [AU]:CN
State or Province Name (full name) [Some-State]:CN
Locality Name (eg, city) []:CN
Organization Name (eg, company) [Internet Widgits Pty Ltd]:test
Organizational Unit Name (eg, section) []:COM
Common Name (e.g. server FQDN or YOUR name) []:test.COM
Email Address []:test@test.COM

Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:
An optional company name []:test.COM

###服務器端的RSA私鑰
D:\cert>openssl rsa -in server-key.pem -out server-key.pem
writing RSA key

###服務器端的數字證書
D:\cert>openssl x509 -sha1 -req -in server-req.pem -days 3650 -CA ca-cert.pem -CAkey ca-key.pem -set_serial 01 > server-cert.pem
Signature ok
subject=C = CN, ST = CN, L = CN, O = test, OU = COM, CN = test.COM, emailAddre
ss = test@test.COM
Getting CA Private Key

###客戶端的證書請求文件,A challenge password必須為空
D:\cert>openssl req -sha1 -newkey rsa:2048 -days 3650 -nodes -keyout client-key.pem > 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) [AU]:CN
State or Province Name (full name) [Some-State]:CN
Locality Name (eg, city) []:CN
Organization Name (eg, company) [Internet Widgits Pty Ltd]:test
Organizational Unit Name (eg, section) []:COM
Common Name (e.g. server FQDN or YOUR name) []:test.COM
Email Address []:test@test.COM

Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:
An optional company name []:

###客戶端的RSA私鑰:
D:\cert>openssl rsa -in client-key.pem -out client-key.pem
writing RSA key

###客戶端的數字證書
D:\cert>openssl x509 -sha1 -req -in client-req.pem -days 3650 -CA ca-cert.pem -CAkey ca-key.pem -set_serial 01 > client-cert.pem
Signature ok
subject=C = CN, ST = CN, L = CN, O = test, OU = COM, CN = test.COM, emailAddre
ss = test@test.COM
Getting CA Private Key

image

5.在my.ini中配置證書

[mysqld]
datadir=D:/app/MariaDB 10.3/data
port=3306
innodb_buffer_pool_size=511M
character-set-server=utf8
event_scheduler=ON
max_connections=1000
ssl
ssl-ca=D:/cert/ca-cert.pem ssl-cert=D:/cert/server-cert.pem ssl-key=D:/cert/server-key.pem
[client]
port=3306
plugin-dir=D:/app/MariaDB 10.3/lib/plugin

只需要添加標紅行,重啟mariadb服務就行。再次執行

show variables like '%ssl%';

返回結果:

image

文件說明

ca-cert.pem: CA 證書, 用於生成服務器端/客戶端的數字證書.
ca-key.pem: CA 私鑰, 用於生成服務器端/客戶端的數字證書.
server-key.pem: 服務器端的 RSA 私鑰
server-req.pem: 服務器端的證書請求文件, 用於生成服務器端的數字證書.
server-cert.pem: 服務器端的數字證書.
client-key.pem: 客戶端的 RSA 私鑰
client-req.pem: 客戶端的證書請求文件, 用於生成客戶端的數字證書.
client-cert.pem: 客戶端的數字證書.


免責聲明!

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



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