Chinaunix首页 | 论坛 | 博客
  • 博客访问: 4153296
  • 博文数量: 240
  • 博客积分: 11504
  • 博客等级: 上将
  • 技术积分: 4277
  • 用 户 组: 普通用户
  • 注册时间: 2006-12-28 14:24
文章分类

全部博文(240)

分类: Mysql/postgreSQL

2013-05-14 12:53:41

我主要体验了下几个关于REPLICATION的工具。 其他的可以参见手册。
先说下我的环境:
MASTER: 192.168.1.131
SLAVE: 192.168.1.132, 192.168.1.133
三台DB都有对外的ALL权限用户。
各个配置文件如下,



点击(此处)折叠或打开

  1. [root@mysql56-master home]# cat /etc/my.cnf
  2. [mysqld]
  3. user = ytt
  4. skip-name-resolve


  5. innodb_buffer_pool_size = 128M




  6. basedir = /usr/local/mysql
  7. datadir = /usr/local/mysql/data
  8. port = 3306
  9. server_id = 131
  10. socket = /tmp/mysql.sock






  11. explicit_defaults_for_timestamp
  12. log-bin=mysql56-master-bin
  13. binlog-ignore-db=mysql


  14. gtid-mode=on
  15. enforce-gtid-consistency
  16. log-slave-updates


  17. binlog-format=ROW
  18. sync-master-info=1
  19. report-host=192.168.1.131
  20. report-port=3306




  21. master_info_repository=table
  22. relay_log_info_repository=table



其他两台SERVER,除了SERVER-ID,都基本相同,我就不贴了。


1. MYSQLREPLICATE 搭建主从的脚本,这里我搭建了两台从机。


点击(此处)折叠或打开

  1. mysqlreplicate --master=root:root@192.168.1.131:3306 --slave=root:root@192.168.1.132:3306;...
  2. [root@mysql56-master home]# ./replicate_create
  3. # master on 192.168.1.131: ... connected.
  4. # slave on 192.168.1.132: ... connected.
  5. # Checking for binary logging on master...
  6. # Setting up replication...
  7. # ...done.
  8. # master on 192.168.1.131: ... connected.
  9. # slave on 192.168.1.133: ... connected.
  10. # Checking for binary logging on master...
  11. # Setting up replication...
  12. # ...done.




2. mysqlrplcheck  检查主从的运行情况。



点击(此处)折叠或打开

  1. [root@mysql56-master home]# mysqlrplcheck --master=root:root@192.168.1.131:3306 --slave=root:root@192.168.1.132:3306 -s
  2. # master on 192.168.1.131: ... connected.
  3. # slave on 192.168.1.132: ... connected.
  4. Test Description Status
  5. ---------------------------------------------------------------------------
  6. Checking for binary logging on master [pass]
  7. Are there binlog exceptions? [WARN]


  8. +---------+--------+------------+
  9. | server | do_db | ignore_db |
  10. +---------+--------+------------+
  11. | master | | mysql |
  12. | slave | | mysql |
  13. +---------+--------+------------+


  14. Replication user exists? [pass]
  15. Checking server_id values [pass]
  16. Checking server_uuid values [pass]
  17. Is slave connected to master? [pass]
  18. Check master information file [pass]
  19. Checking InnoDB compatibility [pass]
  20. Checking storage engines compatibility [pass]
  21. Checking lower_case_table_names settings [pass]
  22. Checking slave delay (seconds behind master) [pass]


  23. #
  24. # Slave status:
  25. #
  26.                 Slave_IO_State : Waiting for master to send event
  27.                    Master_Host : 192.168.1.131
  28.                    Master_User : rpl
  29.                    Master_Port : 3306
  30.                  Connect_Retry : 60
  31.                Master_Log_File : mysql56-master-bin.000002
  32.            Read_Master_Log_Pos : 151
  33.                 Relay_Log_File : mysql56-slave-relay-bin.000003
  34.                  Relay_Log_Pos : 379
  35.          Relay_Master_Log_File : mysql56-master-bin.000002
  36.               Slave_IO_Running : Yes
  37.              Slave_SQL_Running : Yes
  38.                Replicate_Do_DB :
  39.            Replicate_Ignore_DB : mysql
  40.             Replicate_Do_Table :
  41.         Replicate_Ignore_Table :
  42.        Replicate_Wild_Do_Table :
  43.    Replicate_Wild_Ignore_Table :
  44.                     Last_Errno : 0
  45.                     Last_Error :
  46.                   Skip_Counter : 0
  47.            Exec_Master_Log_Pos : 151
  48.                Relay_Log_Space : 819
  49.                Until_Condition : None
  50.                 Until_Log_File :
  51.                  Until_Log_Pos : 0
  52.             Master_SSL_Allowed : No
  53.             Master_SSL_CA_File :
  54.             Master_SSL_CA_Path :
  55.                Master_SSL_Cert :
  56.              Master_SSL_Cipher :
  57.                 Master_SSL_Key :
  58.          Seconds_Behind_Master : 0
  59.  Master_SSL_Verify_Server_Cert : No
  60.                  Last_IO_Errno : 0
  61.                  Last_IO_Error :
  62.                 Last_SQL_Errno : 0
  63.                 Last_SQL_Error :
  64.    Replicate_Ignore_Server_Ids :
  65.               Master_Server_Id : 131
  66.                    Master_UUID : 4d89ad1d-bc12-11e2-87e9-080027338857
  67.               Master_Info_File : mysql.slave_master_info
  68.                      SQL_Delay : 0
  69.            SQL_Remaining_Delay : None
  70.        Slave_SQL_Running_State : Slave has read all relay log; waiting for the slave I/O thread to update it
  71.             Master_Retry_Count : 86400
  72.                    Master_Bind :
  73.        Last_IO_Error_Timestamp :
  74.       Last_SQL_Error_Timestamp :
  75.                 Master_SSL_Crl :
  76.             Master_SSL_Crlpath :
  77.             Retrieved_Gtid_Set :
  78.              Executed_Gtid_Set :
  79.                  Auto_Position : 1
  80. # ...done.
  81. [root@mysql56-master home]




3. mysqlrplshow. 显示主从的架构。



点击(此处)折叠或打开

  1. [root@mysql56-master home]# mysqlrplshow --master=root:root@192.168.1.131:3306 --discover-slaves-login=root:root -v
  2. # master on 192.168.1.131: ... connected.
  3. # Finding slaves for master: 192.168.1.131:3306


  4. # Replication Topology Graph
  5. 192.168.1.131:3306 (MASTER)
  6.    |
  7.    +--- 192.168.1.132:3306 [IO running: Yes] - (SLAVE)
  8.    |
  9.    +--- 192.168.1.133:3306 [IO running: Yes] - (SLAVE)


  10. [root@mysql56-master home]





4. mysqlfailover. 监视主从健康状态。



点击(此处)折叠或打开

  1. [root@mysql56-master home]# mysqlfailover --master=root:root@192.168.1.131:3306 --discover-slaves-login=root:root
  2. # Discovering slaves for master at 192.168.1.131:3306
  3. # Discovering slave at 192.168.1.132:3306
  4. # Found slave: 192.168.1.132:3306
  5. # Discovering slave at 192.168.1.133:3306
  6. # Found slave: 192.168.1.133:3306
  7. # Checking privileges.


  8. MySQL Replication Failover Utility
  9. Failover Mode = auto Next Interval = Tue May 14 12:27:56 2013


  10. Master Information
  11. ------------------
  12. Binary Log File Position Binlog_Do_DB Binlog_Ignore_DB
  13. mysql56-master-bin.0 151 mysql


  14. GTID Executed Set
  15. None


  16. Replication Health Status
  17. +----------------+-------+---------+--------+------------+-------------------------------------------+
  18. | host | port | role | state | gtid_mode | health |
  19. +----------------+-------+---------+--------+------------+-------------------------------------------+
  20. | 192.168.1.131 | 3306 | MASTER | UP | ON | OK |
  21. | 192.168.1.132 | 3306 | SLAVE | UP | ON | OK |
  22. | 192.168.1.133 | 3306 | SLAVE | UP | ON | Binary log and Relay log filters differ. |
  23. +----------------+-------+---------+--------+------------+-------------------------------------------+






  24. Q-quit R-refresh H-health G-GTID Lists U-UUIDs
  25. [root@mysql56-master home]





5. mysqlrpladmin. 对主从进行管理。
 

点击(此处)折叠或打开

  1. 停止从机服务:
  2.  [root@mysql56-master home]# mysqlrpladmin --master=root:root@192.168.1.131:3306 --slaves=root:root@192.168.1.132:3306,root:root@192.168.1.133:3306 stop
  3. # Checking privileges.
  4. # Performing STOP on all slaves.
  5. # Executing stop on slave 192.168.1.132:3306 Ok
  6. # Executing stop on slave 192.168.1.133:3306 Ok
  7. # ...done.
  8. [root@mysql56-master home]#
  9.  开启从机服务:
  10. [root@mysql56-master home]# mysqlrpladmin --master=root:root@192.168.1.131:3306 --slaves=root:root@192.168.1.132:3306,root:root@192.168.1.133:3306 stop
  11. # Checking privileges.
  12. # Performing STOP on all slaves.
  13. # Executing stop on slave 192.168.1.132:3306 Ok
  14. # Executing stop on slave 192.168.1.133:3306 Ok
  15. # ...done.
  16. [root@mysql56-master home]#


  17. 选择最好的备机准备以后切换用.
  18. [root@mysql56-master home]# mysqlrpladmin --master=root:root@192.168.1.131:3306 --slaves=root:root@192.168.1.132:3306,root:root@192.168.1.133:3306 elect
  19. # Checking privileges.
  20. # Electing candidate slave from known slaves.
  21. # Best slave found is located on 192.168.1.132:3306.
  22. # ...done.
  23. [root@mysql56-master home]#
  24. 进行主从切换。


  25. [root@mysql56-master home]# mysqlrpladmin --master=root:root@192.168.1.131:3306 --slaves=root:root@192.168.1.132:3306,root:root@192.168.1.133:3306 --new-master=root:root@192.168.1.132:3306 --demote-master switchover
  26. # Checking privileges.
  27. # Performing switchover from master at 192.168.1.131:3306 to slave at 192.168.1.132:3306.
  28. # Checking candidate slave prerequisites.
  29. # Checking slaves configuration to master.
  30. # Waiting for slaves to catch up to old master.
  31. # Stopping slaves.
  32. # Performing STOP on all slaves.
  33. # Demoting old master to be a slave to the new master.
  34. # Switching slaves to new master.
  35. # Starting all slaves.
  36. # Performing START on all slaves.
  37. # Checking slaves for errors.
  38. # Switchover complete.
  39. #
  40. # Replication Topology Health:
  41. +----------------+-------+---------+--------+------------+-----------------------------+
  42. | host | port | role | state | gtid_mode | health |
  43. +----------------+-------+---------+--------+------------+-----------------------------+
  44. | 192.168.1.132 | 3306 | MASTER | UP | ON | OK |
  45. | 192.168.1.131 | 3306 | SLAVE | UP | ON | OK |
  46. | 192.168.1.133 | 3306 | SLAVE | UP | ON | OK |
  47. +----------------+-------+---------+--------+------------+-----------------------------+
  48. # ...done.
  49. [root@mysql56-master home]#
  50. 显示下新的主从架构:
  51. [root@mysql56-master home]# mysqlrplshow --master=root:root@192.168.1.132:3306 --discover-slaves-login=root:root -v
  52. # master on 192.168.1.132: ... connected.
  53. # Finding slaves for master: 192.168.1.132:3306


  54. # Replication Topology Graph
  55. 192.168.1.132:3306 (MASTER)
  56.    |
  57.    +--- 192.168.1.131:3306 [IO running: Yes] - (SLAVE)
  58.    |
  59.    +--- 192.168.1.133:3306 [IO running: Yes] - (SLAVE)


  60. [root@mysql56-master home]


阅读(4482) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~