MySQL5.6.x 基于GTID的多线程复制-安装配置
MySQL5.6.x 基于GTID的多线程复制-安装配置
操作系统:
RHEL6 Or CentOS6 x86_64
mysql 版本:
mysql-5.6.20
服务器IP:
10.57.1.131 MySQL-Master 10.57.1.132 MySQL-Slave
一、yum安装mysql
# 下载mysql的rpm包
mkdir -pv /root/soft cd /root/soft
#这里提供三个版本的官方64位rpm下载路径,根据自己的系统平台选择对应的rpm下载
# RHEL6 And CentOS6 x86_64 的rpm包
wget http://dev.mysql.com/get/Downloads/MySQL-5.6/MySQL-shared-compat-5.6.20-1.el6.x86_64.rpm wget http://dev.mysql.com/get/Downloads/MySQL-5.6/MySQL-test-5.6.20-1.el6.x86_64.rpm wget http://dev.mysql.com/get/Downloads/MySQL-5.6/MySQL-devel-5.6.20-1.el6.x86_64.rpm wget http://dev.mysql.com/get/Downloads/MySQL-5.6/MySQL-client-5.6.20-1.el6.x86_64.rpm wget http://dev.mysql.com/get/Downloads/MySQL-5.6/MySQL-server-5.6.20-1.el6.x86_64.rpm wget http://dev.mysql.com/get/Downloads/MySQL-5.6/MySQL-shared-5.6.20-1.el6.x86_64.rpm wget http://dev.mysql.com/get/Downloads/MySQL-5.6/MySQL-embedded-5.6.20-1.el6.x86_64.rpm
# RHEL5 And CentOS5 x86_64 的rpm包
wget http://dev.mysql.com/get/Downloads/MySQL-5.6/MySQL-embedded-5.6.20-1.rhel5.x86_64.rpm wget http://dev.mysql.com/get/Downloads/MySQL-5.6/MySQL-shared-compat-5.6.20-1.rhel5.x86_64.rpm wget http://dev.mysql.com/get/Downloads/MySQL-5.6/MySQL-test-5.6.20-1.rhel5.x86_64.rpm wget http://dev.mysql.com/get/Downloads/MySQL-5.6/MySQL-devel-5.6.20-1.rhel5.x86_64.rpm wget http://dev.mysql.com/get/Downloads/MySQL-5.6/MySQL-client-5.6.20-1.rhel5.x86_64.rpm wget http://dev.mysql.com/get/Downloads/MySQL-5.6/MySQL-server-5.6.20-1.rhel5.x86_64.rpm wget http://dev.mysql.com/get/Downloads/MySQL-5.6/MySQL-shared-5.6.20-1.rhel5.x86_64.rpm
# RHEL7 And CentOS7 x86_64 的rpm包
wget http://dev.mysql.com/get/Downloads/MySQL-5.6/MySQL-shared-compat-5.6.20-1.el7.x86_64.rpm wget http://dev.mysql.com/get/Downloads/MySQL-5.6/MySQL-test-5.6.20-1.el7.x86_64.rpm wget http://dev.mysql.com/get/Downloads/MySQL-5.6/MySQL-devel-5.6.20-1.el7.x86_64.rpm wget http://dev.mysql.com/get/Downloads/MySQL-5.6/MySQL-client-5.6.20-1.el7.x86_64.rpm wget http://dev.mysql.com/get/Downloads/MySQL-5.6/MySQL-server-5.6.20-1.el7.x86_64.rpm wget http://dev.mysql.com/get/Downloads/MySQL-5.6/MySQL-shared-5.6.20-1.el7.x86_64.rpm wget http://dev.mysql.com/get/Downloads/MySQL-5.6/MySQL-embedded-5.6.20-1.el7.x86_64.rpm
# 注意上面三项只下载一项即可
# 各rpm包简介
MySQL-server: mysql
# mysql官方提供了7个rpm,当然并不是所有的包都安装的,根据自己的需要选择性的安装刚才下载的几个rpm包
# 一般来说安装 MySQL-server、MySQL-client、MySQL-devel、MySQL-shared、MySQL-shared-compat 这几个rpm包已经足够了,安装如下
# 安装所下载的rpm包
yum localinstall MySQL-server* MySQL-client* MySQL-shared* MySQL-shared-compat* MySQL-devel*
# 将mysql服务设置开机自动启动
chkconfig --add mysql chkconfig mysql on
# 建立mysql数据目录
mkdir -p /data/mysql/data
# 启动mysql服务
server mysql start
二、基于mysql-5.6.x的GTID的多线程复制
1、配置 Master节点
vim /etc/my.cnf
# 内容如下, End结束
[mysqld] # mysql服务器监听的端口 port=3306 # 套接字文件路径 socket=/data/mysql/data/mysql.sock # 数据存储路径 datadir=/data/mysql/data/ # 启用bin-log日志 log-bin=master-bin # binlog日志的格式 binlog-format=ROW # 服务器ID 在主从或主主等环境中的id值一定要是全局唯一的 server-id=1 # 关闭dns解析 skip-name-resolve # 从服务器是否将事件的写操作的信息记录到日志中 log-slave-updates=true # 是否启用GTID的功能 gtid-mode=on # 是否强制GTID的一致性 enforce-gtid-consistency=true # show slave hosts; 所显示的ip及端口 report-port=3306 report-host=10.57.1.131 # slave logs master status and connection information # slave logs ,master status,和连接信息 是记录在文件(FILE)中还是表(TABLE)中 master-info-repository=TABLE relay-log-info-repository=TABLE # 同步master-info信息 sync-master-info=1 # 从服务器的sql线程数,值最好跟数据库的个数一致,0表示禁用多线程功能 slave-parallel-workers=2 # 是否校验binlog日志的完整性,以下三个选项是启用在复制功能中的校验功能 binlog-checksum=CRC32 master-verify-checksum=1 slave-sql-verify-checksum=1 # 启用用于在而进制日志记录事件的相关信息,可降低故障排除的复杂度 binlog-rows-query-log_events=1 [mysqld_safe] log-error=/var/log/mysqld.log [client] socket=/data/mysql/data/mysql.sock # End
# 初始化mysql数据库
/usr/bin/mysql_install_db --user=mysql --datadir=/data/mysql/data
# 重启mysql服务
service mysqld restart
# 创建复制用户
mysql> GRANT REPLICATION SLAVE ON *.* TO slave@"10.57.1.131" IDENTIFIED BY ‘redhat‘; mysql> FLUSH PRIVILEGES;
2、配置Slave节点
vim /etc/my.cnf
# 内容如下, End结束
[mysqld] datadir=/data/mysql/data port=3306 socket=/data/mysql/data/mysql.sock log-bin=mysql-bin server-id=2 slave-parallel-workers=2 binlog-format=ROW log-slave-updates=true gtid-mode=on enforce-gtid-consistency=true master-info-repository=TABLE relay-log-info-repository=TABLE sync-master-info=1 binlog-checksum=CRC32 master-verify-checksum=1 slave-sql-verify-checksum=1 binlog-rows-query-log_events=1 report-port=3306 report-host=10.57.1.132 [mysqld_safe] log-error=/var/log/mysqld.log [client] socket=/data/mysql/data/mysql.sock # End
# 重启mysql服务
service mysqld restart
mysql> CHANGE MASTER TO MASTER_HOST=‘10.57.1.131‘, MASTER_USER=‘slave‘,MASTER_PASSWORD=‘redhat‘, MASTER_AUTO_POSITION=1;
mysql> START SLAVE;
3、测试
# 首先在主库上执行一个写操作,然后在从库上看有没有同步过来即可
本文出自 “往事随风” 博客,谢绝转载!
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。