Fetch the repository succeeded.
---
- 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
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。