mysql复制与ansible

标签 mysql ansible

我正在使用 Ansible 进行 mysql 复制。

我有以下 ansible 任务:

---
- name: update mysql config file
  template:
    src: templates/my.cnf.j2
    dest: /etc/mysql/my.cnf
  notify:
    - restart mysql

- name: create replicator user
  mysql_user:
    name: "replicator"
    host: "%"
    password: "{{ mysql_replicator_password }}"
    priv: "*.*:REPLICATION SLAVE"
    state: present
  notify:
    - restart mysql

- name: Check replication init with checking file existence
  stat: path=/etc/mysql/repl.ansible
  register: check_sql_path

- mysql_replication:
    mode: changemaster
    master_host: "{{ groups.web[1] }}"
    master_user: replicator
    master_password: "{{ mysql_replicator_password }}"
  when: groups.web[1] is defined and check_sql_path.stat.exists == false and '{{ inventory_hostname }}' == '{{ groups.web[0] }}'
  notify:
    - restart mysql

- command: touch /etc/mysql/repl.ansible
  when: groups.web[1] is defined and check_sql_path.stat.exists == false and '{{ inventory_hostname }}' == '{{ groups.web[0] }}'

- mysql_replication:
    mode: changemaster
    master_host: "{{ groups.web[0] }}"
    master_user: replicator
    master_password: "{{ mysql_replicator_password }}"
  when: groups.web[1] is defined and check_sql_path.stat.exists == false and '{{ inventory_hostname }}' == '{{ groups.web[1] }}'
  notify:
    - restart mysql

- command: touch /etc/mysql/repl.ansible
  when: groups.web[1] is defined and check_sql_path.stat.exists == false and '{{ inventory_hostname }}' == '{{ groups.web[1] }}'

这个任务在我运行时没问题,但是当我使用 phpmyadmin 查看复制状态时,我收到以下消息(在两个服务器上):

  • Slave_IO_State:连接到 master
  • Slave_IO_Running:正在连接
  • Slave_SQL_Running:是

我不是 mysql 复制方面的专家,您认为有什么可以帮助我的吗?

(我遵循本教程:https://raymii.org/s/articles/Building_HA_Clusters_With_Ansible_and_Openstack.html)

谢谢

最佳答案

I'm not an expert in mysql replication, do you see anything can help me ?

它是在主-主复制中运行 mysql 的 2 个数据库服务器:

MySQL replication is the process by which a single data set, stored in a MySQL database, will be live-copied to a second server. This configuration, called "master-slave" replication.

Master-master replication allows data to be copied from either server to the other one. This subtle but important difference allows us to perform mysql read or writes from either server. This configuration adds redundancy and increases efficiency when dealing with accessing the data.

您的链接还描述了:

We also use a double when conditional. We need to set up the servers with each other's IP as the master. Therefore we need to run the setup for host A with the master IP of host B, and vice versa.

关于mysql复制与ansible,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36864514/

相关文章:

mysql - 如果我们在wampserver中有mysql,那么我们是否需要单独安装mysqlserver以用于PC上的jsp开发(数据库)

linux - 如何使用 Ansible playbook 创建具有更改所有权的目录结构

ansible - 如何自动执行Ansible Vault解密?

ansible - 如何在开发机器上使用ansible模板在本地创建文件

c# - 如何在C#中一次性执行两个查询?

mysql - SQL : Order by when a value looks like a date

mysql - 如何编写这个 MySQL 查询?

MySQL:WHERE 子选择中 GROUP BY 的奇怪行为

windows - Ansible:无法在 Windows 节点上执行 ping [SSL:CERTIFICATE_VERIFY_FAILED]

Ansible 检查变量是否已设置