溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

PXC安裝文檔

發(fā)布時(shí)間:2020-10-04 08:37:12 來(lái)源:網(wǎng)絡(luò) 閱讀:7073 作者:李興周 欄目:MySQL數(shù)據(jù)庫(kù)

一 環(huán)境準(zhǔn)備

主機(jī)IP 主機(jī)名 操作系統(tǒng) PXC版本
192.168.39.135 node1 CentOS 6.8 Percona-XtraDB-Cluster-57-5.7.21
192.168.39.226 node2 CentOS 6.8 Percona-XtraDB-Cluster-57-5.7.21
192.168.39.227 node3 CentOS 6.8 Percona-XtraDB-Cluster-57-5.7.21

【PXC的數(shù)據(jù)同步流程】
PXC安裝文檔

client端向server端發(fā)送dml更新操作請(qǐng)求時(shí),server的native本地進(jìn)程處理請(qǐng)求,并返回OK準(zhǔn)備接收,client發(fā)送commit更新事務(wù)給server,server將replicate writeset復(fù)制寫(xiě)數(shù)據(jù)集發(fā)給group(cluster集群),cluster將該數(shù)據(jù)集對(duì)應(yīng)產(chǎn)生的唯一的GTID(global transaction ID)發(fā)送給集群每個(gè)server(節(jié)點(diǎn))。當(dāng)前server節(jié)點(diǎn)驗(yàn)證通過(guò)后,執(zhí)行commit_cd動(dòng)作更新本地?cái)?shù)據(jù)庫(kù),并返回OK;若其他節(jié)點(diǎn)驗(yàn)證不通過(guò),則執(zhí)行rollback_cd,回滾剛提交的事務(wù)。其他server(other server)接收并驗(yàn)證通過(guò)后,執(zhí)行apply_cd和commit_cd動(dòng)作更新本地?cái)?shù)據(jù)庫(kù);若驗(yàn)證不通過(guò),則丟棄該數(shù)據(jù)集。

任意節(jié)點(diǎn)收到sql請(qǐng)求,對(duì)于dml更新操作事務(wù),在commit之前,由wsrep API調(diào)用galera庫(kù)進(jìn)行集群內(nèi)部廣播,驗(yàn)證當(dāng)前事務(wù)是否能在所有節(jié)點(diǎn)中執(zhí)行,驗(yàn)證通過(guò)后該事務(wù)真正提交到集群所有節(jié)點(diǎn)執(zhí)行,反之roll back回滾。

【節(jié)點(diǎn)加入后狀態(tài)轉(zhuǎn)變過(guò)程】
PXC安裝文檔

1 OPEN       節(jié)點(diǎn)啟動(dòng)成功,嘗試連接到集群,如果失敗則根據(jù)配置退出或創(chuàng)建新的集群
2 PRIMARY 節(jié)點(diǎn)已處于集群中,在新節(jié)點(diǎn)加入時(shí),選取donor進(jìn)行數(shù)據(jù)同步時(shí)會(huì)產(chǎn)生的狀態(tài)
3 JOINER    節(jié)點(diǎn)處于等待接收/接收同步文件時(shí)的狀態(tài)
4 JOINED    節(jié)點(diǎn)完成數(shù)據(jù)同步,但有部分?jǐn)?shù)據(jù)沒(méi)跟上,在嘗試保持和集群進(jìn)度一致的過(guò)程狀態(tài)
例如某個(gè)節(jié)點(diǎn)故障后,重新加入集群,在追趕集群進(jìn)度時(shí)的狀態(tài)
5 SYNCED  節(jié)點(diǎn)正常提供服務(wù)的狀態(tài),表示已經(jīng)同步完成并和集群進(jìn)度保持一致。
6 DONOR    節(jié)點(diǎn)處于為新節(jié)點(diǎn)提供全量數(shù)據(jù)數(shù)據(jù)同步時(shí)的狀態(tài)。此時(shí)該節(jié)點(diǎn)對(duì)客戶端不提供服務(wù)。

二 下載PXC

安裝yum源

yum install http://www.percona.com/downloads/percona-release/redhat/0.1-4/percona-release-0.1-4.noarch.rpm
這樣會(huì)在/etc/yum.repos.d下生成percona-release.repo文件

先下載安裝兩個(gè)PXC的依賴包
wget http://dl.fedoraproject.org/pub/epel/6/x86_64/Packages/l/libev-4.03-3.el6.x86_64.rpm
wget http://dl.fedoraproject.org/pub/epel/6/x86_64/Packages/s/socat-1.7.2.3-1.el6.x86_64.rpm
yum localinstall libev-4.03-3.el6.x86_64
yum localinstall socat-1.7.2.3-1.el6.x86_64

安裝PXC

yum install Percona-XtraDB-Cluster-57

最終下載下來(lái)的版本是Percona-XtraDB-Cluster-57-5.7.21

注意:三個(gè)節(jié)點(diǎn)上均要安裝。

三 配置文件

node1節(jié)點(diǎn)配置:
[mysql]
prompt="\u@\h:\p [\d]>
#pager="less -i -n -S"
#tee=/home/mysql/query.log
no-auto-rehash

[mysqld]
user = mysql
datadir = /data/mysql/mysql9999/data

event_scheduler = 0

tmpdir=/data/mysql/mysql9999/tmp
#timeout
interactive_timeout = 300
wait_timeout = 300

#character set
character-set-server = utf8

open_files_limit = 65535
max_connections = 100
max_connect_errors = 100000

explicit_defaults_for_timestamp
#logs
log-output=file
slow_query_log = 1
slow_query_log_file = slow.log
log-error = error.log
log_warnings = 2
pid-file = mysql.pid
long_query_time = 1
#log-slow-admin-statements = 1
#log-queries-not-using-indexes = 1
log-slow-slave-statements = 1

#binlog
binlog_format = row
server-id = 63306
log-bin = /data/mysql/mysql9999/logs/mysql-bin
binlog_cache_size = 1M
max_binlog_size = 200M
max_binlog_cache_size = 2G
sync_binlog = 0
expire_logs_days = 10

#relay log
skip_slave_start = 1
max_relay_log_size = 500M
relay_log_purge = 1
relay_log_recovery = 1
log_slave_updates
#slave-skip-errors=1032,1053,1062

#buffers & cache
table_open_cache = 2048
table_definition_cache = 2048
table_open_cache = 2048
max_heap_table_size = 96M
sort_buffer_size = 2M
join_buffer_size = 2M
thread_cache_size = 256
query_cache_size = 0
query_cache_type = 0
query_cache_limit = 256K
query_cache_min_res_unit = 512
thread_stack = 192K
tmp_table_size = 96M
key_buffer_size = 8M
read_buffer_size = 2M
read_rnd_buffer_size = 16M
bulk_insert_buffer_size = 32M

#myisam
myisam_sort_buffer_size = 128M
myisam_max_sort_file_size = 10G
myisam_repair_threads = 1

#innodb
innodb_buffer_pool_size = 500M
innodb_buffer_pool_instances = 1
innodb_data_file_path = ibdata1:200M:autoextend
innodb_flush_log_at_trx_commit = 2
innodb_log_buffer_size = 64M
innodb_log_file_size = 256M
innodb_log_files_in_group = 3
innodb_max_dirty_pages_pct = 90
innodb_file_per_table = 1
innodb_rollback_on_timeout
innodb_status_file = 1
innodb_io_capacity = 2000
transaction_isolation = READ-COMMITTED
innodb_flush_method = O_DIRECT

#pxc
default_storage_engine=Innodb
innodb_locks_unsafe_for_binlog=1
innodb_autoinc_lock_mode=2

wsrep_cluster_name=pxc_lixingzhou
wsrep_cluster_address=gcomm://192.168.39.226,192.168.39.227,192.168.39.135
wsrep_node_address=192.168.39.226
wsrep_provider=/usr/lib64/libgalera_smm.so

wsrep_sst_method=xtrabackup-v2
wsrep_sst_auth=sst:lixingzhou


啟動(dòng)服務(wù):
/etc/init.d/mysql bootstrap-pxc 【bootstrap-pxc啟動(dòng)】

用默認(rèn)errorlog里面生成的默認(rèn)密碼登陸后,修改默認(rèn)生成的root賬戶密碼,否則做不了任何操作。
ALTER USER CURRENT_USER() IDENTIFIED BY '123456';
該參數(shù)是用于其它節(jié)點(diǎn)加入到該集群中,利用XtraBackup執(zhí)行State Snapshot Transfer(類似于全量同步)的。
配置文件中的下邊兩個(gè)參數(shù)相關(guān)
wsrep_sst_method=xtrabackup-v2
wsrep_sst_auth=sst:lixingzhou

CREATE USER 'sst'@'localhost' IDENTIFIED BY 'lixingzhou';
GRANT ALL ON . TO 'sst'@'localhost';
FLUSH PRIVILEGES;

node2,node3 的配置文件和node1基本一致,下邊標(biāo)出需要修改的地方:
server-id = xxxx
wsrep_node_address= xxxx

#配置完之后 啟動(dòng)node2 node3
/etc/init.d/mysql start

查看狀態(tài):

"root@localhost:mysql.sock  [(none)]>show global status like "wsrep%";`
+----------------------------------+-------------------------------------------------------------+
| Variable_name                    | Value                                                       |
+----------------------------------+-------------------------------------------------------------+
| wsrep_local_state_uuid           | cdcda068-49e0-11e8-9890-9a727072a76e                        |
顯示了cluster的state UUID,由此可看出節(jié)點(diǎn)是否還是集群的一員
| wsrep_protocol_version           | 8                                                           |
| wsrep_last_applied               | 97                                                          |
| wsrep_last_committed             | 97                                                          |
| wsrep_replicated                 | 9                                                           |
| wsrep_replicated_bytes           | 2536                                                        |
| wsrep_repl_keys                  | 25                                                          |
| wsrep_repl_keys_bytes            | 416                                                         |
| wsrep_repl_data_bytes            | 1516                                                        |
| wsrep_repl_other_bytes           | 0                                                           |
| wsrep_received                   | 146                                                         |
| wsrep_received_bytes             | 55802905                                                    |
| wsrep_local_commits              | 7                                                           |
| wsrep_local_cert_failures        | 0                                                           |
| wsrep_local_replays              | 0                                                           |
| wsrep_local_send_queue           | 0                                                           |
| wsrep_local_send_queue_max       | 2                                                           |
| wsrep_local_send_queue_min       | 0                                                           |
| wsrep_local_send_queue_avg       | 0.014925                                                    |
| wsrep_local_recv_queue           | 0                                                           |
| wsrep_local_recv_queue_max       | 21                                                          |
| wsrep_local_recv_queue_min       | 0                                                           |
| wsrep_local_recv_queue_avg       | 9.424658                                                    |
| wsrep_local_cached_downto        | 8                                                           |
| 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         | 7.102273                                                    |
| wsrep_apply_oooe                 | 0.034091                                                    |
| wsrep_apply_oool                 | 0.000000                                                    |
| wsrep_apply_window               | 1.034091                                                    |
| wsrep_commit_oooe                | 0.000000                                                    |
| wsrep_commit_oool                | 0.000000                                                    |
| wsrep_commit_window              | 1.034091                                                    |
| wsrep_local_state                | 4                                                           | 
表示正常監(jiān)聽(tīng)
| wsrep_local_state_comment        | Synced                                                      |
以人能讀懂的方式顯示節(jié)點(diǎn)的狀態(tài),正常的返回值是Joining, Waiting on SST
Joined, Synced or Donor,返回Initialized說(shuō)明已不在正常工作狀態(tài)
| wsrep_cert_index_size            | 3923                                                        |
| wsrep_cert_bucket_count          | 126282                                                      |
| wsrep_gcache_pool_size           | 55808488                                                    |
| wsrep_causal_reads               | 0                                                           |
| wsrep_cert_interval              | 0.090909                                                    |
| 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.39.227:3306,192.168.39.226:3306,192.168.39.135: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                 | ddeaa214-49e8-11e8-8ea0-6f78f28ce711                        |
| wsrep_cluster_conf_id            | 20                                                          |
顯示了整個(gè)集群的變化次數(shù)。所有節(jié)點(diǎn)都應(yīng)相同,否則說(shuō)明某個(gè)節(jié)點(diǎn)與集群斷開(kāi)了
| wsrep_cluster_size               | 3                                                           |
集群節(jié)點(diǎn)的數(shù)量
| wsrep_cluster_state_uuid         | cdcda068-49e0-11e8-9890-9a727072a76e                        |
| wsrep_cluster_status             | Primary                                                     |
表示是主節(jié)點(diǎn)可寫(xiě)入
| wsrep_connected                  | ON                                                          |
顯示該節(jié)點(diǎn)是否與其他節(jié)點(diǎn)有網(wǎng)絡(luò)連接。(實(shí)驗(yàn)得知,當(dāng)把某節(jié)點(diǎn)的網(wǎng)卡down掉之后,該值仍為on。
說(shuō)明網(wǎng)絡(luò)還在)丟失連接的問(wèn)題可能在于配置wsrep_cluster_address或wsrep_cluster_name的錯(cuò)誤
| 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           |
# wsrep_ready顯示了節(jié)點(diǎn)是否可以接受queries,如果是OFF幾乎所有的query都會(huì)報(bào)錯(cuò),報(bào)錯(cuò)信息
提示“ERROR 1047 (08501) Unknown Command”
+----------------------------------+-------------------------------------------------------------+

四 注意事項(xiàng)

1 selinux和火墻關(guān)閉
2 pxc 的局限,不支持表級(jí)鎖(lock table/unlock table 不支持),執(zhí)行alter table操作會(huì)鎖住整個(gè)集群??梢灾С植l(fā)寫(xiě)入,通過(guò)自增偏移量和自增步長(zhǎng)來(lái)控制,實(shí)現(xiàn)并發(fā)寫(xiě)入不沖突。但是update/delete 在網(wǎng)絡(luò)抖動(dòng)的情況下,會(huì)重新發(fā)送給集群的其他成員,存在各個(gè)成員都會(huì)本地native process 處理這個(gè)SQL, 然后發(fā)給集群 其他節(jié)點(diǎn),結(jié)果發(fā)現(xiàn)推過(guò)來(lái)的集合和我本地修改的集合內(nèi)容一樣,可能會(huì)報(bào)1213 錯(cuò)誤,導(dǎo)致事務(wù)ID不一 致。會(huì)使節(jié)點(diǎn)下線處理。所以盡量單節(jié)點(diǎn)寫(xiě)入。主要用它的數(shù)據(jù)一致性。
3 整個(gè)集群數(shù)最好為3個(gè)【官方推薦3個(gè)】,最多是8個(gè)。如果多了,節(jié)點(diǎn)之間的認(rèn)證,傳輸,就會(huì)量很大,影響性能。
4 writeSet最大不要超過(guò)16K
5 不支持XA事務(wù)
6 pxc結(jié)構(gòu)里面必須有主鍵,否則當(dāng)數(shù)據(jù)很稀疏的時(shí)候,data page里面存儲(chǔ)的數(shù)據(jù)可能會(huì)有差別。
例如:select * from t1 limit 10; 可能返回的結(jié)果會(huì)不一樣。

7 node能停多長(zhǎng)時(shí)間,可以傳IST,由gcache控制,到底分配多大合適呢?
wsrep_provider_options="gcache.size=1G",可以算一個(gè)小時(shí)的binlog量大概多大,2-3個(gè)小時(shí),2-4G即可。
如果機(jī)器關(guān)閉,緩存就會(huì)清空。

8假設(shè)我們?nèi)齻€(gè)節(jié)點(diǎn)都關(guān)閉了,會(huì)發(fā)起什么呢?
沒(méi)有做到最后關(guān)閉的節(jié)點(diǎn),最先啟動(dòng),發(fā)現(xiàn)GTID不一樣。就會(huì)全部傳SST。
建議滾動(dòng)關(guān)閉,node1 先閉,修復(fù)完畢加回來(lái)了,原則要保持Group里最少一個(gè)成員活著。數(shù)據(jù)庫(kù)關(guān)閉之后,最會(huì)保存一個(gè)last Txid。
9 集群的腦裂問(wèn)題?
發(fā)生腦裂后,拒絕對(duì)外服務(wù), 輸入任何命令都會(huì),unkown command。
火墻設(shè)置:iptables 禁止訪問(wèn) 4567 端口兩個(gè)連不通了。[模擬故障]
忽略上邊的腦裂設(shè)置:SET GLOBAL wsrep_provider_options="pc.ignore_sb=true";

向AI問(wèn)一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI