1 Star 0 Fork 0

newrain001/xa2401-ansible

Create your Gitee Account
Explore and code with more than 12 million developers,Free private repositories !:)
Sign up
This repository doesn't specify license. Please pay attention to the specific project description and its upstream code dependency when using it.
Clone or Download
mysql-replication.yml 1.76 KB
Copy Edit Raw Blame History
Your Name authored 2024-04-19 05:05 . 提交
---
- hosts: all
remote_user: root
vars:
db_password: "QianFeng@123"
repl_user: "slave"
repl_password: "QianFeng@123456"
master_host: 192.168.80.147
tasks:
- name: 拷贝数据库包
unarchive:
src: mysql-yum.tar.gz
dest: /opt/
- name: 安装mysql
shell: "chdir=/opt/mysql-yum yum localinstall -y *.rpm"
- name: 拷贝配置文件
template:
src: my.cnf
dest: /etc/my.cnf
backup: yes
- name: 启动数据库
service:
name: mysqld
state: started
- name: 修改初始密码
shell: passwd=$(grep -o 'root@localhost.*' /var/log/mysqld.log | awk 'END{print $NF}') ; mysqladmin -uroot -p$passwd password "{{ db_password }}"
- name: 配置主库用户
shell: mysql -uroot -p"{{ db_password }}" -e "create user if not exists '{{ repl_user }}'@'%' identified by '{{ repl_password }}'; grant replication slave on *.* to '{{ repl_user }}'@'%'; flush privileges"
when: "role == 'master'"
- name: 查看主库日志
shell: mysql -N -uroot -p"{{ db_password }}" -e "show master status;" | awk '{print $1}'
when: "role == 'master'"
- name: 查看主库日志位置
shell: mysql -N -uroot -p"{{ db_password }}" -e "show master status;" | awk '{print $2}'
when: "role == 'master'"
- name: 执行从库配置
shell: mysql -uroot -p"{{ db_password }}" -e "CHANGE MASTER TO MASTER_HOST='{{ master_host }}',MASTER_USER='{{ repl_user }}',MASTER_PASSWORD='{{ repl_password }}',MASTER_LOG_FILE='mysql-bin.000002',MASTER_LOG_POS=1023; start slave; show slave status\G"
when: "role == 'slave'"
register: slave_status
tags: slave
- name: 输出结果
debug:
var: slave_status
tags: slave
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/newrain001/xa2401-ansible.git
git@gitee.com:newrain001/xa2401-ansible.git
newrain001
xa2401-ansible
xa2401-ansible
master

Search