IP地址白名單
組複製插件具有一個配置選項,用於確定從哪些主機可以接受傳入的組通信連接。此選項稱爲group_replication_ip_whitelist。如果在服務器s1上設置此選項,則當服務器s2正在建立與s1的連接以便進行組通信時,s1在接受s2傳過來的連接之前,首先會檢查白名單。如果s2在白名單中,則s1接受連接,否則s1拒絕s2的連接嘗試。
如果未配置任何白名單,則服務器會自動將白名單設置爲服務器具有接口的專用網絡。這意味着,即使服務器具有公共IP上的接口,也不會默認允許來自外部主機的連接。 每當IP白名單設置爲AUTOMATIC時,在這種情況下可以發出錯誤日誌中的條目,類似於:
2016-07-07T06:40:49.320686Z 4 [Note] Plugin group_replication reported: 'Added automatically \\
IP ranges 10.120.40.237/18,10.178.59.44/22,127.0.0.1/8 to the whitelist'
您可以通過手動設置允許進行組通信連接的IP地址列表來進一步提高組的安全性。可以使用CIDR表示法或簡單的IP地址來指定列表。逗號必須分隔每個條目。例如:
mysql> STOP GROUP_REPLICATION;
mysql> SET GLOBAL group_replication_ip_whitelist="10.120.40.237/18,10.178.59.44/22,127.0.0.1/8";
mysql> START GROUP_REPLICATION;
本地主機IP地址(127.0.0.1)始終添加到白名單中。如果沒有明確,它是隱式和自動添加。
SSL支持
MySQL組複製支持MySQL服務器的OpenSSL和YaSSL構建。
組通信的連接以及恢復的連接使用SSL進行保護。以下部分說明如何配置連接。
Configuring SSL for Recovery
通過常規異步複製連接執行恢復。一旦選擇了複製源,則連接器建立異步複製連接。這都是自動的。
但是,需要SSL連接的用戶必須在連接器連接到施主之前創建。通常,這是在服務器準備加入組時設置的。
donor> SET SQL_LOG_BIN=0;
donor> CREATE USER 'rec_ssl_user'@'%' REQUIRE SSL;
donor> GRANT replication slave ON *.* TO 'rec_ssl_user'@'%';
donor> SET SQL_LOG_BIN=1;
假設組中的所有服務器都有一個複製用戶設置爲使用SSL,您可以配置爲在成員加入到複製源時使用這些憑證。這是根據爲組複製插件提供的SSL選項的值完成的。
new_member> SET GLOBAL group_replication_recovery_use_ssl=1;
new_member> SET GLOBAL group_replication_recovery_ssl_ca= '.../cacert.pem';
new_member> SET GLOBAL group_replication_recovery_ssl_cert= '.../client-cert.pem';
new_member> SET GLOBAL group_replication_recovery_ssl_key= '.../client-key.pem';
並通過將恢復通道配置爲使用需要SSL連接的用戶的憑據。
new_member> CHANGE MASTER TO MASTER_USER="rec_ssl_user" FOR CHANNEL "group_replication_recovery";
new_member> START GROUP_REPLICATION;
Configuring SSL for Group Communication
安全套接字可用於在組中的成員之間建立通信。此配置取決於服務器的SSL配置。因此,如果服務器配置了SSL,則組複製插件也配置了SSL。有關配置服務器SSL的選項的詳細信息,請參見第7.4.5節“安全連接的命令選項”。配置組複製的選項如下表所示。
Server Configuration |
Plugin Configuration Description |
ssl_key |
Path of key file. To be used as client and server certificate. |
ssl_cert |
Path of certificate file. To be used as client and server certificate. |
ssl_ca |
Path of file with SSL CAs that are trusted. |
ssl_capath |
Path of directory containing certificates for SSL CAs that are trusted. |
ssl_crl |
Path of file containing the certificate revocation lists. |
ssl_crlpath |
Path of directory containing revoked certificate lists files. |
ssl_cipher |
Permitted ciphers to use while encrypting data over the connection. |
tls_version |
Secure communication will use this version and its protocols. |
這些選項是組配置所依賴的MySQL服務器配置選項。此外,還有以下特定於組複製的選項,用於在插件本身上配置SSL。
group_replication_ssl_mode
- 指定組複製成員之間的連接的安全狀態
Value |
Description |
DISABLED |
Establish an unencrypted connection (default). |
REQUIRED |
Establish a secure connection if the server supports secure connections. |
VERIFY_CA |
Like REQUIRED, but additionally verify the server TLS certificate against the configured Certificate Authority (CA) certificates. |
VERIFY_IDENTITY |
Like VERIFY_CA, but additionally verify that the server certificate matches the host to which the connection is attempted. |
以下示例顯示了用於在服務器上配置SSL的示例my.cnf文件部分以及如何爲組複製激活它。
[mysqld]
ssl_ca = "cacert.pem"
ssl_capath = "/.../ca_directory"
ssl_cert = "server-cert.pem"
ssl_cipher = "DHE-RSA-AEs256-SHA"
ssl_crl = "crl-server-revoked.crl"
ssl_crlpath = "/.../crl_directory"
ssl_key = "server-key.pem"
group_replication_ssl_mode= REQUIRED
唯一列出的特定於插件的配置選項爲group_replication_ssl_mode。此選項通過使用提供給服務器的ssl_ *參數配置SSL框架來激活組成員之間的SSL通信。
Virtual Private Networks (VPN)
沒有什麼阻止組複製在虛擬專用網絡上操作。在其核心,它只是依靠一個IPv4套接字在服務器之間建立連接,目的是在它們之間傳播消息。