您好,登錄后才能下訂單哦!
需求 、解決問題點(diǎn):
1:現(xiàn)有的mysql數(shù)據(jù)主從模式,數(shù)據(jù)同步延遲;
2:mysql主從進(jìn)程經(jīng)常崩潰,數(shù)據(jù)找平困難;
3:數(shù)據(jù)庫主從或者主主模式數(shù)據(jù)查詢、寫入慢;
4:mariadb或者mysql數(shù)據(jù)庫 節(jié)點(diǎn)性能需要指數(shù)級提升;
5:mariadb或者mysql數(shù)據(jù)庫對數(shù)據(jù)安全性有較高的要求;
6:項(xiàng)目要求數(shù)據(jù)庫有橫向擴(kuò)展的能力;
7 :等等。。。。。。
一、MariaDB Galera Cluster概要:
1.簡述:
MariaDB Galera Cluster 是一套在mysql innodb存儲引擎上面實(shí)現(xiàn)multi-master及數(shù)據(jù)實(shí)時(shí)同步的系統(tǒng)架構(gòu),業(yè)務(wù)層面無需做讀寫分離工作,數(shù)據(jù)庫讀寫壓力都能按照既定的規(guī)則分發(fā)到各個(gè)節(jié)點(diǎn)上去。在數(shù)據(jù)方面完全兼容 MariaDB 和 MySQL。
2.特性:
(1).同步復(fù)制 Synchronous replication
(2).Active-active multi-master 拓?fù)溥壿?/p>
(3).可對集群中任一節(jié)點(diǎn)進(jìn)行數(shù)據(jù)讀寫
(4).自動成員控制,故障節(jié)點(diǎn)自動從集群中移除
(5).自動節(jié)點(diǎn)加入
(6).真正并行的復(fù)制,基于行級
(7).直接客戶端連接,原生的 MySQL 接口
(8).每個(gè)節(jié)點(diǎn)都包含完整的數(shù)據(jù)副本
(9).多臺數(shù)據(jù)庫中數(shù)據(jù)同步由 wsrep 接口實(shí)現(xiàn)
3.局限性
(1).目前的復(fù)制僅僅支持InnoDB存儲引擎,任何寫入其他引擎的表,包括mysql.*表將不會復(fù)制,但是DDL語句會被復(fù)制的,因此創(chuàng)建用戶將會被復(fù)制,但是insert into mysql.user…將不會被復(fù)制的.
(2).DELETE操作不支持沒有主鍵的表,沒有主鍵的表在不同的節(jié)點(diǎn)順序?qū)⒉煌?如果執(zhí)行SELECT…LIMIT… 將出現(xiàn)不同的結(jié)果集.
(3).在多主環(huán)境下LOCK/UNLOCK TABLES不支持,以及鎖函數(shù)GET_LOCK(), RELEASE_LOCK()…
(4).查詢?nèi)罩静荒鼙4嬖诒碇小H绻_啟查詢?nèi)罩?,只能保存到文件中?/p>
(5).允許最大的事務(wù)大小由wsrep_max_ws_rows和wsrep_max_ws_size定義。任何大型操作將被拒絕。如大型的LOAD DATA操作。
(6).由于集群是樂觀的并發(fā)控制,事務(wù)commit可能在該階段中止。如果有兩個(gè)事務(wù)向在集群中不同的節(jié)點(diǎn)向同一行寫入并提交,失敗的節(jié)點(diǎn)將中止。對 于集群級別的中止,集群返回死鎖錯(cuò)誤代碼(Error: 1213 SQLSTATE: 40001 (ER_LOCK_DEADLOCK)).
(7).XA事務(wù)不支持,由于在提交上可能回滾。
(8).整個(gè)集群的寫入吞吐量是由最弱的節(jié)點(diǎn)限制,如果有一個(gè)節(jié)點(diǎn)變得緩慢,那么整個(gè)集群將是緩慢的。為了穩(wěn)定的高性能要求,所有的節(jié)點(diǎn)應(yīng)使用統(tǒng)一的硬件。
(9).集群節(jié)點(diǎn)建議最少3個(gè)。
(10).如果DDL語句有問題將破壞集群。
二:安裝、配置
1:安裝系統(tǒng)、內(nèi)核版本
[root@galeradbnode-6-11 ~]#
more /etc/redhat-release
CentOS Linux release 7.2.1511 (Core)
[root@galeradbnode-6-11 ~]#
uname -a
Linux galeradbnode-6-11 3.10.0-327.18.2.el7.x86_64 #1 SMP Thu May 12 11:03:55 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux
mysqld 10.1.14-MariaDB
2:節(jié)點(diǎn)信息如下:
安裝集群至少需要3個(gè)節(jié)點(diǎn)
galeradbnode-6-11
galeradbnode-6-12
galeradbnode-6-13
3:各節(jié)點(diǎn)配置yum源:
cat >/etc/yum.repos.d/mariadb.repo<<-EOF
[mariadb]
name = MariaDB
baseurl = http://yum.mariadb.org/10.1/centos7-amd64
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1
EOF
安裝注意事項(xiàng):
清理
/usr/bin/mysql*
/usr/sbin/mysql*
# 確認(rèn)本機(jī)防火墻上開放了所需TCP 3306和TCP 4567的端口
iptables -A INPUT -i eth0 -p tcp --dport 3306 -j ACCEPT
iptables -A INPUT -i eth0 -p tcp --dport 4567 -j ACCEPT
簡單配置:
galeradbnode-6-12:172.16.6.12
安裝mariadb:
yum -y install mariadb-server
##########如果需要修改數(shù)據(jù)目錄執(zhí)行下面操作#############
修改啟動文件中數(shù)據(jù)存儲目錄
#vim /etc/init.d/mysql
basedir=/usr
datadir=/data/3306/data
創(chuàng)建數(shù)據(jù)目錄
mkdir -p /data/3306/data
mkdir -p /var/lib/mysql/
修改權(quán)限
chown -R mysql.mysql /data/3306/data
chown -R mysql.mysql /var/lib/mysql/
#舊環(huán)境需要先刪除舊文件
rm -rf /var/lib/mysql/*
#初始化mysql 服務(wù)
mysql_install_db --user=mysql
默認(rèn)安裝不用此選項(xiàng)
--datadir=/data/3306/data/
##############################################
安全配置、創(chuàng)建root密碼,刪除test庫等:
mysql_secure_installation
創(chuàng)建集群連接賬戶密碼
MariaDB [(none)]> grant all on *.* to dbclusteruser@'172.16.6.%' identified by 'galerapassword';
關(guān)閉數(shù)據(jù)庫:
/etc/init.d/mysql stop mysql
修改配置文件
############################以下為配置文件####################################
[root@galeradbnode-6-12 ~]# more /etc/my.cnf.d/server.cnf
#
[client]
user = root
password = dbpassword
port = 13306
# These groups are read by MariaDB server.
# Use it for options that only the server (but not clients) should see
#
# See the examples of server my.cnf files in /usr/share/mysql/
#
# this is read by the standalone daemon and embedded servers
[server]
# this is only for the mysqld standalone daemon
[mysqld]
user = mysql
port = 13306
#
# * Galera-related settings
#
[galera]
wsrep_on=ON
wsrep_provider=/usr/lib64/galera/libgalera_smm.so
wsrep_cluster_address="gcomm://172.16.6.12,172.16.6.13"
wsrep_cluster_name=PTDBCluster
wsrep_node_name = galeradbnode-6-12
wsrep_node_address=172.16.6.12
binlog_format=row
default_storage_engine=InnoDB
innodb_autoinc_lock_mode=2
wsrep_slave_threads=10
innodb_flush_log_at_trx_commit=2
innodb_buffer_pool_size=122M
wsrep_sst_method=rsync
wsrep_sst_auth = dbclusteruser:galerapassword
[embedded]
# This group is only read by MariaDB servers, not by MySQL.
# If you use the same .cnf file for MySQL and MariaDB,
# you can put MariaDB-only options here
[mariadb]
# This group is only read by MariaDB-10.1 servers.
# If you use the same .cnf file for MariaDB of different versions,
# use this group for options that older servers don't understand
[mariadb-10.1]
############################以上為配置文件####################################
啟動節(jié)點(diǎn)1,初始化集群:galeradbnode-6-12
/etc/init.d/mysql start --wsrep-new-cluster
驗(yàn)證集群數(shù)量
MariaDB [(none)]> SHOW STATUS LIKE 'wsrep_cluster_size';
+--------------------+-------+
| Variable_name | Value |
+--------------------+-------+
| wsrep_cluster_size | 1 |
+--------------------+-------+
1 row in set (0.00 sec)
其它節(jié)點(diǎn)安裝部署
1:初始化mariadb 數(shù)據(jù)庫;
2:copy galeradbnode-6-12 配置文件;
[galera]
wsrep_on=ON
wsrep_provider=/usr/lib64/galera/libgalera_smm.so
wsrep_cluster_address="gcomm://172.16.6.12,172.16.6.13"
wsrep_cluster_name=PTDBCluster
wsrep_node_name = galeradbnode-6-12 《==修改為本機(jī)主機(jī)名
wsrep_node_address=172.16.6.12 《==修改為本機(jī)IP地址
binlog_format=row
default_storage_engine=InnoDB
innodb_autoinc_lock_mode=2
wsrep_slave_threads=10
innodb_flush_log_at_trx_commit=2
innodb_buffer_pool_size=122M
wsrep_sst_method=rsync
wsrep_sst_auth = dbclusteruser:ptmind890iop
3:啟動數(shù)據(jù)庫
#/etc/init.d/mysql start
4:驗(yàn)證集群數(shù)量,每加入一臺機(jī)器,cluster 數(shù)量增加1個(gè);
MariaDB [(none)]> SHOW STATUS LIKE 'wsrep_cluster_size';
+--------------------+-------+
| Variable_name | Value |
+--------------------+-------+
| wsrep_cluster_size | 2 |
+--------------------+-------+
查詢集群詳細(xì)配置信息命令如下:
MariaDB [(none)]> show status like 'wsrep_%';
+------------------------------+--------------------------------------+
| Variable_name | Value |
+------------------------------+--------------------------------------+
| wsrep_apply_oooe | 0.000000 |
| wsrep_apply_oool | 0.000000 |
| wsrep_apply_window | 0.000000 |
| wsrep_causal_reads | 0 |
| wsrep_cert_deps_distance | 0.000000 |
| wsrep_cert_index_size | 0 |
| wsrep_cert_interval | 0.000000 |
| wsrep_cluster_conf_id | 2 |
| wsrep_cluster_size | 2 |
| wsrep_cluster_state_uuid | 32725a2c-1be7-11e6-b6f0-87e13f10c1dd |
| wsrep_cluster_status | Primary |
| wsrep_commit_oooe | 0.000000 |
| wsrep_commit_oool | 0.000000 |
| wsrep_commit_window | 0.000000 |
| wsrep_connected | ON |
| wsrep_evs_delayed | |
| wsrep_evs_evict_list | |
| wsrep_evs_repl_latency | 0/0/0/0/0 |
| wsrep_evs_state | OPERATIONAL |
| wsrep_flow_control_paused | 0.000000 |
| wsrep_flow_control_paused_ns | 0 |
| wsrep_flow_control_recv | 0 |
| wsrep_flow_control_sent | 0 |
| wsrep_gcomm_uuid | a38ee701-1be9-11e6-a73b-3357c886f499 |
| wsrep_incoming_addresses | 172.16.6.22:3306,172.16.6.21:3306 |
| wsrep_last_committed | 4 |
| wsrep_local_bf_aborts | 0 |
| wsrep_local_cached_downto | 18446744073709551615 |
| wsrep_local_cert_failures | 0 |
| wsrep_local_commits | 0 |
| wsrep_local_index | 1 |
| wsrep_local_recv_queue | 0 |
| wsrep_local_recv_queue_avg | 0.000000 |
| wsrep_local_recv_queue_max | 1 |
| wsrep_local_recv_queue_min | 0 |
| wsrep_local_replays | 0 |
| wsrep_local_send_queue | 0 |
| wsrep_local_send_queue_avg | 0.000000 |
| wsrep_local_send_queue_max | 1 |
| wsrep_local_send_queue_min | 0 |
| wsrep_local_state | 4 |
| wsrep_local_state_comment | Synced |
| wsrep_local_state_uuid | 32725a2c-1be7-11e6-b6f0-87e13f10c1dd |
| wsrep_protocol_version | 7 |
| wsrep_provider_name | Galera |
| wsrep_provider_vendor | Codership Oy <info@codership.com> |
| wsrep_provider_version | 25.3.15(r3578) |
| wsrep_ready | ON |
| wsrep_received | 6 |
| wsrep_received_bytes | 415 |
| wsrep_repl_data_bytes | 0 |
| wsrep_repl_keys | 0 |
| wsrep_repl_keys_bytes | 0 |
| wsrep_repl_other_bytes | 0 |
| wsrep_replicated | 0 |
| wsrep_replicated_bytes | 0 |
| wsrep_thread_count | 5 |
+------------------------------+--------------------------------------+
wsrep_connected = on 鏈接已開啟
wsrep_cluster_size =3 集群中節(jié)點(diǎn)的數(shù)量
wsrep_incoming_addresses = 172.16.6.12:13306,172.16.6.13:13306 集群中節(jié)點(diǎn)的訪問地址
監(jiān)控狀態(tài)參數(shù)說明:
集群完整性檢查:
wsrep_cluster_state_uuid:在集群所有節(jié)點(diǎn)的值應(yīng)該是相同的,有不同值的節(jié)點(diǎn),說明其沒有連接入集群.
wsrep_cluster_conf_id:正常情況下所有節(jié)點(diǎn)上該值是一樣的.如果值不同,說明該節(jié)點(diǎn)被臨時(shí)"分區(qū)"了.當(dāng)節(jié)點(diǎn)之間網(wǎng)絡(luò)連接恢復(fù)的時(shí)候應(yīng)該會恢復(fù)一樣的值.
wsrep_cluster_size:如果這個(gè)值跟預(yù)期的節(jié)點(diǎn)數(shù)一致,則所有的集群節(jié)點(diǎn)已經(jīng)連接.
wsrep_cluster_status:集群組成的狀態(tài).如果不為"Primary",說明出現(xiàn)"分區(qū)"或是"split-brain"狀況.
節(jié)點(diǎn)狀態(tài)檢查:
wsrep_ready: 該值為ON,則說明可以接受SQL負(fù)載.如果為Off,則需要檢查wsrep_connected.
wsrep_connected: 如果該值為Off,且wsrep_ready的值也為Off,則說明該節(jié)點(diǎn)沒有連接到集群.(可能是wsrep_cluster_address或wsrep_cluster_name等配置錯(cuò)造成的.具體錯(cuò)誤需要查看錯(cuò)誤日志)
wsrep_local_state_comment:如果wsrep_connected為On,但wsrep_ready為OFF,則可以從該項(xiàng)查看原因.
復(fù)制健康檢查:
wsrep_flow_control_paused:表示復(fù)制停止了多長時(shí)間.即表明集群因?yàn)镾lave延遲而慢的程度.值為0~1,越靠近0越好,值為1表示復(fù)制完全停止.可優(yōu)化wsrep_slave_threads的值來改善.
wsrep_cert_deps_distance:有多少事務(wù)可以并行應(yīng)用處理.wsrep_slave_threads設(shè)置的值不應(yīng)該高出該值太多.
wsrep_flow_control_sent:表示該節(jié)點(diǎn)已經(jīng)停止復(fù)制了多少次.
wsrep_local_recv_queue_avg:表示slave事務(wù)隊(duì)列的平均長度.slave瓶頸的預(yù)兆.
最慢的節(jié)點(diǎn)的wsrep_flow_control_sent和wsrep_local_recv_queue_avg這兩個(gè)值最高.這兩個(gè)值較低的話,相對更好.
檢測慢網(wǎng)絡(luò)問題:
wsrep_local_send_queue_avg:網(wǎng)絡(luò)瓶頸的預(yù)兆.如果這個(gè)值比較高的話,可能存在網(wǎng)絡(luò)瓶
沖突或死鎖的數(shù)目:
wsrep_last_committed:最后提交的事務(wù)數(shù)目
wsrep_local_cert_failures和wsrep_local_bf_aborts:回滾,檢測到的沖突數(shù)目
MySQL Galera監(jiān)控
查看MySQL版本: mysql>
SHOW GLOBAL VARIABLES LIKE 'version';
查看wsrep版本: mysql>
SHOW GLOBAL STATUS LIKE 'wsrep_provider_version';
查看wsrep有關(guān)的所有變量: mysql>
HOW VARIABLES LIKE 'wsrep%' \G
查看Galera集群狀態(tài): mysql>
show status like 'wsrep%';
其他相關(guān)
1.Galera Cluster部署的前置檢查
在要轉(zhuǎn)成Galera Cluster的數(shù)據(jù)庫上執(zhí)行如下SQL語句:
SELECT DISTINCT
CONCAT(t.table_schema,'.',t.table_name) as tbl,
t.engine,
IF(ISNULL(c.constraint_name),'NOPK','') AS nopk,
IF(s.index_type = 'FULLTEXT','FULLTEXT','') as ftidx,
IF(s.index_type = 'SPATIAL','SPATIAL','') as gisidx
FROM information_schema.tables AS t
LEFT JOIN information_schema.key_column_usage AS c
ON (t.table_schema = c.constraint_schema AND t.table_name = c.table_name
AND c.constraint_name = 'PRIMARY')
LEFT JOIN information_schema.statistics AS s
ON (t.table_schema = s.table_schema AND t.table_name = s.table_name
AND s.index_type IN ('FULLTEXT','SPATIAL'))
WHERE t.table_schema NOT IN ('information_schema','performance_schema','mysql')
AND t.table_type = 'BASE TABLE'
AND (t.engine <> 'InnoDB' OR c.constraint_name IS NULL OR s.index_type IN ('FULLTEXT','SPATIAL'))
ORDER BY t.table_schema,t.table_name;
上述SQL檢索數(shù)據(jù)庫,輸出不符合使用Galera的表的信息,對應(yīng)的5個(gè)字段順序?yàn)椋罕恚硪?,是否無主鍵,是否有全文索引,是否有空間索引。
找到不符合的原因,對應(yīng)修改即可。
配置高可用轉(zhuǎn)發(fā),集群升級到mmmnnn 模式
nginx配置如下:
upstream galera {
hash $remote_addr consistent;
server 172.16.6.11:13306; #galera集群節(jié)點(diǎn)服務(wù)器
server 172.16.6.12:13306;
server 172.16.6.13:13306;
}
server {
listen 23306; #nginx 監(jiān)聽端口
proxy_pass galera;
}
登陸數(shù)據(jù)庫:
mysql -h nginx轉(zhuǎn)發(fā)服務(wù)器IP -u dbuser -pdbpassword-P23306
參考文檔:
http://www.linuxidc.com/Linux/2016-01/127256.htm
http://blog.sina.com.cn/s/blog_704836f40101lixp.html
http://www.open-open.com/lib/view/open1435888783513.html
http://www.open-open.com/lib/view/open1418521886917.html
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。