项目分步15:数据迁移

架构图解

192.168.4.66

192.168.4.10

192.168.4.88

拷贝PXC软件到3台服务器

拷贝mysql-5.7.17.tar 软件到 pxcnode66 主机

配置从服务器

• 把pxcnode66主机配置为mysql11的从服务器:

– 安装软件mysql-5.7.17.tar

– 修改配置文件 (指定server_id)

– 启动mysqld服务

– 确保数据一致

– 指定主服务器

– 查看状态信息 show slave

status\G;


[root@pxcnode66 ~]# tar -xvf mysql-5.7.17.tar

[root@pxcnode66 ~]# yum -y  install mysql-community-*.rpm

[root@pxcnode66 mysql]# vim /etc/my.cnf

[root@pxcnode66 mysql]# systemctl start mysqld

[root@pxcnode66 ~]# grep password /var/log/mysqld.log

mysql> alter user  root@"localhost" identified by"123qqq...A";

Query OK, 0 rows affected (0.00 sec)

mysql> exit

Bye


确保数据一致

[root@mysql11 ~]# rpm -ivh libev-4.15-1.el6.rf.x86_64.rpm

[root@mysql11 ~]# yum -y  install percona-xtrabackup-24-2.4.7-1.el7.x86_64.rpm

[root@mysql11 ~]# innobackupex  --user root --password 123qqq...A  --slave-info /allbak --no-timestamp

[root@mysql11 ~]# scp -r/allbak  [email protected]:/root/


[root@pxcnode66 ~]# cd PXC

[root@pxcnode66 ~]# rpm -ivh libev-4.15-1.el6.rf.x86_64.rpm

[root@pxcnode66 ~]# yum -y  install percona-xtrabackup-24-2.4.13-1.el7.x86_64.rpm

[root@pxcnode66 ~]# innobackupex --apply-log /root/allbak/

[root@pxcnode66 ~]# innobackupex --copy-back /root/allbak/

[root@pxcnode66 ~]# chown -R mysql:mysql /var/lib/mysql

[root@pxcnode66 ~]# systemctlstart  mysqld

[root@pxcnode66 ~]# cat/root/allbak/xtrabackup_info  | grepmaster11

mysql> change master to  master_host="192.168.4.11" ,master_user="repluser" , master_password="123qqq...A" ,master_log_file="master11.000005" , master_log_pos=154;

mysql> show slave status\G" | grep -i 192.168.4.11


部署PXC集群

配置第1台 PXC 集群服务器192.168.4.66

在pxcnode66主机,做如下配置:

– 停止mysqld服务、卸载mysqld服务软件

– 安装PXC软件、修改配置文件、启动mysql服务

– 数据库管理员登录、用户授权、查看状态信息

[root@pxcnode66 ~]# rpm -qa | grep -i mysql 一定要把查出来的包删干净了,不然是装不上包的

[root@pxcnode66 ~]# rpm -e --nodeps

mysql-community-server mysql-community-embedded-compat mysql-community-common

mysql-community-client mysql-community-devel mysql-community-test

mysql-community-libs-compat mysql-community-minimal-debuginfo

mysql-community-libs mysql-community-embedded mysql-community-embedded-devel


安装PXC软件

[root@pxcnode66 PXC]# rpm -ivh qpress-1.1-14.11.x86_64.rpm

[root@pxcnode66 PXC]# tar -xvf Percona-XtraDB-Cluster-5.7.25-31.35-r463-el7-x86_64-bundle.tar

[root@pxcnode66 PXC]#  yum -y install Percona-XtraDB-Cluster-*.rpm


修改配置文件

[root@pxcnode66 PXC]# vim /etc/percona-xtradb-cluster.conf.d/mysqld.cnf

server-id=66

[root@pxcnode66 PXC]# vim /etc/percona-xtradb-cluster.conf.d/wsrep.cnf

wsrep_cluster_address=gcomm: //不需要写ip地址

wsrep_node_address=192.168.4.66

wsrep_cluster_name=pxc-cluster

wsrep_node_name=pxcnode66

wsrep_sst_auth="sstuser:123qqq...A"

[root@pxcnode66 PXC]# systemctl start mysql

[root@pxcnode66 PXC]# ss -antulp | grep mysql


[root@pxcnode66 PXC]# mysql -uroot -p123qqq...A

[root@pxcnode66 PXC]# mysql -uroot -p123qqq...A

mysql> grant all on *.* to sstuser@"localhost" identified by "123qqq...A";

mysql> show slave status\G;


| wsrep_ready                      |ON

客户端测试

主服务器上输入新数据

[root@mysql11 ~]# mysql -uroot -p123qqq...A

mysql> insert into user()

values("bob");

Pxcnode66上查看能否同步主服务器上的数据

mysql> select * from gamedb.user where name="bob";


配置第二台PXC服务器

在pxcnode77主机作如下配置:

– 安装PXC软件、修改配置文件、启动mysql服务

– 数据库管理员登录、查看状态信息、查看数据

安装pxc软件

[root@pxcnode10 ~]# cd /03/PXC/

[root@pxcnode10 PXC]# rpm -ivh libev-4.15-1.el6.rf.x86_64.rpm

[root@pxcnode10 PXC]# yum -y install percona-xtrabackup-24-2.4.13-1.el7.x86_64.rpm

[root@pxcnode10 PXC]# rpm -ivh qpress-1.1-14.11.x86_64.rpm

[root@pxcnode10 PXC]# tar -xvfPercona-XtraDB-Cluster-5.7.25-31.35-r463-el7-x86_64-bundle.tar  

[root@pxcnode10 PXC]# yum -y install Percona-XtraDB-Cluster-*.rpm

修改配置文件

[root@pxcnode10 PXC]# vim /etc/percona-xtradb-cluster.conf.d/mysqld.cnf

[mysqld]

server-id=10

[root@pxcnode10 PXC]# vim /etc/percona-xtradb-cluster.conf.d/wsrep.cnf

wsrep_cluster_address=gcomm://192.168.4.66,192.168.4.10

wsrep_node_address=192.168.4.10

wsrep_cluster_name=pxc-cluster

wsrep_node_name=pxcnode10

wsrep_sst_auth="sstuser:123qqq...A"


启动服务

[root@pxcnode10 ~]# systemctl start mysql

[root@pxcnode10 ~]# systemctl enable mysql

[root@pxcnode10 ~]# ss -antulp | grep mysql

[root@pxcnode10 ~]# ss -antulp | grep mysql


mysql> show status like "%wsrep%";


mysql> select * from gamedb.user;


配置第三台PXC服务器

在pxcnode88主机做如下配置:

– 安装PXC软件、修改配置文件、启动mysql服务

– 数据库管理员登录、查看状态信息、查看数据


安装PXC软件

[root@pxcnode88 PXC]# rpm -ivh libev-4.15-1.el6.rf.x86_64.rpm

[root@pxcnode88 PXC]# yum -y install percona-xtrabackup-24-2.4.13-1.el7.x86_64.rpm

[root@pxcnode88 PXC]# yum -y install qpress-1.1-14.11.x86_64.rpm

[root@pxcnode88 PXC]# tar -xf Percona-XtraDB-Cluster-5.7.25-31.35-r463-el7-x86_64-bundle.tar

[root@pxcnode88 PXC]# yum -y install Percona-XtraDB-Cluster-*.rpm

修改配置文件

[root@pxcnode88 ~]# vim /etc/percona-xtradb-cluster.conf.d/mysqld.cnf

[mysqld]

server-id=88

wsrep_cluster_address=gcomm://192.168.4.77

wsrep_node_address=192.168.4.88

wsrep_cluster_name=pxc-cluster

wsrep_node_name=pxcnode88

wsrep_sst_auth="sstuser:123qqq...A"


启动服务

[root@pxcnode88 ~]# systemctl start mysql

[root@pxcnode88 ~]# systemctl enable mysql

[root@pxcnode88 ~]# netstat -antulp | grep 3306

[root@pxcnode88 ~]# netstat -antulp | grep 4567

[root@pxcnode88 ~]# mysql -uroot -p123qqq...A

mysql> show status like "%wsrep%";

| wsrep_ready                      |ON

mysql> select * from gamedb.user;


公共配置

修改PXC成员ip列表:

在三台数据库服务器上做如下配置

[root@pxcnode88 ~]# vim /etc/percona-xtradb-cluster.conf.d/wsrep.cnf

wsrep_cluster_address=gcomm://192.168.4.66,192.168.4.77,192.168.4.88

[root@pxcnode88 ~]# systemctl restart mysql

[root@pxcnode88 ~]# systemctl enable mysql

mysql> show status like "%wsrep%";

| wsrep_incoming_addresses         | 192.168.4.88:3306,192.168.4.10:3306,192.168.4.66:3306

[root@pxcnode10 ~]# vim /etc/percona-xtradb-cluster.conf.d/wsrep.cnf

wsrep_cluster_address=gcomm://192.168.4.66,192.168.4.88,192.168.4.10

[root@pxcnode10 ~]# systemctl restart mysql

[root@pxcnode10 ~]# systemctl enablemysql

| wsrep_incoming_addresses         |192.168.4.88:3306,192.168.4.66:3306,192.168.4.10:3306 |


[root@pxcnode66 ~]# vim /etc/percona-xtradb-cluster.conf.d/wsrep.cnf

wsrep_cluster_address=gcomm://192.168.4.10,192.168.4.88,192.168.4.66

[root@pxcnode66 ~]# systemctl restart mysql

[root@pxcnode66 ~]# systemctl enable mysql

mysql> show status like  "%wsrep%";

| wsrep_incoming_addresses         |192.168.4.66:3306,192.168.4.88:3306,192.168.4.10:3306 |


测试配置

[root@client ~]# mysql -h 192.168.4.11 -uyaya99 -p123qqq...A

MySQL [(none)]> insert into gamedb.user() values("plj")

66上查询数据

mysql> select * from gamedb.user;

| plj  |

10上查询数据

mysql> select * from gamedb.user;

| plj  |

77上查询

mysql> select * from gamedb.user;

| plj  |

你可能感兴趣的:(项目分步15:数据迁移)