ansible安装部署步骤[通俗易懂]

Ansible概述

Ansible可以同时管理Redhat系的Linux,Debian系的Linux,以及Windows主机。管理节点只在执行脚本时与远程主机连接,没有特别的同步机制,所以断电等异常一般不会影响ansbile。

ansible是自动化运维工具,基于Python开发,集合了众多运维工具(puppet、cfengine、chef、func、fabric)的优点,实现了批量系统配置、批量程序部署、批量运行命令等功能。ansible是基于模块工作的,本身没有批量部署的能力。真正具有批量部署的是ansible所运行的模块,ansible只是提供一种框架。主要包括:

1、连接插件connection plugins:负责和被监控端实现通信;

2、host inventory:指定操作的主机,是一个配置文件里面定义监控的主机;

3、各种模块核心模块、command模块、自定义模块;

4、借助于插件完成记录日志邮件等功能;

5、playbook:剧本执行多个任务时,非必需可以让节点一次性运行多个任务。

ansible的架构:连接其他主机默认使用ssh协议

管理端:   192.168.59.138

被管理端:192.168.59.139

被管理端:192.168.59.140

1、关闭防火墙

[root@localhost ~]# systemctl stop firewalld.service

[root@localhost ~]# systemctl disable firewalld.service

Removed symlink /etc/systemd/system/multi-user.target.wants/firewalld.service.

Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.

[root@localhost ~]# setenforce 0

2、安装相关软件

[root@localhost ~]# yum -y install epel-release.noarch

[root@localhost ~]# yum install -y ansible

[root@localhost ~]# yum install -y tree

[root@localhost ~]# tree /etc/ansible/

/etc/ansible/

├── ansible.cfg

├── hosts

└── roles

3、修改主机清单

[root@localhost ~]# vim /etc/ansible/hosts    #配置主机清单

#以下内容为添加内容,不是修改内容

[webservers]

192.168.59.139    #被监控端1的IP

[mysql]

192.168.59.140    #被监控端2的IP

4、创建密钥对

[root@m01 ~]# ssh-keygen -t dsa

2)分发公钥给受控端

ssh-copy-id -i /root/.ssh/id_dsa.pub root@192.168.59.139

ssh-copy-id -i /root/.ssh/id_dsa.pub root@92.168.59.139

5、测试是否安装成功

[root@ansible ~]# ansible 192.168.59.139 -m command -a 'date'

                            ansible all -m command -a 'uptime'

[root@ansible ~]# ansible mysql -m command -a 'date'    #当然也可以用别名进程查看

-m:指定模块

-a:指定参数

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。