MMM
, MHA
, NDB Cluster
, Galera Cluster
, InnoDB Cluster
, 腾讯的PhxSQL
, MySQL Fabric
,aliSQL
。NDB
:基于集群的引擎-数据被自动切分并复制到数个机器上(数据节点), 适合于那些须要极高查询性能和高可用性的应用, 原来是为爱立信的电信应用设计的。 NDB
提供了高达99.999%
的可靠性,在读操做多的应用中表现优异。 对于有不少并发写操做的应用, 仍是推荐用InnoDB
。InnoDB Cluster
. 每台服务器实例都运行MySQL Group Replication
(冗余复制机制,内置failover
)MGR
有两种模式,一种是Single-Primary
,一种是Multi-Primary
,即单主或者多主。Multi-Primary
模式中,全部的节点都是主节点,均可以同时被读写,看上去这彷佛更好,可是由于多主的复杂性,在功能上若是设置了多主模式,则会有一些使用的限制,好比不支持Foreign Keys with Cascading Constraints。
deb下载页面:dev.mysql.com/downloads/r…mysql
wget https://repo.mysql.com//mysql-apt-config_0.8.10-1_all.deb
sudo dpkg -i mysql-apt-config_0.8.10-1_all.deb # 选择版本mysql-8.0
sudo apt-get update
复制代码
sudo apt-get install mysql-server mysql-shell mysql-router
复制代码
mysql -u root -p
进入MySQL shell,建立用户名和足够的权限# user,password替换为本身的
mysql> CREATE USER 'user'@'%' IDENTIFIED BY 'password';用户名和密码
mysql> GRANT all privileges on *.* to user@'%' identified by 'password' with grant option;
mysql> flush privileges;
复制代码
/etc/mysql/my.cnf
,添加以下配置:server_id
使用不一样编号;loose-group_replication_group_name
使用UUID
形式,集群中机器使用同一个UUID
;loose-group_replication_single_primary_mode
在单主模式中为ON
,在多主模式中为OFF
。[mysqld]
# server configuration
pid-file = /var/run/mysqld/mysqld.pid
socket = /var/run/mysqld/mysqld.sock
datadir = /var/lib/mysql
log-error = /var/log/mysql/error.log
bind-address = 0.0.0.0
# Disabling symbolic-links is recommended to prevent assorted security risks
#symbolic-links = 0
# Replication configuration parameters
server_id = 1 #2,3
gtid_mode = ON
enforce_gtid_consistency = ON
master_info_repository = TABLE
relay_log_info_repository = TABLE
transaction_write_set_extraction = XXHASH64
binlog_checksum = NONE
log_slave_updates = ON
log_bin = binlog
binlog_format = ROW
relay-log = svr-relay-bin
#
# Group Replication configuration
loose-group_replication_group_name = a38e32fd-5fb6-11e8-ad7a-00259015d941
loose-group_replication_start_on_boot = OFF
loose-group_replication_local_address = svr1:33061
loose-group_replication_group_seeds = svr1:33061,svr2:33061,svr3:3306
loose-group_replication_bootstrap_group = OFF
loose-group_replication_allow_local_disjoint_gtids_join = ON
# Group Replication configuration multi-primary mode
loose-group_replication_single_primary_mode = OFF
loose-group_replication_enforce_update_everywhere_checks = ON
复制代码
检查配置 运行命令进入mysql-js shell: sudo -i mysqlsh --uri=user@svr1:3306
对集群中的机器执行如下命令,检查配置: mysql-js> dba.checkInstanceConfiguration('user@svr1:3306')
经过下列命令查看全部服务器上group_replication配置是否一致: mysql> show variables like 'group_replication%';
sql
建立集群 若是须要建立单主模式集群,执行第1句;若是须要建立多主模式集群,执行第二句。shell
mysql-js> var cluster = dba.createCluster('mysqlCluster') # 单主模式集群
mysql-js> var cluster = dba.createCluster('mysqlCluster', {multiMaster:true}) # 多主模式集群
mysql-js> cluster.addInstance('user@svr2:3306')
mysql-js> cluster.addInstance('user@svr3:3306')
复制代码
mysql-js> var cluster = dba.getCluster()
mysql-js> cluster.status();
复制代码
输出如下内容则表示集群创建起来了(当前输出为多主模式,单主模式相似):bootstrap
{
"clusterName": "mysqlCluster",
"defaultReplicaSet": {
"name": "default",
"status": "OK",
"statusText": "Cluster is ONLINE and can tolerate up to ONE failure.",
"topology": {
"svr1:3306": {
"address": "svr1:3306",
"mode": "R/W",
"readReplicas": {},
"role": "HA",
"status": "ONLINE"
},
"svr2:3306": {
"address": "svr2:3306",
"mode": "R/W",
"readReplicas": {},
"role": "HA",
"status": "ONLINE"
},
"svr3:3306": {
"address": "svr3:3306",
"mode": "R/W",
"readReplicas": {},
"role": "HA",
"status": "ONLINE"
}
}
}
}
复制代码
客户端不能直接链接服务器,须要经过 MySQL Router 来链接。 运行命令:sudo -i mysqlrouter --bootstrap user@svr1:3306 --user mysqlrouter
生成配置文件并运行MySQLRouter
(经过keepalived
的虚拟IP可配置高可用性router) 配置文件路径:/etc/mysqlrouter/mysqlrouter.conf
,可查看访问接口 vim
问题1:[ERROR] Slave SQL for channel 'group_replication_recovery': Could not execute Write_rows event on table mysql_innodb_cluster_metadata.instances; Cannot add or update a child row: a foreign key constraint fails (
mysql_innodb_cluster_metadata
.instances
, CONSTRAINTinstances_ibfk_1
FOREIGN KEY (host_id
) REFERENCEShosts
(host_id
)), Error_code: 1452; handler error HA_ERR_NO_REFERENCED_ROW; the event's master log binlog.000001, end_log_pos 3059, Error_code: 1452 解决方式:清空表mysql_innodb_cluster_metadata.hosts; 从新创建集群bash
问题2:This member has more executed transactions than those present in the group 解决方式: mysql-> stop group_replication; mysql-> reset master;服务器
问题3:用户操做系统资源的限制 [Warning] Buffered warning: Changed limits: max_open_files: 1024 (requested 5000) [Warning] Buffered warning: Changed limits: table_open_cache: 431 (requested 2000) 解决方式: $ vim /etc/security/limits.conf,添加: mysql soft nproc 2047 mysql hard nproc 16384 mysql soft nofile 1024 mysql hard nofile 65535session
问题4:dba.rebootClusterFromCompleteOutage: The active session instance isn't the most updated in comparison with the ONLINE instances of the Cluster's metadata. 在集群没有起来时某些机器的数据表发生变更,致使数据不一致; 解决方式: 全部MySQL机器经过reset master命令清空binlogs
mysql> reset master;
mysql> show master logs;
而后再运行Dba.rebootClusterFromCompleteOutage重启集群。架构
问题5:service mysql restart没法重启mysql,mysql stuck,并一直输出日志'[Note] Plugin group_replication reported: '[GCS] cli_err 2'' 解决方式:惟一中止MySQL的命令为:
sudo pkill -9 mysqld
并发
问题6:如何将Multi-Primary改成Single-Primary? (1). 解散原来的集群:mysql-js> cluster.dissolve({force: true}) (2). 每台主机MySQL修改以下配置: mysql> set global group_replication_enforce_update_everywhere_checks=OFF; mysql> set global group_replication_single_primary_mode=ON; (3). 从新建立集群: mysql-js> var cluster = dba.createCluster('mysqlCluster'); mysql-js> cluster.addInstance('user@svr2:3306'); mysql-js> cluster.addInstance('user@svr3:3306');
This member has more executed transactions than those present in the group