使用percona xtradb cluster的IST(Incremental State Transfer)特性添加新节点,防止新节点加入时使用SST(State SnapShop Transfer)传输全量数据
环境:两台虚拟机
192.168.0.48 node1
192.168.0.49 新加入节点
注意事项:测试环境建议关掉iptables,selinux
1.两个节点都先下载并安装好xtrabackup
shell > yum install perl-IO-Socket-SSL perl-DBD-MySQL perl-Time-HiRes socat nc libaio rsync -y #安装需要的依赖包
shell > rpm -ivh percona-xtrabackup-2.2.11-1.el6.x86_64.rpm
2.下载安装Percona-XtraDB-Cluster
3.先把两个节点的PXC都按照安装官方mysql的步骤安装上去并初始化好实例
shell > tar xf Percona-XtraDB-Cluster-5.6.24-rel72.2-25.11..Linux.x86_64.tar.gz -C /usr/local/services/
shell > cd /usr/local/services/
shell > ln -s Percona-XtraDB-Cluster-5.6.24-rel72.2-25.11..Linux.x86_64/ mysql
shell > cd mysql
shell > groupadd mysql
shell > useradd -r -g mysql mysql
shell > chown -R mysql .
shell > chgrp -R mysql .
shell > cp support-files/my-default.cnf /etc/my.cnf
shell > mkdir -p /data/mysql/data
shell >
shell > ./scripts/mysql_install_db --user=mysql --basedir=/usr/local/services/mysql --datadir=/data/mysql/data/
#如果在初始化的时候报libssl.so.6和libcrypto.so.6两个动态库文件不存在的,就做下链接:
shell > ln -s /usr/lib64/libssl.so /usr/lib64/libssl.so.6
shell > ln -s /usr/lib64/libcrypto.so /usr/lib64/libcrypto.so.6
shell > chown -R root .
shell > cp support-files/mysql.server /etc/init.d/mysqld
shell > chmod 755 /etc/init.d/mysqld
shell > vim /etc/init.d/mysqld
在命令模式下修改下basedir的路径:
% s/usr\/local\/Percona-XtraDB-Cluster-5.6.24-rel72.2-25.11..Linux.x86_64/usr\/local\/services\/mysql/g
4.配置节点1的PXC参数:
/etc/my.cnf添加如下内容:
[mysqld]
basedir = /usr/local/services/mysql
datadir = /data/mysql/data
binlog_format=ROW #binlog格式必须为row
default_storage_engine=InnoDB #暂时不支持其他存储引擎,只支持innodb,当然可以支持myisam,需要另外参数打开
innodb_autoinc_lock_mode=2 #自增锁的优化
log_bin=mysql-bin
server-id=483306
#并在[mysqld]段落添如下PXC相关参数:
wsrep_provider=/usr/local/services/mysql/lib/libgalera_smm.so #库文件
wsrep_cluster_address=gcomm://192.168.0.48,192.168.0.49 #节点中所有ip
wsrep_node_address=192.168.0.48 #节点的ip
wsrep_slave_threads=2 #开启的复制线程数,cpu核数*2
wsrep_cluster_name=pxc-xiaoboluo #集群名字
wsrep_sst_auth=sst:xiaoboluo #sst模式需要的用户名和密码
wsrep_sst_method=xtrabackup-v2 #采用什么方式复制数据。还支持mysqldump,rsync
5.启动,进行授权操作,对于第一个节点必须以特殊方式启动,如下:
查看启动选项:shell > /etc/init.d/mysqld --help
Usage: mysql {start|stop|restart|restart-bootstrap|reload|force-reload|status|bootstrap-pxc} [ MySQL (Percona XtraDB Cluster) options ]
启动:
shell > /etc/init.d/mysqld bootstrap-pxc
Bootstrapping PXC (Percona XtraDB Cluster) SUCCESS! MySQL (Percona XtraDB Cluster) running (37791)
进行查看,可以发现启动两个端口:
shell > netstat -ntupl |grep mysqld
tcp 0 0 0.0.0.0:4567 0.0.0.0:* LISTEN 37791/mysqld
tcp 0 0 :::3306 :::* LISTEN 37791/mysqld
6.对复制帐号进行授权,并修改root密码,推荐使用grant方式
mysql登录:
mysql> GRANT RELOAD, LOCK TABLES, REPLICATION CLIENT ON * . * TO 'sst'@'localhost' IDENTIFIED BY 'xiaoboluo';
Query OK, 0 rows affected (0.05 sec)
mysql> grant all on *.* to root@'192.168.0.%' identified by 'password' with grant option;
Query OK, 0 rows affected (0.00 sec)
mysql> grant all on *.* to root@'localhost' identified by 'password' with grant option;
Query OK, 0 rows affected (0.01 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
7.到这里我们的第一个节点就搞定了,把新节点用传统复制的方式添加进集群是重点(如果是集群是新搭建的,或者说直接使用SST的方式加入新节点,那么新节点的配置就直接按照前面的主节点配置来就可以了,只是把wsrep_node_address改成对应节点的IP即可,而对于已经运行了一段事件的集群,新加入节点使用SST传送全量数据的方式同步的代价比较高,所以下面讨论一个IST方式加入新节点同步数据的方式):
1)、在node1上创建一个复制帐号:
mysql> grant replication slave on *.* to 'repl'@'192.168.0.%' identified by 'repl';
Query OK, 0 rows affected (0.01 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
2)、在node1上导出全量备份数据,为了方便使用mysqldump来导出备份,并scp到新节点上:
shell > mysqldump --single-transaction --master-data=2 -u root -p'password' -A > db.sql
查看到db.sql文件中的change master语句,后边要使用:
shell > grep '\-\- CHANGE MASTER' db.sql
-- CHANGE MASTER TO MASTER_LOG_FILE='mysql-bin.000001', MASTER_LOG_POS=120;
shell > scp db.sql 192.168.0.49:/tmp
3)、在新节点上先添加如下配置参数到/etc/my.cnf中,先不要添加PXC相关的配置项:
basedir = /usr/local/services/mysql
datadir = /data/mysql/data
binlog_format=ROW #binlog格式必须为row
default_storage_engine=InnoDB #暂时不支持其他存储引擎,只支持innodb,当然可以支持myisam,需要另外参数打开
innodb_autoinc_lock_mode=2 #自增锁的优化
log_bin=mysql-bin
server-id=493306
4)、把新节点的实例启动起来,修改root密码,并导入db.sql:
shell > service mysqld start
Starting MySQL (Percona XtraDB Cluster).. SUCCESS!
mysql> grant all on *.* to root@'192.168.0.%' identified by 'password' with grant option;
Query OK, 0 rows affected (0.00 sec)
mysql> grant all on *.* to root@'localhost' identified by 'password' with grant option;
Query OK, 0 rows affected (0.01 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql > source /tmp/db.sql;
5)、使用change master语句开启复制(把前面db.sql文件中的change master语句补全,并在新节点上执行):
mysql > CHANGE MASTER TO MASTER_LOG_FILE='mysql-bin.000001', MASTER_LOG_POS=120,MASTER_USER='repl',MASTER_PASSWORD='repl',MASTER_HOST='192.168.0.48',MASTER_PORT=3306;
mysql> start slave;
Query OK, 0 rows affected (0.00 sec)
mysql> show slave status\G;
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 192.168.0.48
Master_User: repl
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin.000001
Read_Master_Log_Pos: 120
Relay_Log_File: test_web2-relay-bin.000002
Relay_Log_Pos: 283
Relay_Master_Log_File: mysql-bin.000001
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: 120
Relay_Log_Space: 460
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: 483306
Master_UUID: bbba431d-bff5-11e5-b143-000c291c9bd0
Master_Info_File: /data/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
1 row in set (0.00 sec)
6)、同步正常之后,到主库上去创建一个库,表,并写入几条测试数据,然后到从库上看看同步成功没有(因为这里是测试环境,node1节点上没有数据,所以需要搞点测试数据,如果线上环境这步骤可以省略,直接在上一步骤同步建立完之后stop slave,再看一下show slave status记下Relay_Master_Log_File和Exec_Master_Log_Pos的二进制日志坐标即可进入跳过这个步骤)
在node1上创建测试数据
mysql> create database xiaoboluo;
Query OK, 1 row affected (0.02 sec)
mysql> use xiaoboluo
Database changed
mysql> create table test_xiaoboluo(id int unsigned not null auto_increment primary key,test varchar(20));
Query OK, 0 rows affected (0.43 sec)
mysql> insert into test_xiaoboluo(test) values('test1'),('test2'),('test3'),('test4');
Query OK, 4 rows affected (0.02 sec)
Records: 4 Duplicates: 0 Warnings: 0
mysql> select * from test_xiaoboluo;
+----+-------+
| id | test |
+----+-------+
| 1 | test1 |
| 2 | test2 |
| 3 | test3 |
| 4 | test4 |
+----+-------+
4 rows in set (0.00 sec)
mysql>
到新节点上去查看下:
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| test |
| xiaoboluo |
+--------------------+
5 rows in set (0.00 sec)
mysql> use xiaoboluo
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> select * from test_xiaoboluo;
+----+-------+
| id | test |
+----+-------+
| 1 | test1 |
| 2 | test2 |
| 3 | test3 |
| 4 | test4 |
+----+-------+
4 rows in set (0.00 sec)
7)、在新节点上停掉同步,并查看show slave status\G中的Relay_Master_Log_File和Exec_Master_Log_Pos的二进制日志坐标,记下它后边有用,然后停掉新节点的mysqld实例:
mysql> stop slave;
Query OK, 0 rows affected (0.01 sec)
mysql> show slave status\G;
*************************** 1. row ***************************
Slave_IO_State:
Master_Host: 192.168.0.48
Master_User: repl
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin.000001
Read_Master_Log_Pos: 662
Relay_Log_File: test_web2-relay-bin.000002
Relay_Log_Pos: 825
Relay_Master_Log_File: mysql-bin.000001
Slave_IO_Running: No
Slave_SQL_Running: No
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: 662
Relay_Log_Space: 1002
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: NULL
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: 483306
Master_UUID: bbba431d-bff5-11e5-b143-000c291c9bd0
Master_Info_File: /data/mysql/data/master.info
SQL_Delay: 0
SQL_Remaining_Delay: NULL
Slave_SQL_Running_State:
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.00 sec)
已经执行到的日志坐标是:
Relay_Master_Log_File: mysql-bin.000001
Exec_Master_Log_Pos: 662
停掉mysqld实例:
shell > service mysqld stop
Shutting down MySQL (Percona XtraDB Cluster).. SUCCESS!
8)、到node1节点上flush logs以下,然后使用新节点上找到的同步坐标查找xid,这个xid就是新节点在gcache中需要从什么位置开始同步数据:
shell > cd /data/mysql/data/
shell > mysqlbinlog -v mysql-bin.000001 |grep -i xid
#160121 13:11:33 server id 483306 end_log_pos 662 CRC32 0x9e460154 Xid = 8
可以看到,在主库上对应二进制日志坐标的xid=8,记下这个数字,后边有用,顺序在node1上查看下这个xid是否在gcache缓存中有效:
mysql> show status like '%wsrep_local_cached_downto%';
+---------------------------+-------+
| Variable_name | Value |
+---------------------------+-------+
| wsrep_local_cached_downto | 6 |
+---------------------------+-------+
1 row in set (0.00 sec)
发现从6开始,说明xid为8有效,继续后面的步骤
9)、查看node1上的grastate.dat文件:
shell > cat grastate.dat
# GALERA saved state
version: 2.1
uuid: bd355b13-bff5-11e5-bed5-0f40dadab349
seqno: -1
cert_index:
seqno为-1就表示这个节点已经在集群中,把这个文件复制到新节点的datadir目录下,并修改为mysql用户属主:
shell > scp grastate.dat 192.168.0.49:/data/mysql/data/
shell > chown mysql.mysql /data/mysql/data/grastate.dat
10)、修改新节点上/data/mysql/data/grastate.dat文件中的seqno为前面找到的xid:
shell > cat /data/mysql/data/grastate.dat
# GALERA saved state
version: 2.1
uuid: bd355b13-bff5-11e5-bed5-0f40dadab349
seqno: 8
cert_index:
11)、此时把PXC参数全部加进新节点的my.cnf中:
#并在[mysqld]段落添如下PXC相关参数:
wsrep_provider=/usr/local/services/mysql/lib/libgalera_smm.so #库文件
wsrep_cluster_address=gcomm://192.168.0.48,192.168.0.49 #节点中所有ip
wsrep_node_address=192.168.0.49 #节点的ip
wsrep_slave_threads=2 #开启的复制线程数,cpu核数*2
wsrep_cluster_name=pxc-xiaoboluo #集群名字
wsrep_sst_auth=sst:xiaoboluo #sst模式需要的用户名和密码
wsrep_sst_method=xtrabackup-v2 #采用什么方式复制数据。还支持mysqldump,rsync
12)、按照常规启动新节点,然后查看错误日志是否有错误,没有错误就在集群中的两个节点上各写一条数据, 验证下数据是否都能相互同步成功
shell > service mysqld start
Starting MySQL (Percona XtraDB Cluster)........... SUCCESS!
在node1节点的xiaoboluo库test_xiaoboluo表中写入一行数据:
mysql> insert into test_xiaoboluo(test) values('test5');
Query OK, 1 row affected (0.00 sec)
在新节点上查询数据:
mysql> select * from test_xiaoboluo;
+----+-------+
| id | test |
+----+-------+
| 1 | test1 |
| 2 | test2 |
| 3 | test3 |
| 4 | test4 |
| 5 | test5 |
+----+-------+
5 rows in set (0.00 sec)
已经同步过来了,在新节点上插入一行数据:
mysql> insert into test_xiaoboluo(test) values('test6');
Query OK, 1 row affected (0.03 sec)
然后去Node1上查询:
mysql> select * from test_xiaoboluo;
+----+-------+
| id | test |
+----+-------+
| 1 | test1 |
| 2 | test2 |
| 3 | test3 |
| 4 | test4 |
| 5 | test5 |
| 6 | test6 |
+----+-------+
6 rows in set (0.00 sec)
也已经同步过来了,至此,使用IST方式加入PXC新节点的方式目的达到。且同步瞬间已经正常了,新节点上的slave信息可以不需要了,直接stop slave;reset slave all即可。
- Percona Xtradb Cluster的设计与实现
Percona Xtradb Cluster的设计与实现 Percona Xtradb Cluster的实现是在原mysql代码上通过Galera包将不同的mysql实例连接起来,实现了multi ...
- 移动基于Percona XTRADB Cluster的大数据解决方式
移动基于Percona XTRADB Cluster的大数据解决方式 一.移动的去IOE之旅 近期由于"棱镜门"事件的曝光.引起了国家对信息安全问题的注 ...
- mysql高可用之PXC(Percona XtraDB Cluster)
简介 Percona XtraDB Cluster是MySQL高可用性和可扩展性的解决方案,Percona XtraDB Cluster提供的特性如下: 1).同步复制,事务要么在所有节点提交或不提交 ...
- Percona XtraDB Cluster
简介 Percona XtraDB Cluster是MySQL高可用性和可扩展性的解决方案,Percona XtraDB Cluster提供的特性如下: 1.同步复制,事务要么在所有节点提交或不提交. ...
- PXC5.7(Percona XtraDB Cluster)+HAproxy+Keepalived 集群部署
Percona-XtraDB-Cluster+Haproxy 搭建集群环境 环境准备及服务器信息: 配置防火墙 firewall-cmd --add-port=3306/tcp --permanent ...
- Percona XtraDB Cluster vs Galera Cluster vs MySQL Group Replication
Percona XtraDB Cluster vs Galera Cluster vs MySQL Group Replication Overview Galera Cluster 由 Coders ...
- Percona XtraDB Cluster集群
官网参考地址: https://www.percona.com/doc/percona-xtradb-cluster/LATEST/configure.html 前期准备: 都用的root权限或使用s ...
- Percona XtraDB Cluster高可用与状态快照传输(PXC 5.7 )
Percona XtraDB Cluster(下称PXC)高可用集群支持任意节点在运行期间的重启,升级或者意外宕机,即它解决了单点故障问题.那在这个意外宕机或者重启期间,该节点丢失的数据如何再次进行同 ...
- 搭建高可用mysql系列(2)-- Percona XtraDB Cluster 安装
本文主要介绍在 centos 下 Percona XtraDB Cluster(下文简称PXC) 的安装, 个人的系统版本信息如下: [root@c2-d09 worker]# more /etc/r ...
随机推荐
- ORA-16179: incremental changes to "log_archive_dest_1" not allowed with SPFILE
SQL> alter system set log_archive_dest_1='E:\arch ' scope=both; alter system set log_archive_dest ...
- 同一个主机上的JVM实例之间通信
hadoop yarn里用了RPC调用.NM里面文件本地化类ContainerLocalizer用RPC心跳方式跟本机的ResourceLocalizationService通信. 用shared m ...
- networkcommon v3开源消息框架资料
http://www.cnblogs.com/csdev/category/870400.html
- Java 类型转换以及Object转成其他类型
Object转int int count=(int)map.get("count") int count=Integer.parseInt((String)map.get(&quo ...
- How to use Ubuntu Linux in virtual box
安装git : yum install git 查询包: rpm -ql git 打开文件夹目录: nautilus 目录路径
- java ajax传值 中文乱码
String remark = new String(this.getRequest().getParameter("remark").getBytes("iso885 ...
- php-引号中出现$
当双引号中包含变量时,变量对应的值会与双引号中的内容连接在一起: 当单引号中包含变量时,变量会被当做字符串输出. 慕课网,I love you!慕课网,$love
- 从一个例子讲解拷贝构造函数与return
#include "iostream" using namespace std; class Location { public: Location(, ) { X = xx; Y ...
- java中从Spring、Hibernate和Struts框架的action、service和dao三层结构异常处理体系设计
Spring的事务实现采用基于AOP的拦截器来实现,如果没有在事务配置的时候注明回滚的checked exception,那么只有在发生了unchecked exception的时候,才会进行事务回滚 ...
- 关于mybatis的参数2个使用经验(类似于struts2的通配所有页面的action配置,xmlsq语句参数类型为基本类型时的快捷指定办法)
1.我们都知道在struts2中为防止浏览器绕过struts过滤器直接请求页面,所以我们都会配置一个拦截所有页面的action,如下: <action name="*"> ...