ansible是新出现的自动化运维工具,基于Python开发,集合了众多运维工具(puppet、cfengine、chef、func、fabric)等优点,实现了批量系统配置、批量程序部署、批量运行命令等功能。 ansible是基于模块工作的,本身没有批量部署的能力。真正具有批量部署的是ansible所运行的模块,ansible只是提供一种框架。主要包括: (1)、连接插件connection plugins:负责和被监控端实现通信; (2)、host inventory:指定操作的主机,是一个配置文件里面定义监控的主机; (3)、各种模块核心模块、command模块、自定义模块; (4)、借助于插件完成记录日志邮件等功能; (5)、playbook:剧本执行多个任务时,非必需可以让节点一次性运行多个任务。
链接:https://pan.baidu.com/s/18vdKcYUHxdOnZjayle_Fkw
提取码:bmvo
复制这段内容后打开百度网盘手机App,操作更方便哦
基于centos7上的yum安装ansible 基于centos6上安装的MySQL 接下来的时间我们编写脚本吧!!!!!!!!!!!! my.cnf配置如下】 [mysqld] server-id=1 log_bin=mysql-bin relay_log=mysql-relay 保存退出 /opt/my.cnf配置如下】】 [mysqld] server-id=2 log_bin=mysql-bin relay_log=mysql-relay 保存退出
[root@localhost ~]# vim mysql.yaml
—
– hosts: web
tasks:
– name: 安装mysql服务
yum: name={{ item }} state=installed
with_items:
– mysql
– mysql-server
– name: 分发配置文件 主
copy: src=/root/my.cnf dest=/etc/my.cnf
when: ansible_machine_id == “0db24cc9ab3462952a8ded4f0000000c”
– name: 分发配置文件 从
copy: src=/opt/my.cnf dest=/etc/my.cnf
when: ansible_machine_id == “a3a0f053e7d25013af92585f00000011”
– name: 启动mysql
service: name=mysqld state=started
– name: 授权用户
shell: mysql -e “grant all on *.* to ‘tom‘@‘%‘ identified by ‘123‘”
– name: 刷新权限
shell: mysql -e “flush privileges”
– name: 重置日志
shell: mysql -e “reset master”
– name: 停止slave
shell: mysql -e “stop slave”
– name: 编写日志‘152
shell: mysql -e”change master to master_host=‘192.168.220.169‘,
master_user=‘tom‘,master_password=‘123‘,
master_log_file=‘mysql-bin.000001‘,master_log_pos=106;”
when: ansible_machine_id == “a3a0f053e7d25013af92585f00000011” #判断条件
– name: 编写日志‘169
shell: mysql -e”change master to master_host=‘192.168.220.152‘,
master_user=‘tom‘,master_password=‘123‘,
master_log_file=‘mysql-bin.000001‘,master_log_pos=106;”
when: ansible_machine_id == “0db24cc9ab3462952a8ded4f0000000c” #判断条件
– name: 停止slave
shell: mysql -e “start slave”
– name: 重启msyql
service: name=mysqld state=restarted
– name: 关闭防火墙
service: name=iptables state=stopped
希望看到这篇文章的小伙伴给小编一个赞, (#^.^#)