Ansible自动化部署MySQL主从

1、添加hosts文件

# vim /etc/ansible/hosts 
[mysql_slave]
1.1.1.2 ansible_ssh_user=root ansible_ssh_pass=Root
[mysql_master]
1.1.1.1 ansible_ssh_user=root ansible_ssh_pass=Root

2.创建mysql角色文件,用于调用mysql_repl

  1 - hosts: mysql_master
  2   remote_user: root
  3   gather_facts: False
  4   roles:
  5     - {role: mysql_repl,mysql_repl_role: master}
  6 
  7 - hosts: mysql_slave
  8   remote_user: root
  9   gather_facts: False
 10   roles:
 11     - {role: mysql_repl,mysql_repl_role: slave,mysql_repl_master: 1.1.1.1,my    sql_repl_user: [{name: repl,passwd: repl}]}

3.创建变量文件

  1 ---
  2 source_dir: /home/db/mysql/src/
  3 mysql_root_pwd: redhat123
  4 mysql_port: 13306
  5 socket: /tmp/mysql.sock
  6 
  7 mysql_db:
  8 - name: test1
  9   replicate: yes
 10 - name: test2
 11   replicate: no
 12 - name: test3
 13   replicate: no
 14 
 15 mysql_remote_user:
 16 - name: remote
 17   passwd
  • 1
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值