MySQL 主-主複製 + SSL認證

來源:互聯網
上載者:User

一、節點資訊:
Master1:192.168.80.143/24 + CA
Master2:192.168.80.144/24

這裡兩節點同為master,並且是對方節點的slave

二、基本配置:

(1)首先2台都安裝mysql

 
  1. # pvcreate /dev/sda5   
  2. # vgcreate myvg /dev/sda5  
  3. # lvcreate -L 10G -n mydata myvg  
  4. # mkdir -p /data/mydata  
  5. # mke2fs -j /dev/myvg/mydata   
  6. # mount /dev/myvg/mydata /data/mydata/  
  7.  
  8. # tar xf mysql-5.5.24-linux2.6-i686.tar.gz  -C /usr/local/  
  9. # cd /usr/local/  
  10. # ln -s mysql-5.5.24-linux2.6-i686/ mysql  
  11. # cd mysql  
  12. # useradd -r mysql  
  13. # chown -R mysql.mysql .  
  14. # scripts/mysql_install_db --datadir=/data/mydata/ --user=mysql 
  15. # chown -R root .  
  16. # cp support-files/my-large.cnf /etc/my.cnf  
  17. # vim /etc/my.cnf   
  18. thread_concurrency = 2 
  19. datadir = /data/mydata  
  20.  
  21. # cp support-files/mysql.server /etc/rc.d/init.d/mysqld  
  22. # chmod +x /etc/rc.d/init.d/mysqld  
  23. # service mysqld start 

(2)在master1上配置CA服務

 
  1. # vim /etc/pki/tls/openssl.cnf  
  2. dir             = /etc/pki/CA   
  3.  
  4. # cd /etc/pki/CA/  
  5. # mkdir certs newcerts crl  
  6. # touch index.txt  
  7. # echo 01 > serial  
  8.  
  9. # (umask 077;openssl genrsa -out private/cakey.pem 1024)  
  10. # openssl req -x509 -new -key private/cakey.pem  
  11.  
  12. # mkdir /usr/local/mysql/ssl  
  13. # cd /usr/local/mysql/ssl  
  14.  
  15. 主從伺服器都需要認證,所以需要4個  
  16. # (umask 077;openssl genrsa 1024 > master1.key)  
  17. # openssl req -new -key master1.key -out master1.csr  
  18. # openssl ca -in master1.csr -out master1.crt -days 365  
  19.  
  20. # (umask 077;openssl genrsa 1024 > master1slave.key)  
  21. # openssl req -new -key master1slave.key -out master1slave.csr  
  22. # openssl ca -in master1slave.csr -out master1slave.crt -days 365  
  23.  
  24. # (umask 077;openssl genrsa 1024 > master2.key)  
  25. # openssl req -new -key master2.key -out master2.csr  
  26. # openssl ca -in master2.csr -out master2.crt -days 365  
  27.  
  28. # (umask 077;openssl genrsa 1024 > master2slave.key)  
  29. # openssl req -new -key master2slave.key -out master2slave.csr  
  30. # openssl ca -in master2slave.csr -out master2slave.crt -days 365  
  31.  
  32. # cp /etc/pki/CA/cacert.pem .  
  33.  
  34. # chown -R mysql.mysql /user/local/mysql/ssl  
  35.  
  36. # scp  -p /etc/pki/CA/cacert.pem master1slave.* master2.* 192.168.80.144:/usr/local/mysql/ssl/ 

三、兩節點配置:

Master1:

 
  1. # vim /etc/my.cnf  
  2. skip-slave-start=1    //設定重啟服務不自動開啟線程,需要手動開啟  
  3.  
  4. ssl      //指定ssl,CA資訊  
  5. ssl-ca=/usr/local/mysql/ssl/cacert.pem  
  6. ssl-cert=/usr/local/mysql/ssl/master1.crt  
  7. ssl-key=/usr/local/mysql/ssl/master1.key  
  8.  
  9. log-bin=mysql-bin  
  10. relay-log=mysql-relay    //開啟中繼日誌  
  11. auto-increment-increment = 2   //每次ID加2  
  12. auto-increment-offset = 1   //設定起始自動成長ID  
  13.  
  14. server-id       = 1 

Master2:

 
  1. # vim /etc/my.cnf  
  2. skip-slave-start=1 
  3.  
  4. ssl  
  5. ssl-ca=/usr/local/mysql/ssl/cacert.pem  
  6. ssl-cert=/usr/local/mysql/ssl/master2.crt  
  7. ssl-key=/usr/local/mysql/ssl/master2.key  
  8.  
  9. log-bin=mysql-bin  
  10. relay-log=mysql-relay  
  11. auto-increment-increment = 2 
  12. auto-increment-offset = 2 
  13.  
  14. server-id       = 2 
  15.  

重啟服務生效

# service mysqld restart

650) this.width=650;" border=0>

共同配置複製使用者資訊,並指定通過SSL:

 
  1. mysql> GRANT REPLICATION SLAVE,REPLICATION CLIENT ON *.* TO repluser@'192.168.80.%' IDENTIFIED BY 'RedHat' REQUIRE SSL;  
  2.  
  3. mysql> flush privileges; 


分別查看日誌位置資訊:
Master1:

 
  1. mysql>show master status;  
  2. +------------------+----------+--------------+------------------+  
  3. | File             | Position | Binlog_Do_DB | Binlog_Ignore_DB |  
  4. +------------------+----------+--------------+------------------+  
  5. | mysql-bin.000011 |      107 |              |                  |  
  6. +------------------+----------+--------------+------------------+  
  7. 1 row in set (0.00 sec 

Master2:

 
  1. mysql>show master status;  
  2. +------------------+----------+--------------+------------------+  
  3. | File             | Position | Binlog_Do_DB | Binlog_Ignore_DB |  
  4. +------------------+----------+--------------+------------------+  
  5. | mysql-bin.000017 |      107 |              |                  |  
  6. +------------------+----------+--------------+------------------+  
  7. 1 row in set (0.00 sec 


在Master2上配置Master1的slave資訊:

 
  1. mysql> CHANGE MASTER TO MASTER_HOST = '192.168.80.143' ,  //指定主伺服器  
  2.     -> MASTER_USER = 'repluser' ,   //指定使用者  
  3.     -> MASTER_PASSWORD = 'redhat' ,    //密碼  
  4.     -> MASTER_LOG_FILE = 'mysql-bin.000017' ,  //指定日誌  
  5.     -> MASTER_LOG_POS = 107 ,    //指定日誌位  
  6.     -> MASTER_SSL = 1 ,  
  7.     -> MASTER_SSL_CA = '/usr/local/mysql/ssl/cacert.pem' ,  
  8.     -> MASTER_SSL_CERT = '/usr/local/mysql/ssl/master1slave.crt' ,  
  9.     -> MASTER_SSL_KEY = '/usr/local/mysql/ssl/master1slave.key';  


在Master1上配置Master2的slave資訊:

 
  1. mysql> CHANGE MASTER TO MASTER_HOST = '192.168.80.144' ,    
  2.     -> MASTER_USER = 'repluser' ,     
  3.     -> MASTER_PASSWORD = 'redhat' ,      
  4.     -> MASTER_LOG_FILE = 'mysql-bin.000011' ,    
  5.     -> MASTER_LOG_POS = 107 ,      
  6.     -> MASTER_SSL = 1 ,  
  7.     -> MASTER_SSL_CA = '/usr/local/mysql/ssl/cacert.pem' ,  
  8.     -> MASTER_SSL_CERT = '/usr/local/mysql/ssl/master2slave.crt' ,  
  9.     -> MASTER_SSL_KEY = '/usr/local/mysql/ssl/master2slave.key';      
  • 1
  • 2
  • 下一頁

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.