前段时间,老张给大家介绍了企业中主流MySQL高可用集群架构三部曲中的前两部,有不了解的同学可以去访问我之前的博客内容。
第一部曲直通车>> 企业中MySQL主流高可用架构实战三部曲之MHA
第二部曲直通车>>企业中MySQL高可用集群架构三部曲之MM+keepalived
独家新课程上线>>MySQL体系结构深入剖析及实战DBA视频课程
不足之处总结:
192.168.56.100 node1192.168.56.101 node2
192.168.56.102 node3
三台机器的防火墙iptables都要关闭,三台机器的server-id不能一样。
PXC软件包下载:
https://www.percona.com/downloads/Percona-XtraDB-Cluster-56/LATEST/
这里我下载的是:Percona-XtraDB-Cluster-5.6.21-rel70.1-25.8.938.Linux.x86_64.tar.gz
接下来三台机器上都需要针对基础软件包进行安装,使用yum安装即可,解决依赖性。
perl-IO-Socket-SSL.noarch perl-DBD-MySQL.x86_64 perl-Time-HiRes openssl openssl-devel socat
cd /usr/local/tar -zxvf Percona-XtraDB-Cluster-5.6.21-rel70.1-25.8.938.Linux.x86_64.tar.gzln -s Percona-XtraDB-Cluster-5.6.21-rel70.1-25.8.938.Linux.x86_64 mysqlchown mysql:mysql -R mysqlmkdir -p /data/mysqlchown mysql:mysql -R /data/mysql
配置pxc的参数文件,这里就比普通的MySQL参数文件多如下几点:
提及一点注意事项:这里binlog的格式必须row
#pxcdefault_storage_engine=Innodbinnodb_autoinc_lock_mode=2wsrep_cluster_name=pxc_zs ---------------集群的名字wsrep_cluster_address=gcomm://192.168.56.100,192.168.56.101,192.168.56.102(集群中节点的IP)wsrep_node_address=192.168.56.100------当前机器的ip地址wsrep_provider=/usr/local/mysql/lib/libgalera_smm.sowsrep_sst_method=xtrabackup-v2 (sst传输方法)wsrep_sst_auth=sst:zs (账号权限)
初始化数据:
/usr/local/mysql/scripts/mysql_install_db --basedir=/usr/local/mysql --datadir=/data/mysql/ --defaults-file=/etc/my.cnf --user=mysql
cd /usr/local/mysql/support-filescp mysql.server /etc/init.d/mysql
[root@node1 support-files]# /etc/init.d/mysql bootstrap-pxcBootstrapping PXC (Percona XtraDB Cluster)MySQL (Percona Xt[ OK ]ster) running (4740)
mysql> delete from mysql.user where user!='root' or host!='localhost';mysql> grant all privileges on *.* to 'zs'@'%' identified by 'zs';mysql> grant all privileges on *.* to 'sst'@'localhost' identified by 'zs';mysql> flush privileges;
cd /usr/local/tar -zxvf Percona-XtraDB-Cluster-5.6.21-rel70.1-25.8.938.Linux.x86_64.tar.gzln -s Percona-XtraDB-Cluster-5.6.21-rel70.1-25.8.938.Linux.x86_64 mysqlchown mysql:mysql -R mysqlmkdir -p /data/mysqlchown mysql:mysql -R /data/mysql
#pxcdefault_storage_engine=Innodbinnodb_autoinc_lock_mode=2wsrep_cluster_name=pxc_zs ---------------集群的名字wsrep_cluster_address=gcomm://192.168.56.100,192.168.56.101,192.168.56.102(集群中节点的IP)wsrep_node_address=192.168.56.101------当前机器的ip地址wsrep_provider=/usr/local/mysql/lib/libgalera_smm.sowsrep_sst_method=xtrabackup-v2 (sst传输方法)wsrep_sst_auth=sst:zs (账号权限)
/usr/local/mysql/scripts/mysql_install_db --basedir=/usr/local/mysql --datadir=/data/mysql/ --defaults-file=/etc/my.cnf --user=mysql
cd /usr/local/mysql/support-filescp mysql.server /etc/init.d/mysql
[root@node2 mysql]# /etc/init.d/mysql startStarting MySQL (Percona XtraDB Cluster).. [ OK ]
cd /usr/local/tar -zxvf Percona-XtraDB-Cluster-5.6.21-rel70.1-25.8.938.Linux.x86_64.tar.gzln -s Percona-XtraDB-Cluster-5.6.21-rel70.1-25.8.938.Linux.x86_64 mysqlchown mysql:mysql -R mysqlmkdir -p /data/mysqlchown mysql:mysql -R /data/mysql
#pxcdefault_storage_engine=Innodbinnodb_autoinc_lock_mode=2wsrep_cluster_name=pxc_zs ---------------集群的名字wsrep_cluster_address=gcomm://192.168.56.100,192.168.56.101,192.168.56.102(集群中节点的IP)wsrep_node_address=192.168.56.102------当前机器的ip地址wsrep_provider=/usr/local/mysql/lib/libgalera_smm.sowsrep_sst_method=xtrabackup-v2 (sst传输方法)wsrep_sst_auth=sst:zs (账号权限)
/usr/local/mysql/scripts/mysql_install_db --basedir=/usr/local/mysql --datadir=/data/mysql/ --defaults-file=/etc/my.cnf --user=mysql
启动第三个节点的服务:
cd /usr/local/mysql/support-filescp mysql.server /etc/init.d/mysql
[root@node3 mysql]# /etc/init.d/mysql startStarting MySQL (Percona XtraDB Cluster).. [ OK ]
但启动方式不是以/etc/init.d/mysql bootstrap-pxc,换成/etc/init.d/mysql start 这种方式
三个节点都已经启动成功,这样在任意一个节点上面,执行一条DML语句的操作,都会同步到另外两个节点。
至此张老师的企业级MySQL主流高可用集群架构三部曲就完结了!有欠妥的地方,请大家多多指教。
今后还会出更多好文章奉献给大家,技术只有在无限的分享中,得到进一步地升华!
让我们一起加油!
本文出自 “张�d的博客” 博客,转载请与作者联系!