写一段ansible,用来安装mysql主从
时间: 2023-10-26 08:34:04 浏览: 148
Ansible部署Mysql 5.7.28主从
服务器。
好的,以下是可以安装MySQL主从服务器的Ansible代码:
---
- hosts: db_servers
become: true
tasks:
- name: Install MySQL server
yum:
name: mysql-server
state: present
- name: Start MySQL service
service:
name: mysqld
state: started
enabled: true
- name: Configure MySQL master
mysql_replication:
mode: "master"
login_host: "{{ inventory_hostname }}"
login_user: "{{ mysql_user }}"
login_password: "{{ mysql_password }}"
force: true
- name: Configure MySQL slave
mysql_replication:
mode: "slave"
login_host: "{{ inventory_hostname }}"
login_user: "{{ mysql_user }}"
login_password: "{{ mysql_password }}"
master_host: "{{ mysql_master_host }}"
master_user: "{{ mysql_master_user }}"
master_password: "{{ mysql_master_password }}"
master_port: "{{ mysql_master_port }}"
force: true
注意:这个Ansible代码只是一个范例,需要根据你的具体情况进行修改。另外,确保在运行之前,你已经设置好了MySQL的用户名和密码。
阅读全文