日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > 数据库 >内容正文

数据库

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

發布時間:2025/3/20 数据库 53 豆豆
生活随笔 收集整理的這篇文章主要介紹了 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數據場景的數據保存問題,即不能實現分庫分表,但是提供了一個高冗余的環境,適合于業務不是很大但是要求數據絕對安全的環境。

Percona XtraDBCluster提供的特性有:

1.同步復制,事務要么在所有節點提交或不提交。 2.多主復制,可以在任意節點進行寫操作。 3.在從服務器上并行應用事件,真正意義上的并行復制。 4.節點自動配置。 5.數據一致性,不再是異步復制。

?

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

一、環境說明

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-24-2.4.7-1.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 = 3306 server_id = 12 socket = /data/mysql/mysql.sock pid-file = /data/mysql/logs/mysql.pid log-error = /data/mysql/logs/error.log log_warnings = 2 slow_query_log_file = /data/mysql/logs/slow.log long_query_time = 0.1sql_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= 8wsrep_log_conflicts# This changes how InnoDB autoincrement locks are managed and is a requirement for Galera innodb_autoinc_lock_mode=2# 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 = 3306 server_id = 13 socket = /data/mysql/mysql.sock pid-file = /data/mysql/logs/mysql.pid log-error = /data/mysql/logs/error.log log_warnings = 2 slow_query_log_file = /data/mysql/logs/slow.log long_query_time = 0.1sql_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= 8wsrep_log_conflicts# This changes how InnoDB autoincrement locks are managed and is a requirement for Galera innodb_autoinc_lock_mode=2# 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 = 3306 server_id = 198 socket = /data/mysql/mysql.sock pid-file = /data/mysql/logs/mysql.pid log-error = /data/mysql/logs/error.log log_warnings = 2 slow_query_log_file = /data/mysql/logs/slow.log long_query_time = 0.1sql_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= 8wsrep_log_conflicts# This changes how InnoDB autoincrement locks are managed and is a requirement for Galera innodb_autoinc_lock_mode=2# 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 27910 1 0 10:21 pts/2 00:00:00 /bin/sh /usr/bin/mysqld_safe --datadir=/data/mysql/data --pid-file=/data/mysql/logs/mysql.pid --wsrep-new-cluster mysql 28347 27910 22 10:21 pts/2 00:00:23 /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=3306 --wsrep_start_position=00000000-0000-0000-0000-000000000000:-1

?

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

查看錯誤日志信息

[root@master mysql]# tail -f logs/error.log2017-06-07T02:21:30.794514Z 0 [Note] WSREP: Node 04b5f0f9 state primary 2017-06-07T02:21:30.794674Z 0 [Note] WSREP: Current view of cluster as seen by this node view (view_id(PRIM,04b5f0f9,1) memb { 04b5f0f9,0 } joined { } left { } partitioned { } ) 2017-06-07T02:21:30.794745Z 0 [Note] WSREP: Save the discovered primary-component to disk 2017-06-07T02:21:30.794882Z 0 [Note] WSREP: discarding pending addr without UUID: tcp://192.168.3.12:4567 2017-06-07T02:21:30.794926Z 0 [Note] WSREP: discarding pending addr proto entry 0x7f16aefcfcc0 2017-06-07T02:21:30.794988Z 0 [Note] WSREP: discarding pending addr without UUID: tcp://192.168.3.13:4567 2017-06-07T02:21:30.795028Z 0 [Note] WSREP: discarding pending addr proto entry 0x7f16aefcff00 2017-06-07T02:21:30.795060Z 0 [Note] WSREP: discarding pending addr without UUID: tcp://192.168.3.198:4567 2017-06-07T02:21:30.795098Z 0 [Note] WSREP: discarding pending addr proto entry 0x7f16aefcffc0 2017-06-07T02:21:30.795158Z 0 [Note] WSREP: gcomm: connected 2017-06-07T02:21:30.795328Z 0 [Note] WSREP: Shifting CLOSED -> OPEN (TO: 0) 2017-06-07T02:21:30.797700Z 0 [Note] WSREP: Waiting for SST/IST to complete. 2017-06-07T02:21:31.391420Z 0 [Note] WSREP: New COMPONENT: primary = yes, bootstrap = no, my_idx = 0, memb_num = 1 2017-06-07T02:21:32.020639Z 0 [Note] WSREP: Starting new group from scratch: 05719dfe-4b28-11e7-a651-ab4ab48f9b60 2017-06-07T02:21:32.021473Z 0 [Note] WSREP: STATE_EXCHANGE: sent state UUID: 0571c6e9-4b28-11e7-b20d-5a8bf004e006 2017-06-07T02:21:32.021523Z 0 [Note] WSREP: STATE EXCHANGE: sent state msg: 0571c6e9-4b28-11e7-b20d-5a8bf004e006 2017-06-07T02:21:32.021547Z 0 [Note] WSREP: STATE EXCHANGE: got state msg: 0571c6e9-4b28-11e7-b20d-5a8bf004e006 from 0 (pxc01) 2017-06-07T02:21:32.021571Z 0 [Note] WSREP: Quorum results: version = 4, component = PRIMARY, conf_id = 0, members = 1/1 (primary/total), act_id = 0, last_appl. = -1, protocols = 0/7/3 (gcs/repl/appl), group UUID = 05719dfe-4b28-11e7-a651-ab4ab48f9b60 2017-06-07T02:21:32.021599Z 0 [Note] WSREP: Flow-control interval: [100, 100] 2017-06-07T02:21:32.021615Z 0 [Note] WSREP: Restored state OPEN -> JOINED (0) 2017-06-07T02:21:32.021976Z 0 [Note] WSREP: Member 0.0 (pxc01) synced with group. 2017-06-07T02:21:32.022019Z 0 [Note] WSREP: Shifting JOINED -> SYNCED (TO: 0) 2017-06-07T02:21:32.022101Z 2 [Note] WSREP: New cluster view: global state: 05719dfe-4b28-11e7-a651-ab4ab48f9b60:0, view# 1: Primary, number of nodes: 1, my index: 0, protocol version 3 2017-06-07T02:21:32.023374Z 0 [Note] WSREP: SST complete, seqno: 0 2017-06-07T02:21:32.535748Z 0 [Note] InnoDB: PUNCH HOLE support available 2017-06-07T02:21:32.535815Z 0 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins 2017-06-07T02:21:32.535826Z 0 [Note] InnoDB: Uses event mutexes 2017-06-07T02:21:32.535832Z 0 [Note] InnoDB: GCC builtin __sync_synchronize() is used for memory barrier 2017-06-07T02:21:32.535837Z 0 [Note] InnoDB: Compressed tables use zlib 1.2.3 2017-06-07T02:21:32.535842Z 0 [Note] InnoDB: Using Linux native AIO 2017-06-07T02:21:32.536865Z 0 [Note] InnoDB: Number of pools: 1 2017-06-07T02:21:32.536999Z 0 [Note] InnoDB: Using CPU crc32 instructions 2017-06-07T02:21:33.194918Z 0 [Note] InnoDB: Initializing buffer pool, total size = 1G, instances = 8, chunk size = 128M 2017-06-07T02:21:41.225447Z 0 [Note] InnoDB: Completed initialization of buffer pool 2017-06-07T02:21:45.228192Z 0 [Note] InnoDB: If the mysqld execution user is authorized, page cleaner thread priority can be changed. See the man page of setpriority(). 2017-06-07T02:21:45.554968Z 0 [Note] InnoDB: Crash recovery did not find the parallel doublewrite buffer at /data/mysql/data/xb_doublewrite 2017-06-07T02:21:45.556158Z 0 [Note] InnoDB: Highest supported file format is Barracuda. 2017-06-07T02:21:47.397187Z 0 [Note] InnoDB: Created parallel doublewrite buffer at /data/mysql/data/xb_doublewrite, size 31457280 bytes 2017-06-07T02:21:47.700377Z 0 [Note] InnoDB: Creating shared tablespace for temporary tables 2017-06-07T02:21:47.700541Z 0 [Note] InnoDB: Setting file './ibtmp1' size to 12 MB. Physically writing the file full; Please wait ... 2017-06-07T02:21:48.413452Z 0 [Note] InnoDB: File './ibtmp1' size is now 12 MB. 2017-06-07T02:21:48.414626Z 0 [Note] InnoDB: 96 redo rollback segment(s) found. 96 redo rollback segment(s) are active. 2017-06-07T02:21:48.414664Z 0 [Note] InnoDB: 32 non-redo rollback segment(s) are active. 2017-06-07T02:21:48.416853Z 0 [Note] InnoDB: Waiting for purge to start 2017-06-07T02:21:48.468115Z 0 [Note] InnoDB: Percona XtraDB (http://www.percona.com) 5.7.18-15 started; log sequence number 2542677 2017-06-07T02:21:48.468456Z 0 [Note] Plugin 'FEDERATED' is disabled. 2017-06-07T02:21:48.468710Z 0 [Note] InnoDB: Loading buffer pool(s) from /data/mysql/data/ib_buffer_pool 2017-06-07T02:21:48.472685Z 0 [Note] InnoDB: Buffer pool(s) load completed at 170607 10:21:48 2017-06-07T02:21:48.477798Z 0 [Note] Found ca.pem, server-cert.pem and server-key.pem in data directory. Trying to enable SSL support using them. 2017-06-07T02:21:48.477886Z 0 [Note] Skipping generation of SSL certificates as certificate files are present in data directory. 2017-06-07T02:21:48.515627Z 0 [Warning] CA certificate ca.pem is self signed. 2017-06-07T02:21:48.544887Z 0 [Note] Skipping generation of RSA key pair as key files are present in data directory. 2017-06-07T02:21:48.545210Z 0 [Note] Server hostname (bind-address): '*'; port: 3306 2017-06-07T02:21:48.545499Z 0 [Note] IPv6 is available. 2017-06-07T02:21:48.545557Z 0 [Note] - '::' resolves to '::'; 2017-06-07T02:21:48.545717Z 0 [Note] Server socket created on IP: '::'. 2017-06-07T02:21:48.611502Z 0 [Note] Event Scheduler: Loaded 0 events 2017-06-07T02:21:48.651338Z 2 [Note] WSREP: Initialized wsrep sidno 2 2017-06-07T02:21:48.651403Z 2 [Note] WSREP: wsrep_notify_cmd is not defined, skipping notification. 2017-06-07T02:21:48.651443Z 2 [Note] WSREP: REPL Protocols: 7 (3, 2) 2017-06-07T02:21:48.651455Z 2 [Note] WSREP: Assign initial position for certification: 0, protocol version: 3 2017-06-07T02:21:48.651862Z 0 [Note] WSREP: Service thread queue flushed. 2017-06-07T02:21:48.765979Z 0 [Note] /usr/sbin/mysqld: ready for connections. Version: '5.7.18-15-57' socket: '/data/mysql/mysql.sock' port: 3306 Percona XtraDB Cluster (GPL), Release rel15, Revision 7693d6e, WSREP version 29.20, wsrep_29.20 2017-06-07T02:21:48.766032Z 0 [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. 2017-06-07T02:21:48.766043Z 0 [Note] Beginning of list of non-natively partitioned tables 2017-06-07T02:21:48.766034Z 2 [Note] WSREP: GCache history reset: old(00000000-0000-0000-0000-000000000000:0) -> new(05719dfe-4b28-11e7-a651-ab4ab48f9b60:0) 2017-06-07T02:21:48.767985Z 2 [Note] WSREP: Synchronized with group, ready for connections 2017-06-07T02:21:48.768012Z 2 [Note] WSREP: wsrep_notify_cmd is not defined, skipping notification. 2017-06-07T02:21:48.824186Z 0 [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<7 mysql> alter user 'root'@'localhost' identified by '123456';

?

第一節點啟動后,檢查cluster的狀態。
當前第一節點是Primary。

mysql> show status like '%wsrep%'; +----------------------------------+--------------------------------------+ | Variable_name | Value | +----------------------------------+--------------------------------------+ | wsrep_local_state_uuid | 05719dfe-4b28-11e7-a651-ab4ab48f9b60 | | wsrep_protocol_version | 7 | | wsrep_last_committed | 1 | | wsrep_replicated | 1 | | wsrep_replicated_bytes | 230 | | wsrep_repl_keys | 1 | | wsrep_repl_keys_bytes | 31 | | wsrep_repl_data_bytes | 135 | | wsrep_repl_other_bytes | 0 | | wsrep_received | 2 | | wsrep_received_bytes | 141 | | 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 | 1 | | 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 | [ 100, 100 ] | | wsrep_flow_control_interval_low | 100 | | wsrep_flow_control_interval_high | 100 | | 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 | 4 | | wsrep_local_state_comment | Synced | | wsrep_cert_index_size | 1 | | wsrep_cert_bucket_count | 22 | | wsrep_gcache_pool_size | 1590 | | 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.3.12:3306 | | wsrep_desync_count | 0 | | wsrep_evs_delayed | | | wsrep_evs_evict_list | | | wsrep_evs_repl_latency | 1.8541e-05/1.8541e-05/1.8541e-05/0/1 | | wsrep_evs_state | OPERATIONAL | | wsrep_gcomm_uuid | 04b5f0f9-4b28-11e7-aff6-522901b34a55 | | wsrep_cluster_conf_id | 1 | | wsrep_cluster_size | 1 | | wsrep_cluster_state_uuid | 05719dfe-4b28-11e7-a651-ab4ab48f9b60 | | wsrep_cluster_status | Primary | | wsrep_connected | ON | | wsrep_local_bf_aborts | 0 | | wsrep_local_index | 0 | | 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 | 7 | | wsrep_last_committed | 4 | | wsrep_replicated | 4 | | wsrep_replicated_bytes | 950 | | wsrep_repl_keys | 4 | | wsrep_repl_keys_bytes | 124 | | wsrep_repl_data_bytes | 570 | | wsrep_repl_other_bytes | 0 | | wsrep_received | 6 | | wsrep_received_bytes | 423 | | 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 | 1 | | 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 | [ 141, 141 ] | | wsrep_flow_control_interval_low | 141 | | wsrep_flow_control_interval_high | 141 | | 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 | 4 | | wsrep_local_state_comment | Synced | | wsrep_cert_index_size | 1 | | wsrep_cert_bucket_count | 22 | | wsrep_gcache_pool_size | 2561 | | 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.3.12:3306,192.168.3.13: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 | 04b5f0f9-4b28-11e7-aff6-522901b34a55 | | wsrep_cluster_conf_id | 2 | | wsrep_cluster_size | 2 | | wsrep_cluster_state_uuid | 05719dfe-4b28-11e7-a651-ab4ab48f9b60 | | wsrep_cluster_status | Primary | | wsrep_connected | ON | | wsrep_local_bf_aborts | 0 | | wsrep_local_index | 0 | | 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 | 7 | | wsrep_last_committed | 4 | | 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 | 3 | | wsrep_received_bytes | 288 | | 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 | 1452 | | 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.3.12:3306,192.168.3.13:3306,192.168.3.198: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 | ca7f9f30-4b2b-11e7-a0b7-e29969825862 | | wsrep_cluster_conf_id | 3 | | wsrep_cluster_size | 3 | | wsrep_cluster_state_uuid | 05719dfe-4b28-11e7-a651-ab4ab48f9b60 | | 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.20(r7e383f7) | | wsrep_ready | ON | +----------------------------------+--------------------------------------------------------+

?


簡單測試:

在pxc03上創建數據庫tdoa,并在上面建表,且插入幾條數據

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

至此,PXC安裝啟動完畢。

轉載于:https://www.cnblogs.com/reblue520/p/6962599.html

總結

以上是生活随笔為你收集整理的MySQL高可用方案-PXC(Percona XtraDB Cluster)环境部署详解的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。