您好,登錄后才能下訂單哦!
下文主要給大家帶來mysql如何通過SSL實現主從復制,希望這些內容能夠帶給大家實際用處,這也是我編輯mysql如何通過SSL實現主從復制這篇文章的主要目的。好了,廢話不多說,大家直接看下文吧。
實驗環境:
node1:192.168.4.61
node2:192.168.4.62
CA:192.168.4.63
[root@node1~]#ntpdate 172.18.0.1
[root@node2~]#ntpdate 172.18.0.1
[root@node1~]#vim /etc/chrony.conf #node1和node2操作一樣
[root@node1~]#systemctl start chronyd.service #啟動服務
[root@node1~]#ssh-keygen
[root@node1~]#ssh-copy-id -i /root/.ssh/id_rsa.pub 192.168.4.62#將公鑰復制到node2上
node2操作和node1操作相同。
node1和node2配置相同
[root@node1~]#vim /etc/hosts
3 192.168.4.61 node1 4 192.168.4.62 node2
[root@node1~]#yum install -y mariadb-server
[root@node2~]#yum install -y mariadb-server
[root@node1~]#vim /etc/my.cnf.d/server.cnf
[root@node1~]#systemctl start mariadb #啟動mariadb服務
MariaDB [(none)]> GRANT REPLICATION CLIENT,REPLICATION SLAVE ON *.* TO 'joah'@'192.168.4.62' IDENTIFIED BY '123456'; #對用戶授權
MariaDB [(none)]> SHOW VARIABLES LIKE '%log%bin%';
MariaDB [(none)]> SHOW MASTER STATUS;
[root@node2~]#vim /etc/my.cnf.d/server.cnf
[root@node2~]#systemctl start mariadb #啟動mariadb服務
MariaDB [(none)]> CHANGE MASTER TO MASTER_HOST='192.168.4.61',MASTER_USER='joah',MASTER_PASSWORD='123456',MASTER_LOG_FILE='master-log.000003',MASTER_LOG_POS=417; #設置連接主服務器
MariaDB [(none)]> START SLAVE;
MariaDB [(none)]> START SLAVE IO_THREAD,SQL_THREAD;
MariaDB [(none)]> START SLAVE IO_THREAD,SQL_THREAD;
[root@CA/etc/pki/CA]#touch index.txt
[root@CA/etc/pki/CA]#echo 01 > serial
[root@CA/etc/pki/CA]#(umask 077;openssl genrsa -out private/cakey.pem 2048)
[root@CA/etc/pki/CA]#openssl req -new -x509 -key private/cakey.pem -out cacert.pem -days 3650
[root@node1~]#mkdir /etc/mysql/ssl -pv
[root@node1~]#chown mysql.mysql /etc/mysql/ssl/ -R
[root@node1/etc/mysql/ssl]#(umask 077;openssl genrsa -out master.key 2048)[root@node1/etc/mysql/ssl]#openssl req -new -key master.key -out master.csr
[root@node1/etc/mysql/ssl]#scp master.csr 192.168.4.63:/etc/pki/CA/newcerts/
[root@CA/etc/pki/CA/newcerts]#openssl ca -in master.csr -out master.crt -days 365
[root@CA/etc/pki/CA/newcerts]#scp master.crt ../cacert.pem 192.168.4.61:/etc/mysql/ssl
[root@node1~]#vim /etc/my.cnf.d/server.cnf
[root@node1~]#systemctl restart mariadb
[root@node2~]#mkdir /etc/mysql/ssl -pv
[root@node2~]#chown mysql.mysql /etc/mysql/ssl/ -R
[root@node2/etc/mysql/ssl]#(umask 077;openssl genrsa -out slave.key 2048)
[root@node2/etc/mysql/ssl]#openssl req -new -key slave.key -out slave.csr
[root@node2/etc/mysql/ssl]#scp slave.csr 192.168.4.63:/etc/pki/CA/newcerts
[root@CA/etc/pki/CA/newcerts]#openssl ca -in slave.csr -out slave.crt -days 365
[root@CA/etc/pki/CA/newcerts]#scp slave.crt ../cacert.pem 192.168.4.62:/etc/mysql/ssl
[root@node2/etc/mysql/ssl]#vim /etc/my.cnf.d/server.cnf
[root@node2/etc/mysql/ssl]#systemctl restart mariadb
MariaDB [(none)]> GRANT REPLICATION CLIENT,REPLICATION SLAVE ON *.* TO 'joah'@'192.168.4.62' IDENTIFIED BY '123456' REQUIRE SSL;
[root@node2~]#mysql -ujoah -p123456 -h292.168.4.61 --ssl
MariaDB [(none)]> CHANGE MASTER TO MASTER_HOST='192.168.4.61',MASTER_USER='joah',MASTER_PASSWORD='123456',MASTER_LOG_FILE='master-log.000008',MASTER_LOG_POS=429,MASTER_SSL=1,MASTER_SSL_CA='/etc/mysql/ssl/cacert.pem',MASTER_SSL_CERT='/etc/mysql/ssl/slave.crt',MASTER_SSL_KEY='/etc/mysql/ssl/slave.key'; MariaDB [(none)]> START SLAVE; #啟動從云服務器 MariaDB [(none)]> SHOW SLAVE STATUS\G;
(1)如果你已經正確的添加了證書,但是啟動以后還是沒有啟動SSL功能,有可能沒有權限
[root@node2~]#chown mysql.mysql -R /etc/mysql/ssl
(2)如果出現圖片中的問題,停止slave即可
(3)每一個過程中都需要驗證是否成功然后進行下面的操作。
對于以上關于mysql如何通過SSL實現主從復制,大家是不是覺得非常有幫助。如果需要了解更多內容,請繼續關注我們的行業資訊,相信你會喜歡上這些內容的。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。