PXC中文文档--第四章

4.1 创建集群

 引导指的是让最初的集群启动运行,通过引导你将要定义一个含有正确信息的节点,所有的其他节点都要复制他的信息,通过sst的方式,在宕机时间中,引导过程是通过一样的方法,通过挑选最初的节点,从本质上来讲是决定你想让其他的节点复制指向哪一个包含数据库的集群节点。
 再启动PXC时,mysql的配置文件应该包含一下重要的参数。
[mysqld]

Path to Galera library

wsrep_provider=/usr/lib64/libgalera_smm.so

Cluster connection URL

wsrep_cluster_address=gcomm://

In order for Galera to work correctly binlog format should be ROW

binlog_format=ROW

MyISAM storage engine has only experimental support

default_storage_engine=InnoDB

This changes how |InnoDB| autoincrement locks are managed and is a requirement for Galera

innodb_autoinc_lock_mode=2

Bootstrapping the cluster is a bit of a manual process. On the initial node, variable wsrep_cluster_address
should be set to the value: gcomm://. The gcomm:// tells the node it can bootstrap without any cluster to connect to. Setting that and starting up the first node should result in a cluster with a wsrep_cluster_conf_id of 1. After this single-node cluster is started, variable wsrep_cluster_address should be updated to the list of all nodes in the cluster. For example:

引导过程需要手动完成,在最初的节点上,wsrep_cluster_address应该被设置为 gcomm://,这的参数的意思是这个节点可以在启动时不链接任何节点,设置这个参数,并且启动之后,将会看到wsrep_cluster_conf_id这个参数的值为1,在一个单节点启动之后,wsrep_cluster_address这个值应该被更新为当前集群的所有节点列表,比如:
wsrep_cluster_address=gcomm://192.168.70.2,192.168.70.3,192.168.70.4

Although note that cluster membership is not defined by this setting, it is defined by the nodes that join the cluster
with the proper cluster name configured Variable wsrep_cluster_name is used for that, if not explicitly set it will
default to my_wsrep_cluster. Hence, variable wsrep_cluster_address does not need to be identical on
all nodes, it’s just a best practice because on restart the node will try all other nodes in that list and look for any that
are currently up and running the cluster.

尽管集群之间的成员关系不是被这个值所定义的,

Once the first node is configured, then each other node should be started, one at a time. In a bootstrap situation, SST is most likely, so generally multiple nodes joining at once should be avoided.
一旦第一个节点配置并且启动,其他的节点应该启动,并且在同一时间只能启动一个,依次启动,在这个过程中,大多数情况会使用sst的方式恢复数据,所以,应该避免多个节点同时启动(可能考虑最初节点的磁盘压力)
In case cluster that’s being bootstrapped has already been set up before, and to avoid editing the my.cnf twice to change the wsrep_cluster_address to gcomm:// and then to change it back to other node addresses, first
node can be started with:

/etc/init.d/mysql bootstrap-pxc

systemctl start [email protected](两种不同的启动方式吗?)
为了避免在启动一个节点时,这个节点已经被启动,并且避免第二次编辑my.cnf文件更改 wsrep_cluster_address to gcomm:// ,然后在改回其他节点的列表,所以第一个节点应该以以下命令启动,
/etc/init.d/mysql bootstrap-pxc
systemctl start [email protected]

This way values in my.cnf would remain unchanged. Next time node is restarted it won’t require updating the
configuration file. This can be useful in case cluster has been previously set up and for some reason all nodes went down and the cluster needs to be bootstrapped again.
这种方式启动可以让my.cnf配置文件里的参数值不发生改变,下次节点重启的时候,他就不需要更新配置文件了,他在这种情况下会很有用,就是集群在某种原因下所有的节点全部挂掉,集群需要重新引导启动。

4.2 SST

SST—State Snapshot Transfer(快照复制)

State Snapshot Transfer is a full data copy from one node (donor) to the joining node (joiner). It’s used when a new node joins the cluster. In order to be synchronized with the cluster, new node has to transfer data from the node that is already part of the cluster. There are three methods of SST available in Percona XtraDB Cluster: mysqldump, rsync and xtrabackup. The downside of mysqldump and rsync is that the donor node becomes READ-ONLY while data is being copied from one node to another. Xtrabackup SST, on the other hand, uses backup locks, which means galera provider is not paused at all as with FTWRL (Flush Tables with Read Lock) earlier. State snapshot transfer method
can be configured with the wsrep_sst_method variable.
SST是指从donor到joiner的数据全量拷贝,它通常使用在一个新的节点加入时,为了与集群同步,新的节点不得不去一个已经在集群中的节点上拷贝数据,在PXC中,有三种SST的方法,mysqldump,rsync,Xtrabackup。mysqldump跟rsync的缺点是,donor节点在这个过程中会变成只读节点,(整个集群呢,集群是需要所有节点返回成功才算成功的吧,如果这个节点时只读的,其他的节点可写吗?),xtrabackup只在备份的过程中不会影响写入,不过在最后阶段,也就是在备份表结构的时候,还是会引入读锁。,SST的方法可以通过wsrep_sst_method这个参数来设置。

4.2.1 选择donor

If there are no nodes available that can safely perform an incremental state transfer, the cluster defaults to a state
snapshot transfer. If there are nodes available that can safely perform an incremental state transfer, the cluster prefers
a local node over remote nodes to serve as the donor. If there are no local nodes available that can safely perform
an incremental state transfer, the cluster chooses a remote node to serve as the donor. Where there are several local
or remote nodes available that can safely perform an incremental state transfer, the cluster chooses the node with the
highest seqno to serve as the donor.

如果不可以使用增量备份的方法去恢复,就只能通过SST的方式,也就是全量copy,如果有可以执行安全的执行增量的node,PXC更愿意选择一个本地的node,而不是一个远程的node作为donor,如果没有本地可以执行增量的,选择一个远程的,如果有多个远程的,就会选择一个seqno值更高的。

4.2.2 使用xtrabackup

This is the default SST method (version 2 of it: xtrabackup-v2). This is the least blocking method as it uses backup
locks. XtraBackup is run locally on the donor node, so it’s important that the correct user credentials are set up on
the donor node. In order for PXC to perform the SST using the XtraBackup, credentials for connecting to the donor
node need to be set up in the variable wsrep_sst_auth. Beside the credentials, one more important thing is that
the datadir needs to be specified in the server configuration file my.cnf, otherwise the transfer process will fail.
More information about the required credentials can be found in the XtraBackup manual. Easy way to test if the
credentials will work is to run the innobackupex on the donor node with the username and password specified in the
variable wsrep_sst_auth. For example, if the value of the wsrep_sst_auth is root:Passw0rd innoback-
upex command should look like:
innobackupex –user=root –password=Passw0rd /tmp/

使用xtrabackup是默认的SST的方法,这种方法可以将锁时间降到最低,他在donor机器上运行,所以在donor上应该有一个被授权的用户,来执行xtrabackup,为了使PXC使用XTrabackup去执行SST,wsrep_sst_auth这个参数应该正确配置。除了授权用户,更重要的是在my.cnf中要配置datadir,不然备份程序将会失败。关于xtrabackup需要哪些权限,请参照它的手册,很简单的检测用户权限是否正确的方法是,在donor上用定义的用户执行innobackupex,配置方法:
wsrep_sst_auth = innobackupex –user=root –password=Passw0rd /tmp/

4.2.3 使用mysqldump

This method uses the standard mysqldump to dump all the databases from the donor node and import them to the
joining node. For this method to work wsrep_sst_auth needs to be set up with the root credentials. This method
is the slowest one and it also performs the global lock while doing the SST which will block writes to the donor node.
Script used for this method can be found in /usr/bin/wsrep_sst_mysqldump and it’s provided with the Per-
cona XtraDB Cluster binary packages.

这个方法使用标准的mysqldump在donor上dump所有库的所有数据,然后再倒入到新加入的节点中,使用这种方法,需要使用root权限的用户,这种方法是最慢的,并且会在备份期间对donor节点加读锁。在PXC的二进制包中包含这个命令。

4.2.4 使用rsync

This method uses rsync to copy files from donor to the joining node. In some cases this can be faster than using the
XtraBackup but requires the global data lock which will block writes to the donor node. This method doesn’t require
username/password credentials to be set up in the variable wsrep_sst_auth.
Script used for this method can be found in /usr/bin/wsrep_sst_rsync and it’s provided with the Percona
XtraDB Cluster binary packages.

这种方法是使用rsync从donor上copy数据到新加入的节点,有些时候,这种方法会比使用xtrabackup更快,但是需要早donor上读锁,这种方法不需要使用 wsrep_sst_auth进行用户授权,

在/usr/bin/目录下有相关脚本,并且它也包含在PXC的二进制包中。

4.2.5 扩展阅读

• SST Methods for MySQL
• Xtrabackup SST configuration

4.3xtrabackup配置选项

XtraBackup SST works in two stages:
• Stage I on joiner checks if it is SST or IST based on presence of xtrabackup_ist file.
• In Stage II it starts the data transfer, if it’s SST, it empties the data directory sans few files (galera.cache,
sst_in_progress, grastate.dat) and then proceed with the SST or if it’s IST, proceeds as before.

Note: To maintain compatibility with Percona XtraDB Cluster older than 5.5.33-23.7.6, use xtrabackup as SST
method, else xtrabackup-v2 is recommended. xtrabackup-v2 is also the default SST method now.
Latest Percona XtraBackup 2.1.x is strongly recommended for Xtrabackup SST. Refer to Incompatibilities for possible
caveats.

你可能感兴趣的:(PXC中文文档--第四章)