fix(ansible): 一主多从从库强制只读

- mysql-instance.cnf.j2 按 mysql_node_role=replica 注入 read-only/super-read-only,
  阻止业务直接写入从库导致主从数据分叉(复制线程与复制管理语句不受影响)
- 账号配置任务在从库上临时放开只读、配置完成后回锁,
  避免 cnf 只读拒绝 ALTER/CREATE USER;主库与 standalone 不受影响
This commit is contained in:
Hungerdream
2026-07-31 18:49:21 +08:00
parent 716e816a66
commit 454df86021
3 changed files with 30 additions and 0 deletions
+6
View File
@@ -53,6 +53,12 @@ binlog-expire-logs-seconds={{ mysql_binlog_expire_logs_seconds }} # binlog 过
gtid-mode=ON # 启用 GTID(全局事务标识符)
enforce-gtid-consistency=ON # 强制 GTID 一致性(确保复制安全)
relay-log={{ mysql_binlog_dir }}/relay-bin # 中继日志路径(从库重放 binlog 使用)
{% if mysql_node_role | default('') == 'replica' %}
# 从库强制只读:阻止业务直接写入从库导致主从数据分叉
# 复制线程与 CHANGE REPLICATION SOURCE 等复制管理语句不受影响
read-only=ON
super-read-only=ON
{% endif %}
{% endif %}
# =============================================================================