今天需要测试一下MySQL Replication在掉电场景下的恢复,这就需要部署一个M-S机构的架构【详细配置过程请Google,这里不进行讲解】,以前都是手动一台一台部署,不知知道为什么今天突然觉得以前的操作太傻了,想批量部署。下面我来介绍这次使用到的工具Pssh,有时间对这个工具进行详解。
pssh是一个python编写的批量管理服务器的工具,使用过的人都会觉得超级cool!下次介绍我的操作步骤,因为我们每台机器上都有MySQL,那么批量安装MySQL就不讲解了,请大家根据下面的讲解自行补充.pssh的安装即使用请阅读《pssh命令参数详解》
1)查看Master的Status
[root@Main ~]# mysql -u xxxx -pxxxx -e "show master Status;"
Warning: Using a password on the command line interface can be insecure.
+--------------+----------+--------------+------------------+-------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+--------------+----------+--------------+------------------+-------------------+
| mysql.000003 | 410 | test | | |
+--------------+----------+--------------+------------------+-------------------+
[root@Main ~]#
2)批量配置Replication
pssh -h IP.txt -l root -i "/usr/local/mysql/bin/mysql -e \"change master to Master_Host='172.16.31.1', Master_User='replication',Master_Password='replication' ,Master_Log_file='mysql.000003', Master_Log_Pos=410\""
[1] 15:56:14 [SUCCESS] Jan.mars.he
[2] 15:56:14 [SUCCESS] Mar.mars.he
[3] 15:56:14 [SUCCESS] Feb.mars.he
3)批量启动Replication与查看Slave状态
# pssh -h IP.txt -l root -i "/usr/local/mysql/bin/mysql -e \"show slave status \G\""
[1] 15:56:46 [SUCCESS] Feb.mars.he
*************************** 1. row ***************************
Slave_IO_State: Queueing master event to the relay log
Master_Host: 172.16.31.1
Master_User: replication
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql.000003
Read_Master_Log_Pos: 410
Relay_Log_File: relay.000625
Relay_Log_Pos: 163
Relay_Master_Log_File: mysql.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: 410
Relay_Log_Space: 485
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: 100
Master_UUID: 3ce6b577-6bd5-11e4-875a-902b34c2108e
Master_Info_File: /usr/local/mysql/data/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
[2] 15:56:46 [SUCCESS] Jan.mars.he
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 172.16.31.1
Master_User: replication
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql.000003
Read_Master_Log_Pos: 410
Relay_Log_File: relay.000016
Relay_Log_Pos: 279
Relay_Master_Log_File: mysql.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: 410
Relay_Log_Space: 601
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: 100
Master_UUID: 3ce6b577-6bd5-11e4-875a-902b34c2108e
Master_Info_File: /usr/local/mysql/data/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
[3] 15:56:47 [SUCCESS] Mar.mars.he
*************************** 1. row ***************************
Slave_IO_State: Checking master version
Master_Host: 172.16.31.1
Master_User: replication
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql.000003
Read_Master_Log_Pos: 410
Relay_Log_File: relay.000656
Relay_Log_Pos: 279
Relay_Master_Log_File: mysql.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: 410
Relay_Log_Space: 601
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: 100
Master_UUID: 3ce6b577-6bd5-11e4-875a-902b34c2108e
Master_Info_File: /usr/local/mysql/data/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
3)查看简单的信息
[root@Main ~]# pssh -h IP.txt -l root -i "/usr/local/mysql/bin/mysql -e \"show slave status \G\"" |awk '/Running:/{print $0}'
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
[root@Main ~]#
到这里就结束了,大家会不会觉得十分厉害的呢
转载请注明来源:DB爱好者-《批量配置MySQL主从同步》
本文连接地址:http://www.databaseclub.com/2014/11/pssh-mysql-replication/