超酷小 发表于 2018-9-26 13:45:35

4 MySQL 5.7 高可用

  MySQL 5.7主从复制



  https://dev.mysql.com/doc/refman/5.7/en/replication-gtids-howto.html

  GTID(GlobalTransaction>  设置gtid模式,在my.cnf里面的mysqld选项卡里面设置,设置完后,重启mysql服务生效:
  
  gtid_mode=ON
  log-slave-updates=ON
  enforce-gtid-consistency=ON
  mysql> change master to
  master_host=‘主库IP',
  master_port=主库端口,
  master_user='repl',
  master_password=‘repl密码',
  master_auto_position=1;
  mysql> start slave;
  PS:其中这里有差别,以前非gtid的是用master_log_file='mysql-bin.000009',master_log_pos=154;而gtid就采用了master_auto_positon=1;来自动同步主库的binlog了。
  查看从库复制状态,是双YES,而且Seconds_Behind_Master: 0:

  Tell the slave to use the master with GTID based transactions as the replication data source, and to use GTID-based auto-positioning rather than file-based positioning. Issue a CHANGE MASTER TO statement on the slave, including the MASTER_AUTO_POSITION option in the statement to tell the slave that the master's transactions are>  查看备机信息
  1.主库show slave hosts;

[*]SELECT * FROM information_schema.PROCESSLIST WHERE COMMAND = 'Binlog Dump';  查看同步状态
  1.Show slave status\G
[*]SELECT SERVICE_STATE FROM performance_schema.replication_connection_status;
  搭建级联备库

[*]需设置log_slave_updates=1,使备库生成binlog
[*]备份数据库并通过备份建立新数据库
[*]新数据库与备库同步
[*]  新数据库改为与主库同步
  reset slave;
  change master to
  master_host=‘主库IP',
  master_port=主库端口,
  master_user='repl',
  master_password=‘repl密码',
  master_auto_position=1;
[*]su - mysql  2.登录默认(3306)端口的实例
  source .profile
  mysql –uroot –p –h127.0.0.1 –P3306
  3.登录3307端口的实例
  source .p3307
  mysql –uroot –p –h127.0.0.1 –P3307
  知识点整理:
  1、.mysql_history文件记录mysql用户执行的命令,存在安全隐患,需要进行软连接处理。lns -l /dev/null $HOME/.mysql_history
  2、mysql 如何搭建半同步和异步备库。
  3、mysql环境安装。注意修改/relay_log文件夹的属主,VIP配置。

页: [1]
查看完整版本: 4 MySQL 5.7 高可用