MySQL高可用方案-PXC(Percona XtraDB Cluster)环境部署详解

MySQL高可用方案-PXC(Percona XtraDB Cluster)环境部署详解

Percona XtraDB Cluster简称PXC。Percona Xtradb Cluster的实现是在原mysql代码上通过Galera包将不同的mysql实例连接起来,实现了multi-master的集群架构。
下图中有三个实例,组成了一个集群,而这三个节点与普通的主从架构不同,它们都可以作为主节点,三个节点是对等的,这种一般称为multi-master架构,当有客户端要写入或者读取数据时,随便连接哪个实例都是一样的,读到的数据是相同的,写入某一个节点之后,集群自己会将新数据同步到其它节点上面,这种架构不共享任何数据,是一种高冗余架构。

MySQL高可用方案-PXC(Percona XtraDB Cluster)环境部署详解
此方案无法解决较大MySQL数据场景的数据保存问题,即不能实现分库分表,但是提供了一个高冗余的环境,适合于业务不是很大但是要求数据绝对安全的环境。

Percona XtraDBCluster提供的特性有:

.同步复制,事务要么在所有节点提交或不提交。
.多主复制,可以在任意节点进行写操作。
.在从服务器上并行应用事件,真正意义上的并行复制。
.节点自动配置。
.数据一致性,不再是异步复制。

Percona XtraDBCluster完全兼容MySQL和Percona Server,表现在:
1.数据的兼容性
2.应用程序的兼容性:无需更改应用程序

集群特点:
a.集群是有节点组成的,推荐配置至少3个节点,但是也可以运行在2个节点上。
b.每个节点都是普通的mysql/percona服务器,可以将现有的数据库服务器组成集群,反之,也可以将集群拆分成单独的服务器。
c.每个节点都包含完整的数据副本。

优点如下:

1.当执行一个查询时,在本地节点上执行。因为所有数据都在本地,无需远程访问。
2.无需集中管理。可以在任何时间点失去任何节点,但是集群将照常工作。
3.良好的读负载扩展,任意节点都可以查询。
缺点如下:
1.加入新节点,开销大。需要复制完整的数据。
2.不能有效的解决写缩放问题,所有的写操作都将发生在所有节点上。
3.有多少个节点就有多少重复的数据。

Percona XtraDB Cluster与MySQL Replication区别在于:
分布式系统的CAP理论:
C— 一致性,所有节点的数据一致;
A— 可用性,一个或多个节点失效,不影响服务请求;
P— 分区容忍性,节点间的连接失效,仍然可以处理请求;
任何一个分布式系统,需要满足这三个中的两个。

MySQLReplication: 可用性和分区容忍性;
Percona XtraDBCluster: 一致性和可用性。
因此MySQL Replication并不保证数据的一致性,而Percona XtraDB Cluster提供数据一致性

下面,开始安装PXC 5.7.18

一、环境说明

MySQL高可用方案-PXC(Percona XtraDB Cluster)环境部署详解

IP地址 角色 系统 主机名
192.168.3.12 pxc01 CentOS6.5 master
192.168.3.13 pxc02 CentOS6.5 slave01
192.168.3.198 pxc03 CentOS6.5 slave02

二、安装 Percona-XtraDB-Cluster

1、下载依赖包percona-xtrabackup-24-2.4.7-1.el6.x86_64.rpm到各节点
下载地址:https://www.percona.com/downloads/XtraBackup/LATEST/
安装:

# yum localinstall -y percona-xtrabackup--2.4.-.el6.x86_64.rpm

2、下载Percona-XtraDB-Cluster并上传到各节点
下载地址:https://www.percona.com/downloads/Percona-XtraDB-Cluster-LATEST/

安装包列表:
Percona-XtraDB-Cluster-57-5.7.18-29.20.1.el6.x86_64.rpm
Percona-XtraDB-Cluster-client-57-5.7.18-29.20.1.el6.x86_64.rpm
Percona-XtraDB-Cluster-server-57-5.7.18-29.20.1.el6.x86_64.rpm
Percona-XtraDB-Cluster-shared-57-5.7.18-29.20.1.el6.x86_64.rpm

yum localinstall自动解决依赖关系并进行安装

# yum localinstall Percona-XtraDB-Cluster-*.rpm

3、所有节点创建mysql组和用户

# groupadd mysql
# useradd -r -g mysql -s /bin/false mysql

4、创建相关目录

# mkdir /data/mysql/{data,logs,tmp} -p
# chown -R mysql.mysql /data

5、配置my.cnf文件
将/etc/percona-xtradb-cluster.conf.d/wsrep.cnf拷贝到/etc/my.cnf

# cp /etc/percona-xtradb-cluster.conf.d/wsrep.cnf /etc/my.cnf

编辑my.cnf
第一节点 pxc01

[mysqld]
user=mysql
innodb_buffer_pool_size = 1024M
datadir = /data/mysql/data
port =
server_id =
socket = /data/mysql/mysql.sock
pid-file = /data/mysql/logs/mysql.pid
log-error = /data/mysql/logs/error.log
log_warnings =
slow_query_log_file = /data/mysql/logs/slow.log
long_query_time = 0.1 sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES # Path to Galera library
wsrep_provider=/usr/lib64/galera3/libgalera_smm.so # Cluster connection URL contains IPs of nodes
#If no IP is found, this implies that a new cluster needs to be created,
#in order to do that you need to bootstrap this node
wsrep_cluster_address=gcomm://192.168.3.12,192.168.3.13,192.168.3.198 # 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 # Slave thread to use
wsrep_slave_threads= wsrep_log_conflicts # This changes how InnoDB autoincrement locks are managed and is a requirement for Galera
innodb_autoinc_lock_mode= # Node IP address
wsrep_node_address=192.168.3.12
# Cluster name
wsrep_cluster_name=my-pxc-cluster #If wsrep_node_name is not specified, then system hostname will be used
wsrep_node_name=pxc01 #pxc_strict_mode allowed values: DISABLED,PERMISSIVE,ENFORCING,MASTER
pxc_strict_mode=ENFORCING # SST method
wsrep_sst_method=xtrabackup-v2 #Authentication for SST method
wsrep_sst_auth="sstuser:sstuser"

第二节点 pxc02
注意修改 server_id 、wsrep_node_name 、 wsrep_node_address

[mysqld]
user=mysql
innodb_buffer_pool_size = 1024M
datadir = /data/mysql/data
port =
server_id =
socket = /data/mysql/mysql.sock
pid-file = /data/mysql/logs/mysql.pid
log-error = /data/mysql/logs/error.log
log_warnings =
slow_query_log_file = /data/mysql/logs/slow.log
long_query_time = 0.1 sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES # Path to Galera library
wsrep_provider=/usr/lib64/galera3/libgalera_smm.so # Cluster connection URL contains IPs of nodes
#If no IP is found, this implies that a new cluster needs to be created,
#in order to do that you need to bootstrap this node
wsrep_cluster_address=gcomm://192.168.3.12,192.168.3.13,192.168.3.198 # 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 # Slave thread to use
wsrep_slave_threads= wsrep_log_conflicts # This changes how InnoDB autoincrement locks are managed and is a requirement for Galera
innodb_autoinc_lock_mode= # Node IP address
wsrep_node_address=192.168.3.13
# Cluster name
wsrep_cluster_name=my-pxc-cluster #If wsrep_node_name is not specified, then system hostname will be used
wsrep_node_name=pxc02 #pxc_strict_mode allowed values: DISABLED,PERMISSIVE,ENFORCING,MASTER
pxc_strict_mode=ENFORCING # SST method
wsrep_sst_method=xtrabackup-v2 #Authentication for SST method
wsrep_sst_auth="sstuser:sstuser"

第三节点 pxc03
注意修改 server_id 、wsrep_node_name 、 wsrep_node_address

[mysqld]
user=mysql
innodb_buffer_pool_size = 1024M
datadir = /data/mysql/data
port =
server_id =
socket = /data/mysql/mysql.sock
pid-file = /data/mysql/logs/mysql.pid
log-error = /data/mysql/logs/error.log
log_warnings =
slow_query_log_file = /data/mysql/logs/slow.log
long_query_time = 0.1 sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES # Path to Galera library
wsrep_provider=/usr/lib64/galera3/libgalera_smm.so # Cluster connection URL contains IPs of nodes
#If no IP is found, this implies that a new cluster needs to be created,
#in order to do that you need to bootstrap this node
wsrep_cluster_address=gcomm://192.168.3.12,192.168.3.13,192.168.3.198 # 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 # Slave thread to use
wsrep_slave_threads= wsrep_log_conflicts # This changes how InnoDB autoincrement locks are managed and is a requirement for Galera
innodb_autoinc_lock_mode= # Node IP address
wsrep_node_address=192.168.3.198
# Cluster name
wsrep_cluster_name=my-pxc-cluster #If wsrep_node_name is not specified, then system hostname will be used
wsrep_node_name=pxc03 #pxc_strict_mode allowed values: DISABLED,PERMISSIVE,ENFORCING,MASTER
pxc_strict_mode=ENFORCING # SST method
wsrep_sst_method=xtrabackup-v2 #Authentication for SST method
wsrep_sst_auth="sstuser:sstuser

三、启动PXC

1、启动第一节点

[root@master ~]# /etc/init.d/mysql bootstrap-pxc
Bootstrapping PXC (Percona XtraDB Cluster)Initializing MySQ[ OK ]se:
Starting MySQL (Percona XtraDB Cluster)....................[ OK ]

查看进程和端口是否启动

[root@master ~]# ps -ef|grep mysql
root : pts/ :: /bin/sh /usr/bin/mysqld_safe --datadir=/data/mysql/data --pid-file=/data/mysql/logs/mysql.pid --wsrep-new-cluster
mysql : pts/ :: /usr/sbin/mysqld --basedir=/usr --datadir=/data/mysql/data --plugin-dir=/usr/lib64/mysql/plugin --user=mysql --wsrep-provider=/usr/lib64/galera3/libgalera_smm.so --wsrep-new-cluster --log-error=/data/mysql/logs/error.log --pid-file=/data/mysql/logs/mysql.pid --socket=/data/mysql/mysql.sock --port= --wsrep_start_position=----:-

[root@master mysql]# ss -tnlp|grep 4567
LISTEN 0 128 *:4567 *:* users:(("mysqld",28347,11))

查看错误日志信息

[root@master mysql]# tail -f logs/error.log

--07T02::.794514Z  [Note] WSREP: Node 04b5f0f9 state primary
--07T02::.794674Z [Note] WSREP: Current view of cluster as seen by this node
view (view_id(PRIM,04b5f0f9,)
memb {
04b5f0f9,
}
joined {
}
left {
}
partitioned {
}
)
--07T02::.794745Z [Note] WSREP: Save the discovered primary-component to disk
--07T02::.794882Z [Note] WSREP: discarding pending addr without UUID: tcp://192.168.3.12:4567
--07T02::.794926Z [Note] WSREP: discarding pending addr proto entry 0x7f16aefcfcc0
--07T02::.794988Z [Note] WSREP: discarding pending addr without UUID: tcp://192.168.3.13:4567
--07T02::.795028Z [Note] WSREP: discarding pending addr proto entry 0x7f16aefcff00
--07T02::.795060Z [Note] WSREP: discarding pending addr without UUID: tcp://192.168.3.198:4567
--07T02::.795098Z [Note] WSREP: discarding pending addr proto entry 0x7f16aefcffc0
--07T02::.795158Z [Note] WSREP: gcomm: connected
--07T02::.795328Z [Note] WSREP: Shifting CLOSED -> OPEN (TO: )
--07T02::.797700Z [Note] WSREP: Waiting for SST/IST to complete.
--07T02::.391420Z [Note] WSREP: New COMPONENT: primary = yes, bootstrap = no, my_idx = , memb_num =
--07T02::.020639Z [Note] WSREP: Starting new group from scratch: 05719dfe-4b28-11e7-a651-ab4ab48f9b60
--07T02::.021473Z [Note] WSREP: STATE_EXCHANGE: sent state UUID: 0571c6e9-4b28-11e7-b20d-5a8bf004e006
--07T02::.021523Z [Note] WSREP: STATE EXCHANGE: sent state msg: 0571c6e9-4b28-11e7-b20d-5a8bf004e006
--07T02::.021547Z [Note] WSREP: STATE EXCHANGE: got state msg: 0571c6e9-4b28-11e7-b20d-5a8bf004e006 from (pxc01)
--07T02::.021571Z [Note] WSREP: Quorum results:
version = ,
component = PRIMARY,
conf_id = ,
members = / (primary/total),
act_id = ,
last_appl. = -,
protocols = // (gcs/repl/appl),
group UUID = 05719dfe-4b28-11e7-a651-ab4ab48f9b60
--07T02::.021599Z [Note] WSREP: Flow-control interval: [, ]
--07T02::.021615Z [Note] WSREP: Restored state OPEN -> JOINED ()
--07T02::.021976Z [Note] WSREP: Member 0.0 (pxc01) synced with group.
--07T02::.022019Z [Note] WSREP: Shifting JOINED -> SYNCED (TO: )
--07T02::.022101Z [Note] WSREP: New cluster view: global state: 05719dfe-4b28-11e7-a651-ab4ab48f9b60:, view# : Primary, number of nodes: , my index: , protocol version
--07T02::.023374Z [Note] WSREP: SST complete, seqno:
--07T02::.535748Z [Note] InnoDB: PUNCH HOLE support available
--07T02::.535815Z [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
--07T02::.535826Z [Note] InnoDB: Uses event mutexes
--07T02::.535832Z [Note] InnoDB: GCC builtin __sync_synchronize() is used for memory barrier
--07T02::.535837Z [Note] InnoDB: Compressed tables use zlib 1.2.
--07T02::.535842Z [Note] InnoDB: Using Linux native AIO
--07T02::.536865Z [Note] InnoDB: Number of pools:
--07T02::.536999Z [Note] InnoDB: Using CPU crc32 instructions
--07T02::.194918Z [Note] InnoDB: Initializing buffer pool, total size = 1G, instances = , chunk size = 128M
--07T02::.225447Z [Note] InnoDB: Completed initialization of buffer pool
--07T02::.228192Z [Note] InnoDB: If the mysqld execution user is authorized, page cleaner thread priority can be changed. See the man page of setpriority().
--07T02::.554968Z [Note] InnoDB: Crash recovery did not find the parallel doublewrite buffer at /data/mysql/data/xb_doublewrite
--07T02::.556158Z [Note] InnoDB: Highest supported file format is Barracuda.
--07T02::.397187Z [Note] InnoDB: Created parallel doublewrite buffer at /data/mysql/data/xb_doublewrite, size bytes
--07T02::.700377Z [Note] InnoDB: Creating shared tablespace for temporary tables
--07T02::.700541Z [Note] InnoDB: Setting file './ibtmp1' size to MB. Physically writing the file full; Please wait ...
--07T02::.413452Z [Note] InnoDB: File './ibtmp1' size is now MB.
--07T02::.414626Z [Note] InnoDB: redo rollback segment(s) found. redo rollback segment(s) are active.
--07T02::.414664Z [Note] InnoDB: non-redo rollback segment(s) are active.
--07T02::.416853Z [Note] InnoDB: Waiting for purge to start
--07T02::.468115Z [Note] InnoDB: Percona XtraDB (http://www.percona.com) 5.7.18-15 started; log sequence number 2542677
--07T02::.468456Z [Note] Plugin 'FEDERATED' is disabled.
--07T02::.468710Z [Note] InnoDB: Loading buffer pool(s) from /data/mysql/data/ib_buffer_pool
--07T02::.472685Z [Note] InnoDB: Buffer pool(s) load completed at ::
--07T02::.477798Z [Note] Found ca.pem, server-cert.pem and server-key.pem in data directory. Trying to enable SSL support using them.
--07T02::.477886Z [Note] Skipping generation of SSL certificates as certificate files are present in data directory.
--07T02::.515627Z [Warning] CA certificate ca.pem is self signed.
--07T02::.544887Z [Note] Skipping generation of RSA key pair as key files are present in data directory.
--07T02::.545210Z [Note] Server hostname (bind-address): '*'; port:
--07T02::.545499Z [Note] IPv6 is available.
--07T02::.545557Z [Note] - '::' resolves to '::';
--07T02::.545717Z [Note] Server socket created on IP: '::'.
--07T02::.611502Z [Note] Event Scheduler: Loaded events
--07T02::.651338Z [Note] WSREP: Initialized wsrep sidno
--07T02::.651403Z [Note] WSREP: wsrep_notify_cmd is not defined, skipping notification.
--07T02::.651443Z [Note] WSREP: REPL Protocols: (, )
--07T02::.651455Z [Note] WSREP: Assign initial position for certification: , protocol version:
--07T02::.651862Z [Note] WSREP: Service thread queue flushed.
--07T02::.765979Z [Note] /usr/sbin/mysqld: ready for connections.
Version: '5.7.18-15-57' socket: '/data/mysql/mysql.sock' port: Percona XtraDB Cluster (GPL), Release rel15, Revision 7693d6e, WSREP version 29.20, wsrep_29.
--07T02::.766032Z [Note] Executing 'SELECT * FROM INFORMATION_SCHEMA.TABLES;' to get a list of tables using the deprecated partition engine. You may use the startup option '--disable-partition-engine-check' to skip this check.
--07T02::.766043Z [Note] Beginning of list of non-natively partitioned tables
--07T02::.766034Z [Note] WSREP: GCache history reset: old(----:) -> new(05719dfe-4b28-11e7-a651-ab4ab48f9b60:)
--07T02::.767985Z [Note] WSREP: Synchronized with group, ready for connections
--07T02::.768012Z [Note] WSREP: wsrep_notify_cmd is not defined, skipping notification.
--07T02::.824186Z [Note] End of list of non-natively partitioned tables

去error.log日志搜索关键字password找到默认root密码,登录后修改密码(如果不修改密码无法进行其他sql操作)
2017-06-07T02:21:11.228127Z 1 [Note] A temporary password is generated for root@localhost: eu1-!5WyRw<7

修改密码:

# mysql -S /data/mysql/mysql.sock -uroot -peu1-!5WyRw<
mysql> alter user 'root'@'localhost' identified by '';

第一节点启动后,检查cluster的状态。
当前第一节点是Primary。

mysql> show status like '%wsrep%';
+----------------------------------+--------------------------------------+
| Variable_name | Value |
+----------------------------------+--------------------------------------+
| wsrep_local_state_uuid | 05719dfe-4b28-11e7-a651-ab4ab48f9b60 |
| wsrep_protocol_version | |
| wsrep_last_committed | |
| wsrep_replicated | |
| wsrep_replicated_bytes | |
| wsrep_repl_keys | |
| wsrep_repl_keys_bytes | |
| wsrep_repl_data_bytes | |
| wsrep_repl_other_bytes | |
| wsrep_received | |
| wsrep_received_bytes | |
| wsrep_local_commits | |
| wsrep_local_cert_failures | |
| wsrep_local_replays | |
| wsrep_local_send_queue | |
| wsrep_local_send_queue_max | |
| wsrep_local_send_queue_min | |
| wsrep_local_send_queue_avg | 0.000000 |
| wsrep_local_recv_queue | |
| wsrep_local_recv_queue_max | |
| wsrep_local_recv_queue_min | |
| wsrep_local_recv_queue_avg | 0.000000 |
| wsrep_local_cached_downto | |
| wsrep_flow_control_paused_ns | |
| wsrep_flow_control_paused | 0.000000 |
| wsrep_flow_control_sent | |
| wsrep_flow_control_recv | |
| wsrep_flow_control_interval | [ , ] |
| wsrep_flow_control_interval_low | |
| wsrep_flow_control_interval_high | |
| wsrep_flow_control_status | OFF |
| wsrep_cert_deps_distance | 1.000000 |
| wsrep_apply_oooe | 0.000000 |
| wsrep_apply_oool | 0.000000 |
| wsrep_apply_window | 1.000000 |
| wsrep_commit_oooe | 0.000000 |
| wsrep_commit_oool | 0.000000 |
| wsrep_commit_window | 1.000000 |
| wsrep_local_state | |
| wsrep_local_state_comment | Synced |
| wsrep_cert_index_size | |
| wsrep_cert_bucket_count | |
| wsrep_gcache_pool_size | |
| wsrep_causal_reads | |
| wsrep_cert_interval | 0.000000 |
| wsrep_ist_receive_status | |
| wsrep_ist_receive_seqno_start | |
| wsrep_ist_receive_seqno_current | |
| wsrep_ist_receive_seqno_end | |
| wsrep_incoming_addresses | 192.168.3.12: |
| wsrep_desync_count | |
| wsrep_evs_delayed | |
| wsrep_evs_evict_list | |
| wsrep_evs_repl_latency | 1.8541e-05/1.8541e-05/1.8541e-05// |
| wsrep_evs_state | OPERATIONAL |
| wsrep_gcomm_uuid | 04b5f0f9-4b28-11e7-aff6-522901b34a55 |
| wsrep_cluster_conf_id | |
| wsrep_cluster_size | |
| wsrep_cluster_state_uuid | 05719dfe-4b28-11e7-a651-ab4ab48f9b60 |
| wsrep_cluster_status | Primary |
| wsrep_connected | ON |
| wsrep_local_bf_aborts | |
| wsrep_local_index | |
| wsrep_provider_name | Galera |
| wsrep_provider_vendor | Codership Oy <info@codership.com> |
| wsrep_provider_version | 3.20(r7e383f7) |
| wsrep_ready | ON |
+----------------------------------+--------------------------------------+

第一节点创建后,其他节点初始化,需要使用xtrabackup工具来备份,然后恢复。
所以,需要创建一个用户用于备份。

mysql> create user 'sstuser'@'localhost' identified by 'sstuser';
mysql> grant reload,lock tables,replication client,process on *.* to 'sstuser'@'localhost';
mysql> flush privileges;

验证sstuser登录

[root@master ~]# mysql -usstuser -psstuser -S /data/mysql/mysql.sock -e 'show databases'
Warning: Using a password on the command line interface can be insecure.
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+

启动第二节点

# /etc/init.d/mysql start
确认第二节点的状态

# mysql -usstuser -psstuser -S /data/mysql/mysql.sock -e 'show status like "wsrep%"'
Warning: Using a password on the command line interface can be insecure.
+----------------------------------+--------------------------------------+
| Variable_name | Value |
+----------------------------------+--------------------------------------+
| wsrep_local_state_uuid | 05719dfe-4b28-11e7-a651-ab4ab48f9b60 |
| wsrep_protocol_version | |
| wsrep_last_committed | |
| wsrep_replicated | |
| wsrep_replicated_bytes | |
| wsrep_repl_keys | |
| wsrep_repl_keys_bytes | |
| wsrep_repl_data_bytes | |
| wsrep_repl_other_bytes | |
| wsrep_received | |
| wsrep_received_bytes | |
| wsrep_local_commits | |
| wsrep_local_cert_failures | |
| wsrep_local_replays | |
| wsrep_local_send_queue | |
| wsrep_local_send_queue_max | |
| wsrep_local_send_queue_min | |
| wsrep_local_send_queue_avg | 0.000000 |
| wsrep_local_recv_queue | |
| wsrep_local_recv_queue_max | |
| wsrep_local_recv_queue_min | |
| wsrep_local_recv_queue_avg | 0.000000 |
| wsrep_local_cached_downto | |
| wsrep_flow_control_paused_ns | |
| wsrep_flow_control_paused | 0.000000 |
| wsrep_flow_control_sent | |
| wsrep_flow_control_recv | |
| wsrep_flow_control_interval | [ , ] |
| wsrep_flow_control_interval_low | |
| wsrep_flow_control_interval_high | |
| wsrep_flow_control_status | OFF |
| wsrep_cert_deps_distance | 1.000000 |
| wsrep_apply_oooe | 0.000000 |
| wsrep_apply_oool | 0.000000 |
| wsrep_apply_window | 1.000000 |
| wsrep_commit_oooe | 0.000000 |
| wsrep_commit_oool | 0.000000 |
| wsrep_commit_window | 1.000000 |
| wsrep_local_state | |
| wsrep_local_state_comment | Synced |
| wsrep_cert_index_size | |
| wsrep_cert_bucket_count | |
| wsrep_gcache_pool_size | |
| wsrep_causal_reads | |
| wsrep_cert_interval | 0.000000 |
| wsrep_ist_receive_status | |
| wsrep_ist_receive_seqno_start | |
| wsrep_ist_receive_seqno_current | |
| wsrep_ist_receive_seqno_end | |
| wsrep_incoming_addresses | 192.168.3.12:,192.168.3.13: |
| wsrep_desync_count | |
| wsrep_evs_delayed | |
| wsrep_evs_evict_list | |
| wsrep_evs_repl_latency | //// |
| wsrep_evs_state | OPERATIONAL |
| wsrep_gcomm_uuid | 04b5f0f9-4b28-11e7-aff6-522901b34a55 |
| wsrep_cluster_conf_id | |
| wsrep_cluster_size | |
| wsrep_cluster_state_uuid | 05719dfe-4b28-11e7-a651-ab4ab48f9b60 |
| wsrep_cluster_status | Primary |
| wsrep_connected | ON |
| wsrep_local_bf_aborts | |
| wsrep_local_index | |
| wsrep_provider_name | Galera |
| wsrep_provider_vendor | Codership Oy <info@codership.com> |
| wsrep_provider_version | 3.20(r7e383f7) |
| wsrep_ready | ON |
+----------------------------------+--------------------------------------+

启动第三节点

# /etc/init.d/mysql start

确定状态

[root@slave02 ~]# mysql -S /data/mysql/mysql.sock -usstuser -psstuser -e 'show status like "wsrep%"';
Warning: Using a password on the command line interface can be insecure.
+----------------------------------+--------------------------------------------------------+
| Variable_name | Value |
+----------------------------------+--------------------------------------------------------+
| wsrep_local_state_uuid | 05719dfe-4b28-11e7-a651-ab4ab48f9b60 |
| wsrep_protocol_version | |
| wsrep_last_committed | |
| wsrep_replicated | |
| wsrep_replicated_bytes | |
| wsrep_repl_keys | |
| wsrep_repl_keys_bytes | |
| wsrep_repl_data_bytes | |
| wsrep_repl_other_bytes | |
| wsrep_received | |
| wsrep_received_bytes | |
| wsrep_local_commits | |
| wsrep_local_cert_failures | |
| wsrep_local_replays | |
| wsrep_local_send_queue | |
| wsrep_local_send_queue_max | |
| wsrep_local_send_queue_min | |
| wsrep_local_send_queue_avg | 0.000000 |
| wsrep_local_recv_queue | |
| wsrep_local_recv_queue_max | |
| wsrep_local_recv_queue_min | |
| wsrep_local_recv_queue_avg | 0.000000 |
| wsrep_local_cached_downto | |
| wsrep_flow_control_paused_ns | |
| wsrep_flow_control_paused | 0.000000 |
| wsrep_flow_control_sent | |
| wsrep_flow_control_recv | |
| wsrep_flow_control_interval | [ , ] |
| wsrep_flow_control_interval_low | |
| wsrep_flow_control_interval_high | |
| wsrep_flow_control_status | OFF |
| wsrep_cert_deps_distance | 0.000000 |
| wsrep_apply_oooe | 0.000000 |
| wsrep_apply_oool | 0.000000 |
| wsrep_apply_window | 0.000000 |
| wsrep_commit_oooe | 0.000000 |
| wsrep_commit_oool | 0.000000 |
| wsrep_commit_window | 0.000000 |
| wsrep_local_state | |
| wsrep_local_state_comment | Synced |
| wsrep_cert_index_size | |
| wsrep_cert_bucket_count | |
| wsrep_gcache_pool_size | |
| wsrep_causal_reads | |
| wsrep_cert_interval | 0.000000 |
| wsrep_ist_receive_status | |
| wsrep_ist_receive_seqno_start | |
| wsrep_ist_receive_seqno_current | |
| wsrep_ist_receive_seqno_end | |
| wsrep_incoming_addresses | 192.168.3.12:,192.168.3.13:,192.168.3.198: |
| wsrep_desync_count | |
| wsrep_evs_delayed | |
| wsrep_evs_evict_list | |
| wsrep_evs_repl_latency | //// |
| wsrep_evs_state | OPERATIONAL |
| wsrep_gcomm_uuid | ca7f9f30-4b2b-11e7-a0b7-e29969825862 |
| wsrep_cluster_conf_id | |
| wsrep_cluster_size | |
| wsrep_cluster_state_uuid | 05719dfe-4b28-11e7-a651-ab4ab48f9b60 |
| wsrep_cluster_status | Primary |
| wsrep_connected | ON |
| wsrep_local_bf_aborts | |
| wsrep_local_index | |
| wsrep_provider_name | Galera |
| wsrep_provider_vendor | Codership Oy <info@codership.com> |
| wsrep_provider_version | 3.20(r7e383f7) |
| wsrep_ready | ON |
+----------------------------------+--------------------------------------------------------+

简单测试:

在pxc03上创建数据库tdoa,并在上面建表,且插入几条数据

mysql> create database tdoa charset='utf8mb4';
Query OK, row affected (0.05 sec) mysql> use tdoa;
Database changed
mysql> create table user(id int unsigned primary key auto_increment,name varchar());
Query OK, rows affected (0.05 sec) mysql> show tables;
+----------------+
| Tables_in_tdoa |
+----------------+
| user |
+----------------+
row in set (0.00 sec) mysql> insert into user(name) values('jack'),('tom'),('lily'),('lucy');
Query OK, rows affected (0.07 sec)
Records: Duplicates: Warnings: mysql> select * from user;
+----+------+
| id | name |
+----+------+
| | jack |
| | tom |
| | lily |
| | lucy |
+----+------+
rows in set (0.00 sec) mysql> commit;
Query OK, rows affected (0.00 sec) mysql> select * from user;
+----+------+
| id | name |
+----+------+
| | jack |
| | tom |
| | lily |
| | lucy |
+----+------+
rows in set (0.01 sec)

分别在pxc01和pxc02上查看是否有这个表和数据,可以看到数据能够正常同步

[root@master ~]# mysql -S /data/mysql/mysql.sock -uroot -p123456 -e 'use tdoa;show tables;select * from user;'
Warning: Using a password on the command line interface can be insecure.
+----------------+
| Tables_in_tdoa |
+----------------+
| user |
+----------------+
+----+------+
| id | name |
+----+------+
| | jack |
| | tom |
| | lily |
| | lucy | [root@slave01 ~]# mysql -S /data/mysql/mysql.sock -uroot -p123456 -e 'use tdoa;show tables;select * from user;'
Warning: Using a password on the command line interface can be insecure.
+----------------+
| Tables_in_tdoa |
+----------------+
| user |
+----------------+
+----+------+
| id | name |
+----+------+
| | jack |
| | tom |
| | lily |
| | lucy |
+----+------+

至此,PXC安装启动完毕。

上一篇:java无锁化编程一:目录


下一篇:hdu 4335 What is N?