MySQL Cluster high availability --PXC

Bowen outline:

  • A, PXC Introduction
  • Second, the PXC cluster deployment

A, PXC Introduction

Reference: Percona official

PXC is an open source MySQL high availability solution that Percona Server and database integration Xtrabackup and Galera, in order to achieve simultaneous multi-master replication. There are MariaDB Galera Cluster (MGC) and Percona XtraDB Cluster (PXC) based high availability solutions Galera, the current PXC architecture used in the production environment more and more mature, PXC compared to those based on the traditional cluster master-slave mode MHA architecture and dual master, PXC most prominent feature is to solve the long-criticized replication latency issues, basically can achieve real-time synchronization. And between the node and the nodes, their relationship to each other peer. Galera Cluster itself is a multi-master architecture. PXC is in storage engine to achieve synchronous replication layer, rather than asynchronous replication so that data consistency is very high.

It works as follows:
23b358dd6fb14119bb262755f8f70541

To build MySQL PXC architecture requires at least three instances to form a cluster is not a primary mode from among three instances, but their main, so the relationship between the three is equal, regardless of master and slave, which also called multi-master architecture, the client read and write, examples of which are the same connection, the read data is the same, a write arbitrary example, the cluster will own newly written data synchronization to other instances this architecture does not share any data, MySQL is a highly redundant cluster architecture.

1, PXC advantages and disadvantages

advantage:

  • To achieve a strong consistency MySQL Cluster high availability and data.
  • The completion of a truly multi-node cluster literacy program.
  • Improve the problem of master-slave replication latency, basically meeting the real-time synchronization.
  • New node can automatically synchronize data, without prior manual backup, and easy maintenance.
  • Since the writing is a multi-node database failover so easily.

Disadvantages:

  • When adding a new node overhead big, because when you add a new node, you must copy the complete data set from one of the existing nodes, if the existing data in the database is 100GB, then copy 100GB.
  • Any update transactions are required by the global verification will be performed on other nodes, cluster performance is limited by the worst node, also known as short-board effect (cask's law).
  • Because of the need to ensure data consistency, PXC used to achieve real-time synchronous replication-based storage engine layer, in a multi-node concurrent write lock conflict more serious problem.
  • There is a problem writing to expand, will take place on all nodes write, write for a larger load scenes, not recommended PXC.
  • Innodb only supports storage engine.

2, PXC works

ae1ed3e5cff1e8f74959385ee03ecfba

PXC operation process is generally such that write to the requesting client node first connection until the transaction, the node requires a Replication generated writeset broadcasted, then obtain the global transaction ID, collectively transmitted to other nodes up. After certification by other nodes merge data, we found no conflicting data, executes apply_cb and commit_cb operation, otherwise discard the transaction.
And the current node (write requested by the client node) after verification by performing commit_cb operations, and OK is returned to the client. If the validation does not pass, then rollback_cb.
PXC cluster in the production line, there must be at least three nodes. If a node is not verified, there has been conflicting data, the way this time to take the kick inconsistent data node cluster is to appear, and it will automatically shutdown command to shut down automatically.

3, PXC an important concept

First, to regulate the number of nodes in the cluster, the entire control nodes in the cluster minimum of three, within a range of up to eight. At least 3 to prevent split-brain phenomenon, because only appears split-brain in the case of two nodes. Split brain's performance is the output of any command to return the results are unkown command.
When a new node to join the cluster PXC when necessary to elect each node in the cluster from a doner node as a contributor to the total amount of data. There are two ways PXC data transmission node, called SST total amount of transmission, the other called IST incremental transfer. SST transmission has XtraBackup, mysqldump, rsync three ways, and the incremental transfer only XtraBackup. Generally not a big amount of data that can be used when SST transmission as the full amount, but only XtraBackup way.

Node in the cluster, or the failure due to addition of a new node, synchronization failure is a state transition occurs or the like, the meanings of these include the following states:

  • open: node starts successfully, try to connect to the cluster
  • primary: nodes in the cluster, when a new node joins the cluster, data is selected for production donor state synchronization.
  • joiner: node is a state of waiting to receive the synchronization data file.
  • joined: node has completed data synchronization, and try to maintain a consistent schedule to other nodes in the cluster.
  • synced: normal node state to provide services, it said that it has completed synchronization and clustering and consistent progress.
  • doner: when the node is in a state to provide the total amount of data for a new node is added.

Second, the PXC cluster deployment

1, environment preparation

THE CPU name IP
Cent OS 7.5 PXC-01 192.168.20.2
Cent OS 7.5 PXC-02 192.168.20.3
Cent OS 7.5 PXC-03 192.168.20.4

Note: All hosts are in advance do not need to install MySQL services, including the MySQL service in the PXC source package.

Note: All operations, summary of three nodes 2-8 are required to perform. If there is anything that does not need to perform in three nodes, I will be particularly described.

2, install dependencies

[root@pxc-01 ~]# yum install -y libev lsof perl-Compress-Raw-Bzip2 perl-Compress-Raw-Zlib perl-DBD-MySQL perl-DBI perl-Digest perl-Digest-MD5 perl-IO-Compress perl-Net-Daemon perl-PlRPC socat openssl openssl-devel

3, uninstall Mariadb

[root@pxc-01 ~]# yum -y erase mariadb && rpm -qa | grep mariadb | xargs rpm -e --nodeps

4, download the required software packages (xtraBackup, Percona-XtraDB-Cluster and qpress)

[root@pxc-01 bin]# wget https://www.percona.com/downloads/Percona-XtraBackup-2.4/Percona-XtraBackup-2.4.18/binary/redhat/7/x86_64/percona-xtrabackup-24-2.4.18-1.el7.x86_64.rpm
[root@pxc-01 bin]# wget http://www.quicklz.com/qpress-11-linux-x64.tar
#上面这个包使用wget可能会报错406,用浏览器打开链接下载再上传到服务器即可。
[root@pxc-01 bin]# wget https://www.percona.com/downloads/Percona-XtraDB-Cluster-LATEST/Percona-XtraDB-Cluster-5.7.28-31.41/binary/tarball/Percona-XtraDB-Cluster-5.7.28-rel31-31.41.1.Linux.x86_64.ssl101.tar.gz
#这个包下载的话,时间会稍微长一些,耐心等待。

5, the installation and configuration commands qpress xtrabackup

[root@pxc-01 bin]# tar xf qpress-11-linux-x64.tar -C /usr/bin
[root@pxc-01 bin]# rpm -ivh percona-xtrabackup-24-2.4.18-1.el7.x86_64.rpm

6, deployment PXC service

#创建MySQL系统用户
[root@pxc-01 bin]# useradd -M -r -s /bin/false mysql 
#解包
[root@pxc-01 bin]# tar zxf Percona-XtraDB-Cluster-5.7.28-rel31-31.41.1.Linux.x86_64.ssl101.tar.gz
#移动到指定目录
[root@pxc-01 bin]# mv Percona-XtraDB-Cluster-5.7.28-rel31-31.41.1.Linux.x86_64.ssl101 /usr/local/mysql
#创建data目录并更改目录属主属组为MySQL
[root@pxc-01 bin]# mkdir -p /usr/local/mysql/data
[root@pxc-01 bin]# chown -R mysql.mysql /usr/local/mysql/
#为MySQL命令配置全局变量
[root@pxc-01 bin]# echo "export PATH=/usr/local/mysql/bin:$PATH" >> /etc/profile
[root@pxc-01 bin]# source /etc/profile

7, the definition of the MySQL server configuration file

1) pxc-01 complete configuration file as follows:

[root@pxc-01 bin]# cat /etc/my.cnf
# Example: Percona XtraDB Cluster 5.7
[client]
port = 3306
socket = /tmp/mysql.sock
[mysql]
prompt="\u@\h \R:\m:\s[\d]> "
no-auto-rehash
[mysqld]
user = mysql
port = 3306
basedir = /usr/local/mysql
datadir = /usr/local/mysql/data
socket = /tmp/mysql.sock
pid-file = db.pid
character-set-server = utf8mb4
skip_name_resolve = 1
open_files_limit = 65535
back_log = 1024
max_connections = 512
max_connect_errors = 1000000
table_open_cache = 1024
table_definition_cache = 1024
table_open_cache_instances = 64
thread_stack = 512K
external-locking = FALSE
max_allowed_packet = 32M
sort_buffer_size = 4M
join_buffer_size = 4M
thread_cache_size = 768
#query_cache_size = 0
#query_cache_type = 0
interactive_timeout = 600
wait_timeout = 600
tmp_table_size = 32M
max_heap_table_size = 32M
slow_query_log = 1
slow_query_log_file = /usr/local/mysql/data/slow.log
log-error = /usr/local/mysql/data/error.log
long_query_time = 0.1
server-id = 1813306
log-bin = /usr/local/mysql/data/mysql-bin
sync_binlog = 1
binlog_cache_size = 4M
max_binlog_cache_size = 1G
max_binlog_size = 1G
expire_logs_days = 7
master_info_repository = TABLE
relay_log_info_repository = TABLE
gtid_mode = on
enforce_gtid_consistency = 1
log_slave_updates
binlog_format = row    #为了让Galera正确工作,binlog格式应该是ROW
relay_log_recovery = 1
relay-log-purge = 1
key_buffer_size = 32M
read_buffer_size = 8M
read_rnd_buffer_size = 4M
bulk_insert_buffer_size = 64M
lock_wait_timeout = 3600
explicit_defaults_for_timestamp = 1
innodb_thread_concurrency = 0
innodb_sync_spin_loops = 100
innodb_spin_wait_delay = 30
transaction_isolation = REPEATABLE-READ
innodb_buffer_pool_size = 1024M
innodb_buffer_pool_instances = 8
innodb_buffer_pool_load_at_startup = 1
innodb_buffer_pool_dump_at_shutdown = 1
innodb_data_file_path = ibdata1:1G:autoextend
innodb_flush_log_at_trx_commit = 1
innodb_log_buffer_size = 32M
innodb_log_file_size = 2G
innodb_log_files_in_group = 2
#innodb_max_undo_log_size = 4G
innodb_io_capacity = 2000
innodb_io_capacity_max = 4000
innodb_flush_neighbors = 0
innodb_write_io_threads = 4
innodb_read_io_threads = 4
innodb_purge_threads = 4
innodb_page_cleaners = 4
innodb_open_files = 65535
innodb_max_dirty_pages_pct = 50
innodb_flush_method = O_DIRECT
innodb_lru_scan_depth = 4000
innodb_checksum_algorithm = crc32
#innodb_file_format = Barracuda
#innodb_file_format_max = Barracuda
innodb_lock_wait_timeout = 10
innodb_rollback_on_timeout = 1
innodb_print_all_deadlocks = 1
innodb_file_per_table = 1
innodb_online_alter_log_max_size = 4G
internal_tmp_disk_storage_engine = InnoDB
innodb_stats_on_metadata = 0
# PXC  以上都是关于数据库优化的一些信息,大多数为可选配置,与pxc有关的都是下面的参数
wsrep_provider=/usr/local/mysql/lib/libgalera_smm.so
wsrep_provider_options="gcache.size=2G"
wsrep_cluster_name=my_pxc_cluster
wsrep_cluster_address=gcomm://192.168.20.2,192.168.20.3,192.168.20.4
wsrep_node_name=pxc01
wsrep_node_address=192.168.20.2
wsrep_sst_method=xtrabackup-v2
wsrep_sst_auth=sst:pwd@123
pxc_strict_mode=ENFORCING  
default_storage_engine=InnoDB    # myisam存储引擎只能在测试环境中使用
innodb_autoinc_lock_mode=2    # 此 InnoDB 自动增量锁定模式是 Galera 强制的
[mysqldump]
quick
max_allowed_packet = 32M

Some parameters associated PXC explained as follows:

  • wsrep_provider: specifies the path to the desired plug-in (by default have this plugin).
  • wsrep_provider_options = "gcache.size = 1G": Gcache ring buffer size, the pre-allocated at startup, the default is 10M. This configuration there are other options: gcache.size represents the size of the cache is used to write a set of incremental information. The default size is 128MB, the parameters set by the wsrep_provider_options variable. We proposed to adjust the range of 2G-4G, enough buffer space to facilitate additional incremental information.
    gcache.mem_size representatives Gcache in memory cache size, moderate turn up can improve the performance of the entire cluster.
    gcache.page_size can be understood as if the memory is not enough (Gcache insufficient), will be written directly to disk file written set.
  • wsrep_cluster_name: This parameter defines the logical name of the cluster nodes, all nodes participating in the cluster must specify the same name.
  • wsrep_cluster_address: Use this parameter to determine the IP address of another node in the cluster is currently the only supported back-end production model is gcomm.
  • wsrep_node_name: This parameter is used to set its own logical node name.
  • wsrep_node_address: used to specify the IP address of the current node.
  • wsrep_sst_method: A method for the specified data synchronization recommended xtrabackup-v2
  • wsrep_sst_auth: define user and password to use when sst copy data (database node must have a specified user and password)
  • pxc_strict_mode: strict mode, the official suggested the parameter value ENFORCING. With this configuration, any table created in the database must have a primary key, otherwise it is impossible to write data.

More detailed explanation please move PXC parameters: MySQL wsrep option , there will be surprised to find that, at the same time, to modify the above configuration items, it is recommended to see a detailed explanation of the options.

2) pxc-02 complete node configuration file as follows:

Compared with pxc-01 nodes, only three can not be the same, the following are marked out

[root@pxc-02 src]# cat /etc/my.cnf 
# Example: Percona XtraDB Cluster 5.7
[client]
port = 3306
socket = /tmp/mysql.sock
[mysql]
prompt="\u@\h \R:\m:\s[\d]> "
no-auto-rehash
[mysqld]
user = mysql
port = 3306
basedir = /usr/local/mysql
datadir = /usr/local/mysql/data
socket = /tmp/mysql.sock
pid-file = db.pid
character-set-server = utf8mb4
skip_name_resolve = 1
open_files_limit = 65535
back_log = 1024
max_connections = 512
max_connect_errors = 1000000
table_open_cache = 1024
table_definition_cache = 1024
table_open_cache_instances = 64
thread_stack = 512K
external-locking = FALSE
max_allowed_packet = 32M
sort_buffer_size = 4M
join_buffer_size = 4M
thread_cache_size = 768
#query_cache_size = 0
#query_cache_type = 0
interactive_timeout = 600
wait_timeout = 600
tmp_table_size = 32M
max_heap_table_size = 32M
slow_query_log = 1
slow_query_log_file = /usr/local/mysql/data/slow.log
log-error = /usr/local/mysql/data/error.log
long_query_time = 0.1
server-id = 1813307                   # server-id不可以一样
log-bin = /usr/local/mysql/data/mysql-bin
sync_binlog = 1
binlog_cache_size = 4M
max_binlog_cache_size = 1G
max_binlog_size = 1G
expire_logs_days = 7
master_info_repository = TABLE
relay_log_info_repository = TABLE
gtid_mode = on
enforce_gtid_consistency = 1
log_slave_updates
binlog_format = row   
relay_log_recovery = 1
relay-log-purge = 1
key_buffer_size = 32M
read_buffer_size = 8M
read_rnd_buffer_size = 4M
bulk_insert_buffer_size = 64M
lock_wait_timeout = 3600
explicit_defaults_for_timestamp = 1
innodb_thread_concurrency = 0
innodb_sync_spin_loops = 100
innodb_spin_wait_delay = 30
transaction_isolation = REPEATABLE-READ
innodb_buffer_pool_size = 1024M
innodb_buffer_pool_instances = 8
innodb_buffer_pool_load_at_startup = 1
innodb_buffer_pool_dump_at_shutdown = 1
innodb_data_file_path = ibdata1:1G:autoextend
innodb_flush_log_at_trx_commit = 1
innodb_log_buffer_size = 32M
innodb_log_file_size = 2G
innodb_log_files_in_group = 2
#innodb_max_undo_log_size = 4G
innodb_io_capacity = 2000
innodb_io_capacity_max = 4000
innodb_flush_neighbors = 0
innodb_write_io_threads = 4
innodb_read_io_threads = 4
innodb_purge_threads = 4
innodb_page_cleaners = 4
innodb_open_files = 65535
innodb_max_dirty_pages_pct = 50
innodb_flush_method = O_DIRECT
innodb_lru_scan_depth = 4000
innodb_checksum_algorithm = crc32
#innodb_file_format = Barracuda
#innodb_file_format_max = Barracuda
innodb_lock_wait_timeout = 10
innodb_rollback_on_timeout = 1
innodb_print_all_deadlocks = 1
innodb_file_per_table = 1
innodb_online_alter_log_max_size = 4G
internal_tmp_disk_storage_engine = InnoDB
innodb_stats_on_metadata = 0
# PXC  
wsrep_provider=/usr/local/mysql/lib/libgalera_smm.so
wsrep_provider_options="gcache.size=2G"
wsrep_cluster_name=my_pxc_cluster
wsrep_cluster_address=gcomm://192.168.20.2,192.168.20.3,192.168.20.4
wsrep_node_name=pxc02             # 节点的逻辑名称不可以一样
wsrep_node_address=192.168.20.3     #这里的IP地址是本机的,当然也不一样
wsrep_sst_method=xtrabackup-v2
wsrep_sst_auth=sst:pwd@123
pxc_strict_mode=ENFORCING
default_storage_engine=InnoDB 
innodb_autoinc_lock_mode=2    
[mysqldump]
quick
max_allowed_packet = 32M

3) pxc-03 complete configuration file as follows:

Similarly, it is not the same three configurations, namely, server-id, logical node name, and the IP address of the node.

[root@pxc-03 src]# cat /etc/my.cnf 
# Example: Percona XtraDB Cluster 5.7
[client]
port = 3306
socket = /tmp/mysql.sock
[mysql]
prompt="\u@\h \R:\m:\s[\d]> "
no-auto-rehash
[mysqld]
user = mysql
port = 3306
basedir = /usr/local/mysql
datadir = /usr/local/mysql/data
socket = /tmp/mysql.sock
pid-file = db.pid
character-set-server = utf8mb4
skip_name_resolve = 1
open_files_limit = 65535
back_log = 1024
max_connections = 512
max_connect_errors = 1000000
table_open_cache = 1024
table_definition_cache = 1024
table_open_cache_instances = 64
thread_stack = 512K
external-locking = FALSE
max_allowed_packet = 32M
sort_buffer_size = 4M
join_buffer_size = 4M
thread_cache_size = 768
#query_cache_size = 0
#query_cache_type = 0
interactive_timeout = 600
wait_timeout = 600
tmp_table_size = 32M
max_heap_table_size = 32M
slow_query_log = 1
slow_query_log_file = /usr/local/mysql/data/slow.log
log-error = /usr/local/mysql/data/error.log
long_query_time = 0.1
server-id = 1813308
log-bin = /usr/local/mysql/data/mysql-bin
sync_binlog = 1
binlog_cache_size = 4M
max_binlog_cache_size = 1G
max_binlog_size = 1G
expire_logs_days = 7
master_info_repository = TABLE
relay_log_info_repository = TABLE
gtid_mode = on
enforce_gtid_consistency = 1
log_slave_updates
binlog_format = row   
relay_log_recovery = 1
relay-log-purge = 1
key_buffer_size = 32M
read_buffer_size = 8M
read_rnd_buffer_size = 4M
bulk_insert_buffer_size = 64M
lock_wait_timeout = 3600
explicit_defaults_for_timestamp = 1
innodb_thread_concurrency = 0
innodb_sync_spin_loops = 100
innodb_spin_wait_delay = 30
transaction_isolation = REPEATABLE-READ
innodb_buffer_pool_size = 1024M
innodb_buffer_pool_instances = 8
innodb_buffer_pool_load_at_startup = 1
innodb_buffer_pool_dump_at_shutdown = 1
innodb_data_file_path = ibdata1:1G:autoextend
innodb_flush_log_at_trx_commit = 1
innodb_log_buffer_size = 32M
innodb_log_file_size = 2G
innodb_log_files_in_group = 2
#innodb_max_undo_log_size = 4G
innodb_io_capacity = 2000
innodb_io_capacity_max = 4000
innodb_flush_neighbors = 0
innodb_write_io_threads = 4
innodb_read_io_threads = 4
innodb_purge_threads = 4
innodb_page_cleaners = 4
innodb_open_files = 65535
innodb_max_dirty_pages_pct = 50
innodb_flush_method = O_DIRECT
innodb_lru_scan_depth = 4000
innodb_checksum_algorithm = crc32
#innodb_file_format = Barracuda
#innodb_file_format_max = Barracuda
innodb_lock_wait_timeout = 10
innodb_rollback_on_timeout = 1
innodb_print_all_deadlocks = 1
innodb_file_per_table = 1
innodb_online_alter_log_max_size = 4G
internal_tmp_disk_storage_engine = InnoDB
innodb_stats_on_metadata = 0
# PXC  
wsrep_provider=/usr/local/mysql/lib/libgalera_smm.so
wsrep_provider_options="gcache.size=2G"
wsrep_cluster_name=my_pxc_cluster
wsrep_cluster_address=gcomm://192.168.20.2,192.168.20.3,192.168.20.4
wsrep_node_name=pxc03
wsrep_node_address=192.168.20.4
wsrep_sst_method=xtrabackup-v2
wsrep_sst_auth=sst:pwd@123
pxc_strict_mode=ENFORCING
default_storage_engine=InnoDB 
innodb_autoinc_lock_mode=2    
[mysqldump]
quick
max_allowed_packet = 32M

8, each node initialization MySQL-related services and open the firewall port

#初始化MySQL服务
[root@pxc-01 ~]# mysqld --defaults-file=/etc/my.cnf --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data/ --initialize
#开启防火墙相关端口
[root@pxc-01 ~]# firewall-cmd --permanent --add-port={3306,4567,4444,4568}/tcp
success
[root@pxc-01 ~]# firewall-cmd --reload
[root@pxc-01 ~]# firewall-cmd --list-all
public (active)
  target: default
  icmp-block-inversion: no
  interfaces: ens33
  sources: 
  services: ssh dhcpv6-client
  ports: 3306/tcp 4567/tcp 4444/tcp 4568/tcp    #确认端口已添加
  protocols: 
  masquerade: no
  forward-ports: 
  source-ports: 
  icmp-blocks: 
  rich rules: 

Port-related information is as follows:

  • mysql service port: 3306
  • Cluster communication ports: 4567
  • SST (State Snaphot Transfer) Port: 4444
  • IST(Incremental State Transfer)端口:4568

NOTE: The next operation, if not specifically stated, are carried out on pxc-01 nodes.

9, the guide pxc-01 initializes the cluster nodes

[root@pxc-01 ~]# mysqld --defaults-file=/etc/my.cnf --wsrep_new_cluster &
[root@pxc-01 ~]# ss -anptl | grep mysql
LISTEN     0      128          *:4567                     *:*                   users:(("mysqld",pid=61739,fd=11))
LISTEN     0      128         :::3306                    :::*                   users:(("mysqld",pid=61739,fd=31))

10, see the initial password and log in to the host in pxc01 MySQL

# 查看初始密码
[root@pxc-01 ~]# grep password /usr/local/mysql/data/error.log 
2020-02-26T13:11:29.770228Z 1 [Note] A temporary password is generated for root@localhost: j?wh;jn=7uB.
#登录数据库,由于有特殊字符,所以要给密码用单引号引起来
[root@pxc-01 ~]# mysql -uroot -p'j?wh;jn=7uB.'    
#修改root用户的初始密码,才能进行其他操作。
root@localhost 21:47: [(none)]> alter user root@localhost identified by '123.com';
# 创建配置文件中指定的sst账号,密码一定要和配置文件中指定的密码一致。
root@localhost 21:47: [(none)]> grant all privileges on *.* to sst@localhost identified by 'pwd@123';

11, will add additional nodes to the cluster

Note: The following operations need to be performed on each pxc-01 to be added to the cluster nodes, I have here is performed separately on pxc-02 and pxc-03 node.

[root@pxc-02 src]# mysqld --defaults-file=/etc/my.cnf &
[1] 61731
[root@pxc-02 src]# ss -anltp | grep mysql    #此刻新加入集群的节点,正在从群集内的节点中同步数据
LISTEN     0      128          *:4567                     *:*                   users:(("mysqld",pid=61731,fd=11))
[root@pxc-02 src]# ss -anltp | grep mysql   
#耐心等待一会,当发现3306端口在监听,则表示数据已同步,该节点已经加入到集群中
LISTEN     0      128          *:4567                     *:*                   users:(("mysqld",pid=61731,fd=11))
LISTEN     0      128         :::3306                    :::*                   users:(("mysqld",pid=61731,fd=36))
#启动成功后的节点,直接可以使用pxc-01节点设置的root密码进行数据库登录操作
#因为pxc-01节点的数据库信息已经同步到了本地数据库节点。
[root@pxc-02 src]# mysql -uroot -p123.com

12. Verify that the replication function

在pxc-01节点创建库及表
[root@pxc-01 ~]# mysql -uroot -p123.com
root@localhost 22:23: [(none)]> create database test01;
root@localhost 22:24: [(none)]> use test01
root@localhost 22:31: [test01]> create table t1(id int primary key,name varchar(10));

# 分别在三个节点上插入一条数据
# pxc-01:
root@localhost 22:31: [test01]> insert into t1(id,name) values(1,'张三');
# pxc-02:
root@localhost 22:33: [(none)]> insert into test01.t1(id,name) values(2,'李四');
# pxc-03:
root@localhost 22:33: [(none)]> insert into test01.t1(id,name) values(3,'王五');

Finally, just to see the new table in any node, it is the following data should look like this:

2020-02-26_223531

13, adding MySQL as a system service

After you add a system service, a later start and stop the service do not need to think first start using the service as mysqld command to start up, but the use of direct systemctl start mysqldcommand.

#拷贝脚本文件
[root@pxc-01 ~]# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
[root@pxc-01 ~]# chkconfig --add mysqld    #添加为系统服务
[root@pxc-01 ~]# chkconfig mysqld on    #加入开机自启

So far, three nodes are added to this cluster of them, later to add additional nodes to the cluster, as long as the configuration and pxc-02 or pxc-03 to node (node ​​configuration pxc-01 slightly not the same, because it is the first node in the cluster).

14, see the cluster status

2020-02-26_223916

Explained above parameters as follows:

  • wsrep_cluster_size: the current number of nodes in the cluster.
  • wsrep_cluster_state_uuid: cluster UUID, the same UUID value in a cluster must be consistent.
  • wsrep_cluster_status: cluster state consisting of primary value indicates normal. The following is an explanation of the various status values:
    • open: node starts successfully, try to connect to the cluster.
    • primary: nodes in the cluster, when a new node joins the cluster, data is selected for production donor state synchronization.
    • joiner: node is a state of waiting to receive the synchronization data file.
    • joined: node has completed data synchronization, and try to maintain a consistent schedule to other nodes in the cluster.
    • synced: normal node state to provide services, it said that it has completed synchronization and clustering and consistent progress.
    • doner: when the node is in a state to provide the total amount of data for a new node is added.

2020-02-26_224422

wsrep_local_state: Displays the current status of the node, a value of 4 indicates normal. The state has four values:

  • joining: represents the node is added to the cluster
  • doner: when the node is in a state to provide the total amount of data for a new node is added.
  • joined: the current node has successfully joined the cluster.
  • synced: the current node in the cluster nodes are synchronized.

Guess you like

Origin blog.51cto.com/14154700/2473891
Recommended