Percona XtraDB 集群安装与配置
-
Upload
yucheng-hu -
Category
Technology
-
view
921 -
download
8
description
Transcript of Percona XtraDB 集群安装与配置
![Page 1: Percona XtraDB 集群安装与配置](https://reader034.fdocuments.us/reader034/viewer/2022052206/554f4412b4c905423f8b4770/html5/thumbnails/1.jpg)
Percona XtraDB Cluster Installation and setup
(basics)
Peter BorosConsultant
![Page 2: Percona XtraDB 集群安装与配置](https://reader034.fdocuments.us/reader034/viewer/2022052206/554f4412b4c905423f8b4770/html5/thumbnails/2.jpg)
www.percona.com
Agenda
● Installing the first node of the cluster● Connecting subsequent nodes to the cluster● Installing HaProxy on the application server● Testing with a real-world application: sysbench● Breaking and fixing the cluster
![Page 3: Percona XtraDB 集群安装与配置](https://reader034.fdocuments.us/reader034/viewer/2022052206/554f4412b4c905423f8b4770/html5/thumbnails/3.jpg)
www.percona.com
Agenda
● Installing the first node of the cluster● Connecting subsequent nodes to the cluster● Installing HaProxy on the application server● Testing with a real-world application: sysbench● Breaking and fixing the cluster
![Page 4: Percona XtraDB 集群安装与配置](https://reader034.fdocuments.us/reader034/viewer/2022052206/554f4412b4c905423f8b4770/html5/thumbnails/4.jpg)
www.percona.com
Overview
● The goal of this talk to show Percona XtraDB Cluster basics with a hands-on approach.
● We will use freshly installed CentOS 6 machines. Those are vanilla installations.
● We will cover load balancing using HaProxy.
![Page 5: Percona XtraDB 集群安装与配置](https://reader034.fdocuments.us/reader034/viewer/2022052206/554f4412b4c905423f8b4770/html5/thumbnails/5.jpg)
www.percona.com
Percona XtraDB cluster at a glance
● All nodes are equal● All nodes have all the data● Replication is (virtually) synchronous
● Completely different from asynchronous mysql replication
● At least 3 nodes (or 2 + arbitrator)
![Page 6: Percona XtraDB 集群安装与配置](https://reader034.fdocuments.us/reader034/viewer/2022052206/554f4412b4c905423f8b4770/html5/thumbnails/6.jpg)
www.percona.com
Packages on all database nodes
● Add Percona's yum repository# rpm -Uhv http://www.percona.com/downloads/percona-release/percona-release-0.0-1.x86_64.rpm
● Install PXC packages# yum -y install Percona-XtraDB-Cluster-server \Percona-XtraDB-Cluster-client \Percona-Server-shared-compat \percona-xtrabackup
![Page 7: Percona XtraDB 集群安装与配置](https://reader034.fdocuments.us/reader034/viewer/2022052206/554f4412b4c905423f8b4770/html5/thumbnails/7.jpg)
www.percona.com
Packages installed
Installing: Percona-Server-shared-compat replacing mysql-libs.x86_64 5.1.61-4.el6 Percona-XtraDB-Cluster-client Percona-XtraDB-Cluster-server percona-xtrabackupInstalling for dependencies: Percona-XtraDB-Cluster-galera libaio nc perl perl-Module-Pluggable perl-Pod-Escapes perl-Pod-Simple perl-libs perl-version rsync
![Page 8: Percona XtraDB 集群安装与配置](https://reader034.fdocuments.us/reader034/viewer/2022052206/554f4412b4c905423f8b4770/html5/thumbnails/8.jpg)
www.percona.com
Configuring the nodes
● wsrep_cluster_address=gcomm://● Initializes a new cluster, new nodes can connect to this one
● wsrep_cluster_address=gcomm://<IP addr>:4567● Starts a new node, which will try to connect to the node
specificed
● wsrep_urls● Option for [mysqld_safe] section, not for [mysqld], will set
wsrep_cluster_address to a usable item on this list.● Example:
wsrep_urls=gcomm://node1:4567,gcomm://node2:4567,gcomm://node3:4567
![Page 9: Percona XtraDB 集群安装与配置](https://reader034.fdocuments.us/reader034/viewer/2022052206/554f4412b4c905423f8b4770/html5/thumbnails/9.jpg)
www.percona.com
Configuring the first node
[mysqld]server_id=1binlog_format=ROWlog_bin=mysql-binwsrep_cluster_address=gcomm://wsrep_provider=/usr/lib64/libgalera_smm.sodatadir=/var/lib/mysql
wsrep_slave_threads=4wsrep_cluster_name=pxctestwsrep_sst_method=xtrabackupwsrep_node_name=pxc1
log_slave_updates
innodb_locks_unsafe_for_binlog=1innodb_autoinc_lock_mode=2
We are starting a new cluster with node'pxc1' as primary
![Page 10: Percona XtraDB 集群安装与配置](https://reader034.fdocuments.us/reader034/viewer/2022052206/554f4412b4c905423f8b4770/html5/thumbnails/10.jpg)
www.percona.com
Configuring subsequent nodes
[mysqld]server_id=1binlog_format=ROWlog_bin=mysql-binwsrep_cluster_address=gcomm://192.168.56.41wsrep_provider=/usr/lib64/libgalera_smm.sodatadir=/var/lib/mysql
wsrep_slave_threads=4wsrep_cluster_name=pxctestwsrep_sst_method=xtrabackupwsrep_node_name=pxc2
log_slave_updates
innodb_locks_unsafe_for_binlog=1innodb_autoinc_lock_mode=2
The other nodes are joining to 'pxc1'
![Page 11: Percona XtraDB 集群安装与配置](https://reader034.fdocuments.us/reader034/viewer/2022052206/554f4412b4c905423f8b4770/html5/thumbnails/11.jpg)
www.percona.com
Additional configuration for demo
● iptables disabled● service iptables stop● chkconfig –del iptables
● SELinux disabled in /etc/selinux/config
![Page 12: Percona XtraDB 集群安装与配置](https://reader034.fdocuments.us/reader034/viewer/2022052206/554f4412b4c905423f8b4770/html5/thumbnails/12.jpg)
Demo: building the clusterand destroying it
and building it again
![Page 13: Percona XtraDB 集群安装与配置](https://reader034.fdocuments.us/reader034/viewer/2022052206/554f4412b4c905423f8b4770/html5/thumbnails/13.jpg)
What we saw...
![Page 14: Percona XtraDB 集群安装与配置](https://reader034.fdocuments.us/reader034/viewer/2022052206/554f4412b4c905423f8b4770/html5/thumbnails/14.jpg)
www.percona.com
State transfer
● SST (Snapshot State Transfer)● Copies the whole data set● Different methods: xtrabackup, rsync, etc...
● IST (Incremental State Transfer)● Transactions incrementally replayed from gcache● You can use a manual backup created with
xtrabackup using --galera-info option of innobackupex
http://www.mysqlperformanceblog.com/2012/08/02/avoiding-sst-when-adding-new-percona-xtradb-cluster-node/
![Page 15: Percona XtraDB 集群安装与配置](https://reader034.fdocuments.us/reader034/viewer/2022052206/554f4412b4c905423f8b4770/html5/thumbnails/15.jpg)
www.percona.com
Split Brain
● When only 1 node was up, the data was not usable
● Using 3 nodes guarantees that you can lose 1 node
● A node has to be able to access the majority of cluster node to serve the data
![Page 16: Percona XtraDB 集群安装与配置](https://reader034.fdocuments.us/reader034/viewer/2022052206/554f4412b4c905423f8b4770/html5/thumbnails/16.jpg)
www.percona.com
What pxc1 saw
This does not necessarily mean pxc2 and pxc3 are dead...
![Page 17: Percona XtraDB 集群安装与配置](https://reader034.fdocuments.us/reader034/viewer/2022052206/554f4412b4c905423f8b4770/html5/thumbnails/17.jpg)
www.percona.com
Possibilities
![Page 18: Percona XtraDB 集群安装与配置](https://reader034.fdocuments.us/reader034/viewer/2022052206/554f4412b4c905423f8b4770/html5/thumbnails/18.jpg)
www.percona.com
Continuing operation in split brain mode
● The users (application servers) who can access pxc1 will write pxc1
● The users (application server) who can access pxc2 and pxc3 will write to that cluster
● This can be prevented by shutting down the node if it's not part of the group in majority
● garbd: galera arbitrator daemon, used in voting, but doesn't store data
![Page 19: Percona XtraDB 集群安装与配置](https://reader034.fdocuments.us/reader034/viewer/2022052206/554f4412b4c905423f8b4770/html5/thumbnails/19.jpg)
www.percona.com
Load balancing
● Some application can use driver level load balancing by connecting to all nodes (JDBC)
● For the rest, external solution necessary● LVS● HaProxy
– We will cover this● Any kind of load balancing software is usable, if it
can balance TCP connections at least
![Page 20: Percona XtraDB 集群安装与配置](https://reader034.fdocuments.us/reader034/viewer/2022052206/554f4412b4c905423f8b4770/html5/thumbnails/20.jpg)
www.percona.com
HaProxy configuration
backend pxc-backmode tcpbalance leastconnoption httpchkserver pxc1 192.168.56.41:3306 check port 9200 inter 12000 rise 3 fall 3server pxc2 192.168.56.42:3306 check port 9200 inter 12000 rise 3 fall 3server pxc3 192.168.56.43:3306 check port 9200 inter 12000 rise 3 fall 3
backend pxc-onenode-backmode tcpbalance leastconnoption httpchkserver pxc1 192.168.56.41:3306 check port 9200 inter 12000 rise 3 fall 3server pxc2 192.168.56.42:3306 check port 9200 inter 12000 rise 3 fall 3 backupserver pxc3 192.168.56.43:3306 check port 9200 inter 12000 rise 3 fall 3 backup
![Page 21: Percona XtraDB 集群安装与配置](https://reader034.fdocuments.us/reader034/viewer/2022052206/554f4412b4c905423f8b4770/html5/thumbnails/21.jpg)
www.percona.com
Application server node prepared for demo
● CentOS 6 base installation● EPEL repo added● HaProxy installed from EPEL repo● Sysbench 0.5 package made by Frederic
Descamps
![Page 22: Percona XtraDB 集群安装与配置](https://reader034.fdocuments.us/reader034/viewer/2022052206/554f4412b4c905423f8b4770/html5/thumbnails/22.jpg)
Load balancing demo
![Page 23: Percona XtraDB 集群安装与配置](https://reader034.fdocuments.us/reader034/viewer/2022052206/554f4412b4c905423f8b4770/html5/thumbnails/23.jpg)
Q&A
![Page 24: Percona XtraDB 集群安装与配置](https://reader034.fdocuments.us/reader034/viewer/2022052206/554f4412b4c905423f8b4770/html5/thumbnails/24.jpg)