[iyunv@node1 ~]# touch /etc/pki/CA/index.txt [iyunv@node1 ~]# echo 01 >/etc/pki/CA/serial[iyunv@node1 ~]# cd /etc/pki/CA/[iyunv@node1 CA]# (umask 066; openssl genrsa -out /etc/pki/CA/private/cakey.pem 2048) #创建CA所需秘钥[iyunv@node1 CA]# openssl req -new -x509 -key private/cakey.pem -out cacert.pem -days 36500 #生成自签名证书(…………此处略去N行)-----Country Name (2 letter code) [XX]:CNState or Province Name (full name) []:BeiJingLocality Name (eg, city) [Default City]:BeiJing Organization Name (eg, company) [Default Company Ltd]:ITOrganizational Unit Name (eg, section) []:OPTCommon Name (eg, your name or your server's hostname) []:node1.magedu.comEmail Address []:
2、为node1(172.16.69.66)节点签发证书
[iyunv@node1 ~]# mkdir /etc/my.cnf.d/ssl[iyunv@node1 ~]# cd /etc/my.cnf.d/ssl/[iyunv@node1 ssl]# mkdir /etc/my.cnf.d/ssl[iyunv@node1 ssl]# (umask 077;openssl genrsa -out /etc/my.cnf.d/ssl/node1.key 2048) #生成申请证书所需秘钥[iyunv@node1 CA]# openssl req -new -key /etc/my.cnf.d/ssl/node1.key -days 36500 -out /etc/my.cnf.d/ssl/node1.csr #生成证书申请文件(…………此处略去N行)-----Country Name (2 letter code) [XX]:CNState or Province Name (full name) []:BeiJingLocality Name (eg, city) [Default City]:BeiJingOrganization Name (eg, company) [Default Company Ltd]:ITOrganizational Unit Name (eg, section) []:OPTCommon Name (eg, your name or your server's hostname) []:node1.magedu.comEmail Address []:Please enter the following 'extra' attributesto be sent with your certificate requestA challenge password []:An optional company name []: [iyunv@node1 ssl]# cd /etc/my.cnf.d/ssl/[iyunv@node1 ssl]# openssl ca -in node1.csr -out master.crt -days 36500 #CA为申请主机签署证书Using configuration from /etc/pki/tls/openssl.cnfCheck that the request matches the signatureSignature okCertificate Details: Serial Number: 1 (0x1) Validity Not Before: Feb 23 12:48:02 2017 GMT Not After : Jan 30 12:48:02 2117 GMT Subject: countryName = CN stateOrProvinceName = BeiJing organizationName = IT organizationalUnitName = OPT commonName = node1.magedu.com X509v3 extensions: X509v3 Basic Constraints: CA:FALSE Netscape Comment: OpenSSL Generated Certificate X509v3 Subject Key Identifier: 86:11:7C:13:93:64:6E:9A:9B:A6:E4:ED:34:1E:55:04:D1:D2:D1:AE X509v3 Authority Key Identifier: keyid:57:A8:09:4A:FB:C4:39:30:F8:01:19:08:7F:EC:46:FD:81:38:DF:C6Certificate is to be certified until Jan 30 12:48:02 2117 GMT (36500 days)Sign the certificate? [y/n]:y1 out of 1 certificate requests certified, commit? [y/n]yWrite out database with 1 new entriesData Base Updated
3、分别为Slave服务器生成证书请求
(1)为node2(172.16.69.99)生成证书请求
[iyunv@node2 ~]# mkdir /etc/my.cnf.d/ssl[iyunv@node2 ~]# cd /etc/my.cnf.d/ssl[iyunv@node2 ssl]# ls[iyunv@node2 ssl]# (umask 077;openssl genrsa -out /etc/my.cnf.d/ssl/node2.key 2048) #生成申请证书所需秘钥[iyunv@node2 ssl]# openssl req -new -key /etc/my.cnf.d/ssl/node2.key -days 36500 -out /etc/my.cnf.d/ssl/node2.csr #生成证书申请文件(…………此处略去N行)-----Country Name (2 letter code) [XX]:CNState or Province Name (full name) []:BeiJingLocality Name (eg, city) [Default City]:BeiJingOrganization Name (eg, company) [Default Company Ltd]:ITOrganizational Unit Name (eg, section) []:OPTCommon Name (eg, your name or your server's hostname) []:node2.magedu.comEmail Address []:Please enter the following 'extra' attributesto be sent with your certificate requestA challenge password []:An optional company name []:
[iyunv@node3 ssl]# (umask 077;openssl genrsa -out /etc/my.cnf.d/ssl/node3.key 2048) [iyunv@node3 ssl]# (umask 077;openssl^Cenrsa -out /etc/my.cnf.d/ssl/node3.key 2048) [iyunv@node3 ssl]# openssl req -new -key /etc/my.cnf.d/ssl/node3.key -days 36500 -out /etc/my.cnf.d/ssl/node3.csr (…………此处略去N行)-----Country Name (2 letter code) [XX]:CNState or Province Name (full name) []:BeiJingLocality Name (eg, city) [Default City]:BeiJing Organization Name (eg, company) [Default Company Ltd]:IT Organizational Unit Name (eg, section) []:OPTCommon Name (eg, your name or your server's hostname) []:node3.magedu.comEmail Address []:Please enter the following 'extra' attributesto be sent with your certificate requestA challenge password []:An optional company name []:
[iyunv@node1 ~]# chown -R mysql.mysql /etc/my.cnf.d/ssl/[iyunv@node1 ~]# ll /etc/my.cnf.d/ssl/total 20-rw-r--r-- 1 mysql mysql 1326 Feb 23 23:17 cacert.pem-rw-r--r--. 1 mysql mysql 4457 Feb 23 20:49 node1.crt-rw-r--r--. 1 mysql mysql 1005 Feb 23 20:40 node1.csr-rw-------. 1 mysql mysql 1675 Feb 23 20:25 node1.key[iyunv@node2 ~]# chown -R mysql.mysql /etc/my.cnf.d/ssl/[iyunv@node2 ~]# ll /etc/my.cnf.d/ssl/total 20-rw-r--r-- 1 mysql mysql 1326 Feb 23 23:19 cacert.pem-rw-r--r--. 1 mysql mysql 4457 Feb 23 21:25 node2.crt-rw-r--r--. 1 mysql mysql 1005 Feb 23 21:03 node2.csr-rw-------. 1 mysql mysql 1679 Feb 23 20:59 node2.key[iyunv@node3 ssl]# chown -R mysql.mysql /etc/my.cnf.d/ssl/[iyunv@node3 ~]# ll /etc/my.cnf.d/ssl/total 20-rw-r--r-- 1 mysql mysql 1326 Feb 23 23:19 cacert.pem-rw-r--r--. 1 mysql mysql 4457 Feb 23 21:25 node3.crt-rw-r--r--. 1 mysql mysql 1005 Feb 23 21:05 node3.csr-rw-------. 1 mysql mysql 1679 Feb 23 21:00 node3.key
MariaDB [(none)]> CREATE DATABASE hellodb;Query OK, 1 row affected (0.00 sec)MariaDB [(none)]> SHOW DATABASES; +--------------------+| Database |+--------------------+| information_schema || hellodb || mysql || performance_schema || test |+--------------------+5 rows in set (0.00 sec)
2、在slave服务器node2、node3上验证
MariaDB [(none)]> SHOW DATABASES;+--------------------+| Database |+--------------------+| information_schema || hellodb || mysql || performance_schema || test |+--------------------+5 rows in set (0.00 sec)