MYSQL 5.6 複製(半同步) 部署實錄

MASTER(KING01)

[root@king01 ~]# vi /etc/my.cnf
server_id = 1
log_bin = mysql-bin
binlog_format = row
sync_binlog = 1
binlog_cache_size = 16M
max_binlog_cache_size = 32M
max_binlog_size = 512M
expire_logs_days = 7
master_info_repository = table
relay_log_info_repository = table
relay_log = relay-bin
relay_log_recovery = 1


[root@king01 ~]# mkdir -p /usr/local/mysql/backup
[root@king01 ~]# chown -R mysql /usr/local/mysql/backup
[root@king01 ~]# su - mysql
[mysql@king01 ~]$ vi xtrabackup_full.sh
#!/bin/bash
user='root'
passwd='abcd.1234'
my_config='/etc/my.cnf'
backup_dir='/usr/local/mysql/backup'
if [ -f ~/.bash_profile ];
then
  . ~/.bash_profile
fi
innobackupex  --defaults-file=$my_config --user=$user --password=$passwd $backup_dir

[mysql@king01 ~]$ chmod a+x xtrabackup_full.sh 

[mysql@king01 ~]$ ./xtrabackup_full.sh
[mysql@king01 ~]$ cd /usr/local/mysql/backup
[mysql@king01 backup]$ scp -r 2018-02-05_05-41-26 [email protected]:/usr/local/mysql/backup


[root@king01 ~]# mysql -uroot -pabcd.1234

mysql> grant replication slave on *.* to 'repl'@'192.168.1.%' identified by 'repl';
Query OK, 0 rows affected (0.11 sec)

mysql> flush privileges; 
Query OK, 0 rows affected (0.05 sec)


SLAVE(KING02)

[root@king02 ~]# vi /etc/my.cnf
server_id = 2
log_bin = mysql-bin
binlog_format = row
sync_binlog = 1
binlog_cache_size = 16M
max_binlog_cache_size = 32M
max_binlog_size = 512M
expire_logs_days = 7
master_info_repository = table
relay_log_info_repository = table
relay_log = relay-bin
relay_log_recovery = 1


[root@king02 ~]# mkdir -p /usr/local/mysql/backup
[root@king02 ~]# chown -R mysql /usr/local/mysql/backup
[root@king02 ~]# chown -R mysql /usr/local/mysql/data/
[root@king02 ~]# cd /usr/local/mysql/data/
[root@king02 data]# rm -rf *


[root@king02 ~]# su - mysql
[mysql@king02 ~]$ innobackupex --defaults-file=/etc/my.cnf --apply-log /usr/local/mysql/backup/2018-02-05_05-41-26
[mysql@king02 ~]$ innobackupex --defaults-file=/etc/my.cnf --copy-back /usr/local/mysql/backup/2018-02-05_05-41-26
[root@king02 ~]# service mysqld start
Starting MySQL.Logging to '/usr/local/mysql/data/mysql.err'.
.......                                                    [  OK  ]


[root@king02 ~]# cd /usr/local/mysql/backup/2018-02-05_05-41-26
[root@king02 2018-02-05_05-41-26]# cat xtrabackup_binlog_info
mysql-bin.000006        146505795


[root@king02 ~]# mysql -uroot -pabcd.1234

mysql> change master to \
master_host='192.168.1.201', \
master_user='repl', \
master_password='repl', \
master_log_file='mysql-bin.000006', \
master_log_pos=146505795;
Query OK, 0 rows affected, 2 warnings (0.05 sec)

mysql> start slave;
Query OK, 0 rows affected (0.03 sec)


mysql> show slave status\G;
*************************** 1. row ***************************
               Slave_IO_State: Waiting for master to send event
                  Master_Host: 192.168.1.201
                  Master_User: repl
                  Master_Port: 3306
                Connect_Retry: 60
              Master_Log_File: mysql-bin.000006
          Read_Master_Log_Pos: 146506084
               Relay_Log_File: relay-bin.000002
                Relay_Log_Pos: 572
        Relay_Master_Log_File: mysql-bin.000006
             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: 146506084
              Relay_Log_Space: 739
              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
                  Master_UUID: a7c3a6e9-254f-11e8-90d3-0800272bd617
             Master_Info_File: mysql.slave_master_info
                    SQL_Delay: 0
          SQL_Remaining_Delay: NULL
      Slave_SQL_Running_State: Slave has read all relay log; waiting for the slave I/O thread to update it
           Master_Retry_Count: 86400
                  Master_Bind: 
      Last_IO_Error_Timestamp: 
     Last_SQL_Error_Timestamp: 
               Master_SSL_Crl: 
           Master_SSL_Crlpath: 
           Retrieved_Gtid_Set: 
            Executed_Gtid_Set: 
                Auto_Position: 0
1 row in set (0.03 sec)


半同步複製

[root@king01 ~]# mysql -uroot -pabcd.1234

mysql> install plugin rpl_semi_sync_master soname 'semisync_master.so';
Query OK, 0 rows affected (0.16 sec)

[root@king01 ~]# vi /etc/my.cnf
rpl_semi_sync_master_enabled=1
rpl_semi_sync_master_timeout=3000


[root@king02 ~]# mysql -uroot -pabcd.1234

mysql> install plugin rpl_semi_sync_slave soname 'semisync_slave.so';
Query OK, 0 rows affected (0.11 sec)

[root@king02 ~]# vi /etc/my.cnf
rpl_semi_sync_slave_enabled=1


[root@king02 ~]# service mysqld restart
Shutting down MySQL..                                      [  OK  ]
Starting MySQL.........                                    [  OK  ]
[root@king01 ~]# service mysqld restart
Shutting down MySQL..                                      [  OK  ]
Starting MySQL....                                         [  OK  ]


root@king01 ~]# mysql -uroot -pabcd.1234

mysql> show status like 'rpl_semi_sync%';
+--------------------------------------------+---------+
| Variable_name                              | Value   |
+--------------------------------------------+---------+
| Rpl_semi_sync_master_clients               | 1       |
| Rpl_semi_sync_master_net_avg_wait_time     | 1542    |
| Rpl_semi_sync_master_net_wait_time         | 538362  |
| Rpl_semi_sync_master_net_waits             | 349     |
| 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      | 9083    |
| Rpl_semi_sync_master_tx_wait_time          | 2779470 |
| Rpl_semi_sync_master_tx_waits              | 306     |
| Rpl_semi_sync_master_wait_pos_backtraverse | 0       |
| Rpl_semi_sync_master_wait_sessions         | 0       |
| Rpl_semi_sync_master_yes_tx                | 357     |
+--------------------------------------------+---------+
14 rows in set (0.07 sec)






發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章