mysql5.7 pxc

mysql5.7  pxc

pxc优点总结:
可以达到时时同步,无延迟现象发生
完全兼容MySQL
对于集群中新节点的加入,维护起来很简单
数据的强一致性
不足之处总结:
只支持Innodb存储引擎
存在多节点update更新问题,也就是写放大问题
在线DDL语句,锁表问题
sst针对新节点加入的传输代价过高的问题

关于写放大的原理图

 mysql5.7  pxc

下面从上次组复制转pxc

https://www.cnblogs.com/omsql/p/9277047.html

pxc架构图如下

mysql5.7  pxc

卸载mysql

卸载前记得备份my.cnf

yum remove mysql-community-*

安装pxc

yum install http://www.percona.com/downloads/percona-release/redhat/0.1-6/percona-release-0.1-6.noarch.rpm
yum install http://rpmfind.net/linux/dag/redhat/el6/en/x86_64/dag/RPMS/socat-1.7.2.4-1.el6.rf.x86_64.rpm
yum install Percona-XtraDB-Cluster-57

修改my.cnf

#pxc
wsrep_provider=/usr/lib64/galera3/libgalera_smm.so
wsrep_cluster_address=gcomm://192.168.20.201,192.168.20.202,192.168.20.203
wsrep_slave_threads= 8
innodb_autoinc_lock_mode=2
wsrep_node_address=192.168.20.201
wsrep_cluster_name=ht-pxc-cluster
wsrep_node_name=pxc01
pxc_strict_mode=ENFORCING
wsrep_sst_method=xtrabackup-v2
wsrep_sst_auth=sst:ocm123

第一个节点启动
/etc/init.d/mysqld bootstrap-pxc
创建用户
SHOW VARIABLES LIKE 'validate_password%';
set global validate_password_policy=LOW;
set global validate_password_length=4;
create user 'sst'@'localhost' identified by 'ocm123';
grant all privileges on *.* to 'sst'@'localhost' identified by 'ocm123';
flush privileges;

第二个节点启动
/etc/init.d/mysql start
第三个节点启动
/etc/init.d/mysql start

  添加第三个节点redis03的时候redis02日志输出如下

1 redis02
2 2018-07-09T15:01:19.004758Z 0 [Note] WSREP: Member 2.0 (pxc03) requested state transfer from '*any*'. Selected 0.0 (pxc02)(SYNCED) as donor.
3 2018-07-09T15:01:19.004800Z 0 [Note] WSREP: Shifting SYNCED -> DONOR/DESYNCED (TO: 7054)
4 2018-07-09T15:01:19.004867Z 5 [Note] WSREP: wsrep_notify_cmd is not defined, skipping notification.
5 2018-07-09T15:01:19.005039Z 0 [Note] WSREP: Initiating SST/IST transfer on DONOR side (wsrep_sst_xtrabackup-v2 --role 'donor' --address '192.168.20.203:4444/xtrabackup_sst//1' --socket '/data/mysql/mysql.sock' --datadir '/data/mysql/' --defaults-file '/etc/my.cnf' --defaults-group-suffix ''  --binlog 'mysql-bin' --gtid '62e9006b-8379-11e8-bc64-874d49a77c07:7054')
6 2018-07-09T15:01:19.087469Z 5 [Note] WSREP: DONOR thread signaled with 0
View Code

redis02被选为donar,使用xtrabackup备份整个库传到redis03下,同时查看redis03  /data/mysql

[root@redis03 mysql]# ls
galera.cache  grastate.dat  gvwstate.dat  sst_in_progress

恢复完后如下

1 [root@redis03 mysql]# ls
2 auto.cnf         grastate.dat    ib_logfile1             mysql-bin.000007    public_key.pem                                       server-cert.pem               xtrabackup_info
3 ca-key.pem       gvwstate.dat    ibtmp1                  mysql-bin.index     pxc                                                  server-key.pem                xtrabackup_master_key_id
4 ca.pem           ht              innobackup.move.log     mysql.sock          redis03-relay-bin-group_replication_applier.000001   sys
5 client-cert.pem  ib_buffer_pool  innobackup.prepare.log  mysql.sock.lock     redis03-relay-bin-group_replication_applier.index    xb_doublewrite
6 client-key.pem   ibdata1         mysql                   performance_schema  redis03-relay-bin-group_replication_recovery.000001  xtrabackup_binlog_pos_innodb
7 galera.cache     ib_logfile0     mysql-bin.000006        private_key.pem     redis03-relay-bin-group_replication_recovery.index   xtrabackup_galera_info

上面输出可以看出sst针对新节点加入的传输代价过高。

查看集群状态

root@redis03> show status like 'wsrep%';
+----------------------------------+-------------------------------------------------------------+
| Variable_name                    | Value                                                       |
+----------------------------------+-------------------------------------------------------------+
| wsrep_local_state_uuid           | 62e9006b-8379-11e8-bc64-874d49a77c07                        |
| wsrep_protocol_version           | 8                                                           |
| wsrep_last_applied               | 7054                                                        |
| wsrep_last_committed             | 7054                                                        |
| wsrep_replicated                 | 0                                                           |
| wsrep_replicated_bytes           | 0                                                           |
| wsrep_repl_keys                  | 0                                                           |
| wsrep_repl_keys_bytes            | 0                                                           |
| wsrep_repl_data_bytes            | 0                                                           |
| wsrep_repl_other_bytes           | 0                                                           |
| wsrep_received                   | 2                                                           |
| wsrep_received_bytes             | 285                                                         |
| wsrep_local_commits              | 0                                                           |
| wsrep_local_cert_failures        | 0                                                           |
| wsrep_local_replays              | 0                                                           |
| wsrep_local_send_queue           | 0                                                           |
| wsrep_local_send_queue_max       | 1                                                           |
| wsrep_local_send_queue_min       | 0                                                           |
| wsrep_local_send_queue_avg       | 0.000000                                                    |
| wsrep_local_recv_queue           | 0                                                           |
| wsrep_local_recv_queue_max       | 1                                                           |
| wsrep_local_recv_queue_min       | 0                                                           |
| wsrep_local_recv_queue_avg       | 0.000000                                                    |
| wsrep_local_cached_downto        | 0                                                           |
| wsrep_flow_control_paused_ns     | 0                                                           |
| wsrep_flow_control_paused        | 0.000000                                                    |
| wsrep_flow_control_sent          | 0                                                           |
| wsrep_flow_control_recv          | 0                                                           |
| wsrep_flow_control_interval      | [ 173, 173 ]                                                |
| wsrep_flow_control_interval_low  | 173                                                         |
| wsrep_flow_control_interval_high | 173                                                         |
| 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                | 4                                                           |
| wsrep_local_state_comment        | Synced                                                      |
| wsrep_cert_index_size            | 0                                                           |
| wsrep_cert_bucket_count          | 22                                                          |
| wsrep_gcache_pool_size           | 1320                                                        |
| wsrep_causal_reads               | 0                                                           |
| wsrep_cert_interval              | 0.000000                                                    |
| wsrep_ist_receive_status         |                                                             |
| wsrep_ist_receive_seqno_start    | 0                                                           |
| wsrep_ist_receive_seqno_current  | 0                                                           |
| wsrep_ist_receive_seqno_end      | 0                                                           |
| wsrep_incoming_addresses         | 192.168.20.202:3306,192.168.20.201:3306,192.168.20.203:3306 |
| wsrep_desync_count               | 0                                                           |
| wsrep_evs_delayed                |                                                             |
| wsrep_evs_evict_list             |                                                             |
| wsrep_evs_repl_latency           | 0/0/0/0/0                                                   |
| wsrep_evs_state                  | OPERATIONAL                                                 |
| wsrep_gcomm_uuid                 | ee9c63ef-8388-11e8-af36-8bf4f2f07974                        |
| wsrep_cluster_conf_id            | 5                                                           |
| wsrep_cluster_size               | 3                                                           |
| wsrep_cluster_state_uuid         | 62e9006b-8379-11e8-bc64-874d49a77c07                        |
| wsrep_cluster_status             | Primary                                                     |
| wsrep_connected                  | ON                                                          |
| wsrep_local_bf_aborts            | 0                                                           |
| wsrep_local_index                | 2                                                           |
| wsrep_provider_name              | Galera                                                      |
| wsrep_provider_vendor            | Codership Oy <info@codership.com>                           |
| wsrep_provider_version           | 3.26(rac090bc)                                              |
| wsrep_ready                      | ON                                                          |
+----------------------------------+-------------------------------------------------------------+
View Code

在对pxc做此oltp测试

安装sysbench
yum install sysbench
生成数据,创建10个表,每个表百万行
sysbench oltp_common  --tables=10 --table-size=1000000 --db-driver=mysql  --mysql-db=pxc --mysql-user=root --mysql-password=ocm123  prepare

oltp 测试,开启50个并行
sysbench oltp_read_write.lua --db-driver=mysql --mysql-host=127.0.0.1 --mysql-port=3306 --mysql-db=pxc --mysql-user=root --mysql-password=ocm123 --table_size=1000000  --tables=10 --threads=50 --report-interval=10 --time=300  run

  oltp测试结果如下

 1 [root@redis01 sysbench]# sysbench oltp_read_write.lua --db-driver=mysql --mysql-host=127.0.0.1 --mysql-port=3306 --mysql-db=pxc --mysql-user=root --mysql-password=ocm123 --table_size=1000000  --tables=10 --threads=50 --report-interval=10 --time=300  run
 2 sysbench 1.0.14 (using bundled LuaJIT 2.1.0-beta2)
 3 
 4 Running the test with following options:
 5 Number of threads: 50
 6 Report intermediate results every 10 second(s)
 7 Initializing random number generator from current time
 8 
 9 
10 Initializing worker threads...
11 
12 Threads started!
13 
14 [ 10s ] thds: 50 tps: 7.90 qps: 231.92 (r/w/o: 168.04/26.19/37.69) lat (ms,95%): 5813.24 err/s: 0.00 reconn/s: 0.00
15 [ 20s ] thds: 50 tps: 11.80 qps: 254.99 (r/w/o: 177.69/32.30/45.00) lat (ms,95%): 5918.87 err/s: 0.00 reconn/s: 0.00
16 [ 30s ] thds: 50 tps: 8.90 qps: 179.97 (r/w/o: 124.58/26.10/29.30) lat (ms,95%): 6476.48 err/s: 0.00 reconn/s: 0.00
17 [ 40s ] thds: 50 tps: 10.40 qps: 175.17 (r/w/o: 122.35/19.81/33.01) lat (ms,95%): 9284.15 err/s: 0.00 reconn/s: 0.00
18 [ 50s ] thds: 50 tps: 9.20 qps: 182.49 (r/w/o: 131.10/21.90/29.50) lat (ms,95%): 9799.46 err/s: 0.00 reconn/s: 0.00
19 [ 60s ] thds: 50 tps: 8.80 qps: 198.65 (r/w/o: 140.97/24.39/33.29) lat (ms,95%): 7215.39 err/s: 0.00 reconn/s: 0.00
20 [ 70s ] thds: 50 tps: 7.00 qps: 145.72 (r/w/o: 99.01/21.60/25.10) lat (ms,95%): 8795.93 err/s: 0.00 reconn/s: 0.00
21 [ 80s ] thds: 50 tps: 13.70 qps: 239.41 (r/w/o: 171.21/27.20/41.00) lat (ms,95%): 8484.79 err/s: 0.00 reconn/s: 0.00
22 [ 90s ] thds: 50 tps: 7.40 qps: 161.92 (r/w/o: 107.41/24.90/29.60) lat (ms,95%): 8484.79 err/s: 0.00 reconn/s: 0.00
23 [ 100s ] thds: 50 tps: 8.00 qps: 186.69 (r/w/o: 130.99/24.00/31.70) lat (ms,95%): 5918.87 err/s: 0.00 reconn/s: 0.00
24 [ 110s ] thds: 50 tps: 10.00 qps: 200.01 (r/w/o: 140.00/27.40/32.60) lat (ms,95%): 5709.50 err/s: 0.00 reconn/s: 0.00
25 [ 120s ] thds: 50 tps: 10.60 qps: 210.17 (r/w/o: 148.38/25.60/36.19) lat (ms,95%): 8184.67 err/s: 0.00 reconn/s: 0.00
26 [ 130s ] thds: 50 tps: 11.50 qps: 223.73 (r/w/o: 159.42/24.70/39.61) lat (ms,95%): 7895.16 err/s: 0.00 reconn/s: 0.00
27 [ 140s ] thds: 50 tps: 11.90 qps: 242.60 (r/w/o: 168.03/31.09/43.48) lat (ms,95%): 4943.53 err/s: 0.00 reconn/s: 0.00
28 [ 150s ] thds: 50 tps: 9.10 qps: 185.45 (r/w/o: 127.53/26.21/31.71) lat (ms,95%): 4517.90 err/s: 0.00 reconn/s: 0.00
29 [ 160s ] thds: 50 tps: 14.50 qps: 253.44 (r/w/o: 179.83/27.70/45.91) lat (ms,95%): 8184.67 err/s: 0.00 reconn/s: 0.00
30 [ 170s ] thds: 50 tps: 8.40 qps: 203.91 (r/w/o: 140.80/28.10/35.00) lat (ms,95%): 4943.53 err/s: 0.00 reconn/s: 0.00
31 [ 180s ] thds: 50 tps: 13.90 qps: 261.61 (r/w/o: 187.64/28.89/45.08) lat (ms,95%): 7754.26 err/s: 0.00 reconn/s: 0.00
32 [ 190s ] thds: 50 tps: 10.50 qps: 226.94 (r/w/o: 153.93/35.31/37.71) lat (ms,95%): 7754.26 err/s: 0.00 reconn/s: 0.00
33 [ 200s ] thds: 50 tps: 12.00 qps: 218.73 (r/w/o: 153.52/25.30/39.91) lat (ms,95%): 4203.93 err/s: 0.00 reconn/s: 0.00
34 [ 210s ] thds: 50 tps: 11.80 qps: 249.64 (r/w/o: 177.76/29.89/41.99) lat (ms,95%): 5607.61 err/s: 0.00 reconn/s: 0.00
35 [ 220s ] thds: 50 tps: 12.69 qps: 256.80 (r/w/o: 178.93/30.99/46.88) lat (ms,95%): 4517.90 err/s: 0.00 reconn/s: 0.00
36 [ 230s ] thds: 50 tps: 14.01 qps: 253.05 (r/w/o: 180.41/27.62/45.03) lat (ms,95%): 5709.50 err/s: 0.00 reconn/s: 0.00
37 [ 240s ] thds: 50 tps: 9.20 qps: 211.70 (r/w/o: 145.10/31.10/35.50) lat (ms,95%): 5507.54 err/s: 0.00 reconn/s: 0.00
38 [ 250s ] thds: 50 tps: 14.10 qps: 259.32 (r/w/o: 186.52/29.30/43.50) lat (ms,95%): 7086.63 err/s: 0.00 reconn/s: 0.00
39 [ 260s ] thds: 50 tps: 9.20 qps: 210.87 (r/w/o: 139.78/35.00/36.10) lat (ms,95%): 8038.61 err/s: 0.00 reconn/s: 0.00
40 [ 270s ] thds: 50 tps: 11.20 qps: 222.78 (r/w/o: 156.79/27.50/38.50) lat (ms,95%): 6026.41 err/s: 0.00 reconn/s: 0.00
41 [ 280s ] thds: 50 tps: 11.50 qps: 230.55 (r/w/o: 160.73/31.31/38.51) lat (ms,95%): 7615.89 err/s: 0.00 reconn/s: 0.00
42 [ 290s ] thds: 50 tps: 12.80 qps: 255.18 (r/w/o: 179.29/30.90/45.00) lat (ms,95%): 7086.63 err/s: 0.00 reconn/s: 0.00
43 [ 300s ] thds: 50 tps: 12.90 qps: 237.20 (r/w/o: 171.00/24.80/41.40) lat (ms,95%): 6247.39 err/s: 0.00 reconn/s: 0.00
44 SQL statistics:
45     queries performed:
46         read:                            46186
47         write:                           8348
48         other:                           11446
49         total:                           65980
50     transactions:                        3299   (10.93 per sec.)
51     queries:                             65980  (218.52 per sec.)
52     ignored errors:                      0      (0.00 per sec.)
53     reconnects:                          0      (0.00 per sec.)
54 
55 General statistics:
56     total time:                          301.9413s
57     total number of events:              3299
58 
59 Latency (ms):
60          min:                                  975.37
61          avg:                                 4575.91
62          max:                                13565.48
63          95th percentile:                     7479.98
64          sum:                             15095927.24
65 
66 Threads fairness:
67     events (avg/stddev):           65.9800/1.97
68     execution time (avg/stddev):   301.9185/0.01

pxc的  qtp才为11 (虚拟机,3节点在一个磁盘上)