MySQL主從複製 半同步 基於ssL加密複製

MySQL主從複製.半同步.基於ssL加密複製

                   

MySQL複製的好處

1.      負載均衡html

2.      數據的分佈node

3.      備份的操做mysql

4.      高可用和容錯linux

MySQL複製的原理

 

1.master服務器改變的數據記錄到二進制日誌(binary log)中sql

2.slave服務器將master服務器上的二進制日誌經過i/o線程獲取到本身的中繼日誌中(relay-log數據庫

3.slave服務器經過sql線程讀取中繼日誌,而後將改變的數據寫入到本身的數據庫中       vim

上述圖片爲二進制簡單的複製過程簡介安全

配置注意事項和前提條件

1.      master服務器必須開啓二進制日誌服務器

2.      masterslaveserver-id不能相同網絡

3.      同一個master的多個slaveserver也不能相同

4.      Binlog_format最好相同 ,不然會致使數據不一致

5.      slave服務器上配置log-slave-updates=1時,也須要開啓二進制日誌

6.      Read_only選項開啓,能夠阻止沒有權限的線程修改數據

----------------------------------------------------------------------------------------------------------------------------------

       軟件版本

                  

 系統版本 : 
     Centos 6.4_2.6.32-358.el6.x86_64  
 Myql版本:
     mysql-5.5.33-linux2.6-x86_64.tar.gz
 環境介紹  :
     master服務器:node3  192.168.17.15
     Slave服務器: node4   192.168.17.32


       安裝準備

1.修改主機名

2.配置主機名解析,修改hosts文件

3.同步倆臺服務器時間 ,讓時間保持一致

安裝MySQL

1.Masterslavemysql安裝配置同樣

[root@node3 ~]# useradd -r -u 306 mysql 
[root@node3 ~]# mkdir -p /mydata/data          
[root@node3 ~]# tar xfmysql-5.5.33-linux2.6-x86_64.tar.gz -C /usr/local/
[root@node3 ~]# cd /usr/local/
[root@node3 local]# ln -svmysql-5.5.33-linux2.6-x86_64/ mysql 
`mysql' ->`mysql-5.5.33-linux2.6-x86_64/'         
[root@node3 local]# cd mysql
[root@node3 mysql]# chown -R root.mysql .
[root@node3 mysql]# cpsupport-files/mysql.server /etc/init.d/mysqld 
cp: overwrite `/etc/init.d/mysqld'? y
[root@node3 mysql]# chmod +x /etc/init.d/mysqld
[root@node3 mysql]# chkconfig --add mysqld 
[root@node3 mysql]# chkconfig mysqld on 
[root@node3 mysql]# cpsupport-files/my-large.cnf /etc/my.cnf 
cp: overwrite `/etc/my.cnf'? y
[root@node3 mysql]# vim /etc/my.cnf
datadir = /mydata/data
innodb_file_per_table = 1
[root@node3 mysql]# echo"PATH=/usr/local/mysql/bin:$PATH" >> /etc/profile 
 [root@node3mysql]# .  /etc/profile
 [root@node3mysql]# ln -s /usr/local/mysql/include/ /usr/include/mysql
[root@node3 mysql]# echo "/usr/local/mysql/lib">> /etc/ld.so.conf
[root@node3 mysql]# ldconfig 
[root@node3 mysql]# chown -R mysql.mysql/mydata/data
[root@node3 mysql]#./scripts/mysql_install_db --user=mysql --datadir=/mydata/data 
Installing MySQL system tables...
OK
Filling help tables...
OK
 
To start mysqld at boot time you have tocopy
support-files/mysql.server to the rightplace for your system
PLEASE REMEMBER TO SET A PASSWORD FOR THEMySQL root USER !
To do so, start the server, then issue thefollowing commands:
./bin/mysqladmin -u root password'new-password'
./bin/mysqladmin -u root -h node3 password'new-password'
Alternatively you can run:
./bin/mysql_secure_installation
which will also give you the option ofremoving the test
databases and anonymous user created by default.  This is
strongly recommended for productionservers.
See the manual for more instructions.
You can start the MySQL daemon with:
cd . ; ./bin/mysqld_safe &
You can test the MySQL daemon withmysql-test-run.pl
cd ./mysql-test ; perl mysql-test-run.pl
Please report any problems with the./bin/mysqlbug script!
 [root@node3 mysql]# service mysqld start 
Starting MySQL... SUCCESS!


主從複製配置

master服務器上創建用於slave服務器複製數據的帳戶(最小權限)      

[root@node3 mysql]# mysql 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.5.33-log MySQL CommunityServer (GPL)
 
Copyright (c) 2000, 2013, Oracle and/or itsaffiliates. All rights reserved.
 
Oracle is a registered trademark of OracleCorporation and/or its
affiliates. Other names may be trademarksof their respective
owners.
 
Type 'help;' or '\h' for help. Type '\c' toclear the current input statement.
mysql> grant replication client,replication slave on *.* to 'bds'@'192.168.%.%' identified by 'budongshu';
Query OK, 0 rows affected (0.00 sec)
mysql> flush privileges; 
Query OK, 0 rows affected (0.00 sec)
mysql> show grants  for 'bds'@'192.168.%.%' ;
+----------------------------------------------------------------------------------------------------------------------------------------------+
| Grants for bds@192.168.%.%                                                                                                                  |
+----------------------------------------------------------------------------------------------------------------------------------------------+
| GRANT REPLICATION SLAVE, REPLICATIONCLIENT ON *.* TO 'bds'@'192.168.%.%' IDENTIFIED BY PASSWORD'*55DE68D71BDCF62EA7C0476394AF10F053178281' |
+----------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)


 

2. Slave服務器上使用受權用戶鏈接測試

[root@node4 ~]# mysql -ubds -pbudongshu -h192.168.17.15 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.5.33-log MySQL CommunityServer (GPL)
Copyright (c) 2000, 2013, Oracle and/or itsaffiliates. All rights reserved.
Oracle is a registered trademark of OracleCorporation and/or its
affiliates. Other names may be trademarksof their respective
owners.
Type 'help;' or '\h' for help. Type '\c' toclear the current input statement.
mysql>


3. 修改slave服務器的配置文件

skip_slave_start = 1
read_only = 1
relay_log = relay_log
relay_log_index = relay_log.index
server-id       = 21
#log-bin=mysql-bin
#log-bin=mysql-bin
[root@node4 ~]# service mysqld restart


4.修改mater服務器的配置文件

log-bin=mysql-bin
log_bin_index = msyql_bin.index
binlog_format=mixed
server-id       = 1


5.查看master服務器的二進制日誌和二進制日誌事件位置

mysql> show master status;                                                                               
+------------------+----------+--------------+------------------+
| File             | Position | Binlog_Do_DB |Binlog_Ignore_DB |
+------------------+----------+--------------+------------------+
| mysql-bin.000003 |      355 |              |                  |
+------------------+----------+--------------+------------------+
1 row in set (0.00 sec)


6.開始在slave服務器同步master服務器的數據

 

mysql> help change master to
MASTER_BIND = 'interface_name'
  |MASTER_HOST = 'host_name'
  |MASTER_USER = 'user_name'
  |MASTER_PASSWORD = 'password'
  |MASTER_PORT = port_num
  |MASTER_CONNECT_RETRY = interval
  |MASTER_HEARTBEAT_PERIOD = interval
  |MASTER_LOG_FILE = 'master_log_name'
  |MASTER_LOG_POS = master_log_pos
mysql> change master tomaster_host='192.168.17.15',master_user='bds',master_password='budongshu',master_port=3306,master_log_file='mysql-bin.000003',master_log_pos=355;
Query OK, 0 rows affected (0.01 sec)


7.啓動slave服務器的複製線程並查看狀態

mysql> start slave;
Query OK, 0 rows affected (0.00 sec)
 
mysql> show slave status\G
*************************** 1. row***************************
               Slave_IO_State: Waiting formaster to send event
                  Master_Host: 192.168.17.15
                  Master_User: bds
                  Master_Port: 3306
                Connect_Retry: 60
              Master_Log_File: mysql-bin.000003
         Read_Master_Log_Pos: 355
               Relay_Log_File: relay_log.000002
                Relay_Log_Pos: 253
       Relay_Master_Log_File: mysql-bin.000003
            Slave_IO_Running: Yes
           Slave_SQL_Running: Yes
              Replicate_Do_DB: 
         Replicate_Ignore_DB: 
          Replicate_Do_Table: 
      Replicate_Ignore_Table: 
     Replicate_Wild_Do_Table: 
 Replicate_Wild_Ignore_Table: 
                  Last_Errno: 0
                   Last_Error: 
                 Skip_Counter: 0
         Exec_Master_Log_Pos: 355
              Relay_Log_Space: 403
              Until_Condition: None
               Until_Log_File: 
                Until_Log_Pos: 0
          Master_SSL_Allowed: No
          Master_SSL_CA_File: 
          Master_SSL_CA_Path: 
              Master_SSL_Cert: 
           Master_SSL_Cipher: 
               Master_SSL_Key: 
       Seconds_Behind_Master: 0
Master_SSL_Verify_Server_Cert: No
                Last_IO_Errno: 0
                Last_IO_Error: 
               Last_SQL_Errno: 0
               Last_SQL_Error: 
 Replicate_Ignore_Server_Ids: 
            Master_Server_Id: 1
1 row in set (0.00 sec)


 

mysql> show processlist; 
+----+-------------+-----------+------+---------+------+-----------------------------------------------------------------------------+------------------+
| Id | User        | Host      | db  | Command | Time | State                                                                      |Info             |
+----+-------------+-----------+------+---------+------+-----------------------------------------------------------------------------+------------------+
|  2| root        | localhost | NULL |Query   |    0 | NULL                                                                       | show processlist |
|  3| system user |           | NULL |Connect |   54 | Waiting for master tosend event                                           | NULL             |
|  4| system user |           | NULL |Connect |   53 | Slave has read all relaylog; waiting for the slave I/O thread to update it | NULL             |
+----+-------------+-----------+------+---------+------+-----------------------------------------------------------------------------+------------------+
3 rows in set (0.00 sec)


9.master服務器建立數據庫,而後在從服務器上驗證是否存在

mysql> create database bds;
Query OK, 1 row affected (0.00 sec)
[root@node4 ~]# mysql -e 'show databases'; 
+--------------------+
| Database           |
+--------------------+
| information_schema |
| bds                |
| mysql              |
| performance_schema |
| test               |
+--------------------+
 
[root@node4 ~]# mysql -e 'show databases'; 
+--------------------+
| Database           |
+--------------------+
| information_schema |
| bds                |
| mysql              |
| performance_schema |
| test               |
+--------------------+


10.查看倆臺服務器的二進制日誌事件位置和是否一致

[root@node3 ~]# mysql -e 'show masterstatus';
+------------------+----------+--------------+------------------+
| File             | Position | Binlog_Do_DB |Binlog_Ignore_DB |
+------------------+----------+--------------+------------------+
| mysql-bin.000003 |      436 |             |                  |
+------------------+----------+--------------+------------------+
 
[root@node4 ~]# mysql -e 'show slave status\G' | grep "Read"
         Read_Master_Log_Pos: 436


半同步複製

         半同步複製表示master服務器只須要接收到其中一臺的slave服務器的返回信息,就會commit,不然須要等待直到超過

設定的時間,而後降級切換成異步再提交,這樣作的目的可使主從數據的數據延遲縮小,能夠在損失很小的性能前提下提升

數據的安全性。

1.      半同步的開啓比較簡單,只須要在masterslave服務器上都安裝上本同步插件並啓動便可。

2.      插件在mysql的安裝目錄中  /usr/local/mysql/lib/plugin/   (二進制形式安裝mysql的位置)

[root@node3 ~]# ll/usr/local/mysql/lib/plugin/ | grep "semi"
-rwxr-xr-x. 1 root mysql 170178 Jul 15  2013 semisync_master.so
-rwxr-xr-x. 1 root mysql  88895 Jul 15 2013 semisync_slave.so


3.在倆臺服務器上分別安裝插件

mysql> install pluginrpl_semi_sync_master soname 'semisync_master.so';
mysql> set globalrpl_semi_sync_master_enabled = 1 ; 
mysql> set globalrpl_semi_sync_master_timeout = 1000 ;        
 
mysql> install plugin rpl_semi_sync_slave soname 'semisync_slave.so';
mysql> set globalrpl_semi_sync_slave_enabled = 1;
mysql> stop slave io_thread;start slaveio_thread;


3.查看半同步狀態

mysql> show global status like'rpl_semi%';
+--------------------------------------------+-------+
| Variable_name                              | Value |
+--------------------------------------------+-------+
| Rpl_semi_sync_master_clients               | 1     |
|Rpl_semi_sync_master_net_avg_wait_time    | 0     |
| Rpl_semi_sync_master_net_wait_time         | 0    |
| Rpl_semi_sync_master_net_waits             | 0     |
| Rpl_semi_sync_master_no_times              | 0     |
| Rpl_semi_sync_master_no_tx                 | 0     |
| Rpl_semi_sync_master_status                | ON    |
|Rpl_semi_sync_master_timefunc_failures    | 0     |
|Rpl_semi_sync_master_tx_avg_wait_time     | 0     |
| Rpl_semi_sync_master_tx_wait_time          | 0    |
| Rpl_semi_sync_master_tx_waits              | 0     |
|Rpl_semi_sync_master_wait_pos_backtraverse | 0     |
| Rpl_semi_sync_master_wait_sessions         | 0    |
| Rpl_semi_sync_master_yes_tx                | 0     |
+--------------------------------------------+-------+
mysql> show global variables like'%rpl%';
+------------------------------------+-------+
| Variable_name                      | Value |
+------------------------------------+-------+
| rpl_recovery_rank                  | 0    |
| rpl_semi_sync_master_enabled       | ON   |
| rpl_semi_sync_master_timeout       | 1000 |
| rpl_semi_sync_master_trace_level   | 32   |
| rpl_semi_sync_master_wait_no_slave |ON    |
+------------------------------------+-------+  
 
mysql> show global status like'rpl_semi%';
+----------------------------+-------+
| Variable_name              | Value |
+----------------------------+-------+
| Rpl_semi_sync_slave_status | ON    |
+----------------------------+-------+
mysql> show global variables like'%rpl%';
+---------------------------------+-------+
| Variable_name                   | Value |
+---------------------------------+-------+
| rpl_recovery_rank               | 0     |
| rpl_semi_sync_slave_enabled     | ON   |
| rpl_semi_sync_slave_trace_level | 32    |
+---------------------------------+-------+


  1. 查看slave線程是否啓動

[root@node4 ~]# mysql -e 'show slavestatus\G' | grep "Running"
            Slave_IO_Running: Yes
           Slave_SQL_Running: Yes


 

5.在master服務器上將前面建立的’bds’數據庫刪除,而後驗證slave服務器同步狀態。

mysql> drop database bds;
mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| test               |
+--------------------+
mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| test               |
+--------------------+


6.以上配置不會永久生效,若是想永久生效,須要寫在配置文件中重啓服務便可。

基於ssl的加密複製

         由於mysql在傳輸數據的時候是明文傳輸的 ,再生產環境中很是的不安全 ,尤爲是在跨網絡環境中,

爲了解決這個問題,須要進行加密傳輸,因此用基於ssl的加密傳輸數據。

1.    master服務器本身作成CA服務器

[root@node3 CA]# cd /etc/pki/CA/
[root@node3 CA]# (umask 077; openssl genrsa-out private/cakey.pem 2048 )
root@node3 CA]# openssl req -new -x509 -keyprivate/cakey.pem -out cacert.pem -days 365 
You are about to be asked to enterinformation that will be incorporated
into your certificate request.
What you are about to enter is what iscalled a Distinguished Name or a DN.
There are quite a few fields but you canleave some blank
For some fields there will be a defaultvalue,
If you enter '.', the field will be leftblank.
-----
Country Name (2 letter code) [XX]:cn
State or Province Name (full name) []:bj
Locality Name (eg, city) [DefaultCity]:beijing
Organization Name (eg, company) [DefaultCompany Ltd]:bds
Organizational Unit Name (eg, section)[]:tech
Common Name (eg, your name or your server'shostname) []:node3
Email Address []:node3@qq.com
[root@node3 CA]# touch  index.txt 
[root@node3 CA]# echo 01 > serial


2.爲master 建立證書申請並由CA服務器簽發證書  

[root@node3 CA]# mkdir  /usr/local/mysql/ssl/  -pv
[root@node3 CA]# cd /usr/local/mysql/ssl/ 
[root@node3 ssl]# (umask 077; opensslgenrsa -out  master.key 2048) 
[root@node3 ssl]# openssl req -new -keymaster.key -out master.csr -days 365 
You are about to be asked to enterinformation that will be incorporated
into your certificate request.
What you are about to enter is what iscalled a Distinguished Name or a DN.
There are quite a few fields but you canleave some blank
For some fields there will be a defaultvalue,
If you enter '.', the field will be leftblank.
-----
Country Name (2 letter code) [XX]:cn
State or Province Name (full name) []:bj
Locality Name (eg, city) [DefaultCity]:beijing
Organization Name (eg, company) [DefaultCompany Ltd]:bds
Organizational Unit Name (eg, section)[]:tech
Common Name (eg, your name or your server'shostname) []:node3
Email Address []:node3@qq.com         
Please enter the following 'extra'attributes
to be sent with your certificate request
A challenge password []:
An optional company name []:
[root@node3 ssl]# openssl ca -in master.csr-out master.crt -days 365
Using configuration from/etc/pki/tls/openssl.cnf
Check that the request matches thesignature
Signature ok
Certificate Details:
       Serial Number: 1 (0x1)
       Validity
           Not Before: Dec  3 04:40:39 2014GMT
           Not After : Dec  3 04:40:39 2015GMT
       Subject:
           countryName               = cn
           stateOrProvinceName       = bj
           organizationName          = bds
           organizationalUnitName    = tech
           commonName                = node3
           emailAddress              =node3@qq.com
       X509v3 extensions:
           X509v3 Basic Constraints: 
                CA:FALSE
           Netscape Comment: 
                OpenSSL Generated Certificate
           X509v3 Subject Key Identifier: 
               BF:D7:B2:93:F5:67:00:58:1B:3B:B1:2D:93:E1:9F:2B:4B:15:52:0E
           X509v3 Authority Key Identifier: 
               keyid:70:41:30:49:6D:7E:3F:9A:73:B2:25:15:B8:D1:6F:24:3F:3C:54:39
Certificate is to be certified untilDec  3 04:40:39 2015 GMT (365 days)
Sign the certificate? [y/n]:y
1 out of 1 certificate requests certified, commit?[y/n]y
Write out database with 1 new entries
Data Base Updated


3.slave服務器建立證書申請

mkdir /usr/local/mysql/ssl
[root@node4 ~]# cd /usr/local/mysql/ssl/
[root@node4 ssl]#  (umask 077;openssl genrsa -out slave.key2048)
[root@node4 ssl]# openssl req -new -keyslave.key -out slave.csr -days 365
You are about to be asked to enterinformation that will be incorporated
into your certificate request.
What you are about to enter is what iscalled a Distinguished Name or a DN.
There are quite a few fields but you canleave some blank
For some fields there will be a defaultvalue,
If you enter '.', the field will be leftblank.
-----
Country Name (2 letter code) [XX]:cn
State or Province Name (full name) []:bj
Locality Name (eg, city) [DefaultCity]:beijing
Organization Name (eg, company) [DefaultCompany Ltd]:bds
Organizational Unit Name (eg, section)[]:tech
Common Name (eg, your name or your server'shostname) []:node4
Email Address []:node3@qq.com
Please enter the following 'extra'attributes
to be sent with your certificate request
A challenge password []:
An optional company name []:


  1. 爲服務器簽署證書

[root@node4 ssl]# scp slave.csrnode3:/root/
[root@node3 ~]# openssl ca -in/root/slave.csr -out /root/slave.crt -days 365 
Using configuration from /etc/pki/tls/openssl.cnf
Check that the request matches thesignature
Signature ok
Certificate Details:
       Serial Number: 2 (0x2)
       Validity
           Not Before: Dec  3 05:35:16 2014GMT
           Not After : Dec  3 05:35:16 2015GMT
       Subject:
           countryName               = cn
           stateOrProvinceName       = bj
           organizationName          = bds
           organizationalUnitName    = tech
           commonName                = node4
           emailAddress              =node3@qq.com
       X509v3 extensions:
           X509v3 Basic Constraints: 
                CA:FALSE
           Netscape Comment: 
                OpenSSL Generated Certificate
           X509v3 Subject Key Identifier: 
                BF:8A:0A:65:FC:92:75:64:CB:44:0D:DC:ED:FE:E5:E9:3E:85:5F:92
           X509v3 Authority Key Identifier: 
               keyid:70:41:30:49:6D:7E:3F:9A:73:B2:25:15:B8:D1:6F:24:3F:3C:54:39
 
Certificate is to be certified untilDec  3 05:35:16 2015 GMT (365 days)
Sign the certificate? [y/n]:y
1 out of 1 certificate requests certified,commit? [y/n]y
Write out database with 1 new entries
Data Base Updated 
[root@node3 ~]# scp slave.crt  node4:/usr/local/mysql/ssl/
[root@node3 ~]# scp /etc/pki/CA/cacert.pem node4:/usr/local/mysql/ssl/
[root@node3 ~]# cp/etc/pki/CA/cacert.pem /usr/local/mysql/ssl/


  1. 修改masterslave服務器證書屬主屬組爲mysql用戶

[root@node3 ~]# chown -R mysql.mysql/usr/local/mysql/ssl/
[root@node4 ssl]# chown -R mysql.mysql  /usr/local/mysql/ssl/


  1. 修改配置文件開啓ssl加密功能

[root@node3 ~]# vi /etc/my.cnf
ssl
ssl_ca = /usr/local/mysql/ssl/cacert.pem
ssl_cert = /usr/local/mysql/ssl/master.crt
ssl_key = /usr/local/mysql/ssl/master.key 
[root@node4 ssl]# vi /etc/my.cnf 
[root@node3 ~]# service mysqld restart  
ssl
ssl_ca = /usr/local/mysql/ssl/cacert.pem
ssl_cert = /usr/local/mysql/ssl/slave.crt
ssl_key = /usr/local/mysql/ssl/slave.key 
[root@node4 ssl]# service mysqld restart


  1. master服務器查看ssl加密是否開啓,而後建立受權一個基於密鑰認證的用戶 

[root@node3 ~]# mysql
mysql> show variables like "%ssl%" ;
+---------------+---------------------------------+
| Variable_name | Value                           |
+---------------+---------------------------------+
| have_openssl  | YES                             |
| have_ssl      | YES                             |
| ssl_ca        | /usr/local/mysql/ssl/cacert.pem |
| ssl_capath    |                                 |
| ssl_cert      | /usr/local/mysql/ssl/master.crt |
| ssl_cipher    |                                 |
| ssl_key       | /usr/local/mysql/ssl/master.key |
+---------------+---------------------------------+
mysql> grant replicationclient,replication slave on *.* to 'bds'@'192.168.%.%' identified by'budognshu' require ssl;
mysql> flush privileges;


8 . 查看master服務器二進制日誌文件位置和事件位置用於slave服務器鏈接今後位置開始複製

mysql> show master status; 
+------------------+----------+--------------+------------------+
| File             | Position | Binlog_Do_DB |Binlog_Ignore_DB |
+------------------+----------+--------------+------------------+
| mysql-bin.000004 |      367 |              |                  |
+------------------+----------+--------------+------------------+


9. 測試使用加密用戶指定密鑰鏈接master服務器

[root@node4 ~]# mysql -ubds -pbudongshu -h192.168.17.15 --ssl-ca=/usr/local/mysql/ssl/cacert.pem --ssl-cert=/usr/local/mysql/ssl/slave.crt--ssl-key=/usr/local/mysql/ssl/slave.key 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.5.33-log MySQL CommunityServer (GPL)
Copyright (c) 2000, 2013, Oracle and/or itsaffiliates. All rights reserved.
Oracle is a registered trademark of OracleCorporation and/or its
affiliates. Other names may be trademarksof their respective
owners.
Type 'help;' or '\h' for help. Type '\c' toclear the current input statement.
mysql>


10. 查看slave服務器是否開啓ssl 加密 並鏈接master服務器

[root@node4 ~]# mysql
mysql> show variables like"%ssl%"; 
+---------------+---------------------------------+
| Variable_name | Value                           |
+---------------+---------------------------------+
| have_openssl  | YES                             |
| have_ssl      | YES                             |
| ssl_ca        | /usr/local/mysql/ssl/cacert.pem |
| ssl_capath    |                                 |
| ssl_cert      | /usr/local/mysql/ssl/slave.crt  |
| ssl_cipher    |                                 |
| ssl_key       | /usr/local/mysql/ssl/slave.key  |
+---------------+---------------------------------+
mysql> change master tomaster_host='192.168.17.15',master_user='bds',master_password='budongshu',
   -> master_log_file='mysql-bin.000004',
   -> master_log_pos=367,
   -> master_ssl=1,
   -> master_ssl_ca='/usr/local/mysql/ssl/cacert.pem',
   -> master_ssl_cert='/usr/local/mysql/ssl/slave.crt',
   -> master_ssl_key='/usr/local/mysql/ssl/slave.key';


11 .查看slave服務器狀態

mysql> start slave;
Query OK, 0 rows affected (0.00 sec)
 
mysql> show slave status\G
*************************** 1. row***************************
               Slave_IO_State: Waiting formaster to send event
                  Master_Host: 192.168.17.15
                  Master_User: bds
                  Master_Port: 3306
                Connect_Retry: 60
              Master_Log_File: mysql-bin.000004
         Read_Master_Log_Pos: 367
               Relay_Log_File: relay_log.000002
                Relay_Log_Pos: 253
       Relay_Master_Log_File: mysql-bin.000004
            Slave_IO_Running: Yes
           Slave_SQL_Running: Yes
              Replicate_Do_DB: 
         Replicate_Ignore_DB: 
          Replicate_Do_Table: 
      Replicate_Ignore_Table: 
     Replicate_Wild_Do_Table: 
 Replicate_Wild_Ignore_Table: 
                   Last_Errno: 0
                   Last_Error: 
                 Skip_Counter: 0
         Exec_Master_Log_Pos: 367
             Relay_Log_Space: 403
              Until_Condition: None
               Until_Log_File: 
                Until_Log_Pos: 0
          Master_SSL_Allowed: Yes
          Master_SSL_CA_File: /usr/local/mysql/ssl/cacert.pem
          Master_SSL_CA_Path: 
              Master_SSL_Cert:/usr/local/mysql/ssl/slave.crt
           Master_SSL_Cipher: 
               Master_SSL_Key:/usr/local/mysql/ssl/slave.key
       Seconds_Behind_Master: 0
Master_SSL_Verify_Server_Cert: No
                Last_IO_Errno: 0
                Last_IO_Error: 
               Last_SQL_Errno: 0
               Last_SQL_Error: 
 Replicate_Ignore_Server_Ids: 
            Master_Server_Id: 1


12 .驗證基於ssl複製

Master
mysql> create database bds;
mysql> show databases;       
+--------------------+
| Database           |
+--------------------+
| information_schema |
| bds                |
| mysql              |
| performance_schema |
| test               |
+--------------------+
Slave 
mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| bds                |
| mysql              |
| performance_schema |
| test               |
+--------------------+
相關文章
相關標籤/搜索