MySQL--------基于半同步复制搭建主从
发布时间:2023-05-08 13:26:37 所属栏目:MySql教程 来源:
导读:背景
* MySQL Replication默认都是异步(asynchronous),当主库在执行完一些事务后,是不会管备库的进度的。如果备库不幸落后,而更不幸的是主库此时又出现Crash(例如宕机),这时备库中的数据就是不完整的。
* MySQL Replication默认都是异步(asynchronous),当主库在执行完一些事务后,是不会管备库的进度的。如果备库不幸落后,而更不幸的是主库此时又出现Crash(例如宕机),这时备库中的数据就是不完整的。
背景 * MySQL Replication默认都是异步(asynchronous),当主库在执行完一些事务后,是不会管备库的进度的。如果备库不幸落后,而更不幸的是主库此时又出现Crash(例如宕机),这时备库中的数据就是不完整的。简而言之,在主库发生故障的时候,我们无法使用备库来继续提供数据一致的服务了。 * Semi sync Replication在一定程度上保证提交的事务已经传给了至少一个备库。 * Semi sync Replication仅仅保证事务的已经传递到备库上,但是并不确保已经在备库上执行完成。 * Semi sync Replication主库等待超时(rpl_semi_sync_master_timeout)后,会自动降级为默认的异步(asynchronous)。 * MysqL 5.5版本开始支持Semi sync Replication MySQL--------基于半同步复制搭建主从 环境 * master 服务器环境 MysqL> system cat /etc/redhat-release CentOS release 6.8 (Final) MysqL> system ifconfig eth0 | sed -rn '2s#^.*addr:(.*) Bca.*$#\1#gp' 172.18.0.1 MysqL> show variables like 'version'; +---------------+------------+ | Variable_name | Value | +---------------+------------+ | version | 5.6.36-log | +---------------+------------+ 1 row in set (0.00 sec) * master 服务器环境 MysqL> system cat /etc/redhat-release CentOS release 6.8 (Final) MysqL> system ifconfig eth0 | sed -rn '2s#^.*addr:(.*) Bca.*$#\1#gp' 172.18.4.1 MysqL> show variables like 'version'; +---------------+------------+ | Variable_name | Value | +---------------+------------+ | version | 5.6.36-log | +---------------+------------+ 1 row in set (0.00 sec) * master服务器my.cnf配置文件 [MysqLd] ########basic settings######## # 主从server-id一定要设置不同 server-id = 110 port = 3306 user = MysqL bind_address = 0.0.0.0 character_set_server=utf8mb4 skip_name_resolve = 1 datadir = /data/MysqL_data log_error = error.log #######replication settings######## master_info_repository = TABLE relay_log_info_repository = TABLE # MysqL复制是基于binlog日志的 log_bin = bin.log sync_binlog = 1 log_slave_updates # MysqL binlog格式搭建主从时必须设置为row binlog_format = row relay_log = relay.log relay_log_recovery = 1 slave_skip_errors = ddl_exist_errors ######semi sync replication settings######## # 设置插件目录路径 plugin_dir=/usr/local/MysqL/lib/plugin # 加载插件 plugin_load = "rpl_semi_sync_master=semisync_master.so;rpl_semi_sync_slave=semisync_slave.so" # 开启master semi sync replication loose_rpl_semi_sync_master_enabled = 1 # 开启slave semi sync replication loose_rpl_semi_sync_slave_enabled = 1 # 等待5秒无ack应答自动切换为异步模式 loose_rpl_semi_sync_master_timeout = 5000 * slave服务器my.cnf配置文件 [MysqLd] ########basic settings######## server-id = 210 port = 3306 user = MysqL bind_address = 0.0.0.0 character_set_server=utf8mb4 skip_name_resolve = 1 datadir = /data/MysqL_data log_error = error.log # slave上开启只读,避免应用误写导致主从数据不一致 read_only = on #######replication settings######## master_info_repository = TABLE relay_log_info_repository = TABLE log_bin = bin.log sync_binlog = 1 log_slave_updates binlog_format = row relay_log = relay.log relay_log_recovery = 1 binlog_gtid_simple_recovery = 1 slave_skip_errors = ddl_exist_errors ######semi sync replication settings######## plugin_dir=/usr/local/MysqL/lib/plugin plugin_load = "rpl_semi_sync_master=semisync_master.so;rpl_semi_sync_slave=semisync_slave.so" loose_rpl_semi_sync_master_enabled = 1 loose_rpl_semi_sync_slave_enabled = 1 loose_rpl_semi_sync_master_timeout = 5000 (编辑:汽车网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
推荐文章
站长推荐