当前位置:网站首页>自动化运维之Ansible安装部署
自动化运维之Ansible安装部署
2022-07-24 13:44:00 【星哥玩云】
初步了解Ansible ansible基于Python开发,,集合了众多运维工具的优点,实现了批量运行命令,部署程序,配置系统等功能。默认通过SSH协议进行远程命令执行或下发配置,无需部署任何客户端代理软件,从而使得自动化环境部署变得更加简单。可同时支持多台主机并行管理,使得管理主机更加便捷。
Ansible核心组件 ansible可以看做是一种基于模块进行工作的框架结构,批量部署能力就是有ansible所运行的模块实现的。简而言之ansible是基于“模块”完成各种“任务”的。 结构图如下所示
ansible组件由如下六部分组成 Ansible core 核心引擎
Host inventory 主机清单:用来定义Ansible所管理的主机,默认是在Ansible的hosts配置文件中定义被管理的主机,同时也支持自定义动态主机清单和指定其他配置文件的位置
Connection plugins 连接插件:负责和被管理主机实现通信。除支持使用SSH连接被管理主机外,ansible还支持其它的连接方式,所以需要有连接插件将各个主机用连接插件连接到ansible
Playbooks(yam1,jinja2)剧本:用来集中定义ansible的任务配置文件,即将多个任务定义在一个剧本中由ansible自动执行,可以由控制主机针对多台被管理主机同时运行多个任务
Core modules 核心模块:是ansible自带的模块,使用这些模块将资源分发到被管理主机,使其执行特定任务或匹配特定状态
Custom modules 自定义模块:用于完成模块功能的补充,可借助相关插件完成记录日志,发送邮件等功能
安装部署ansible服务 ansible自动化运维环境由控制主机与被管理主机组成,由于ansible是基于SSH协议进行通信的,所以控制主机安装ansible软件后不需要重启或运行任何程序,被管理主机也不需要安装或运行任何代理程序。
案例环境如下:
1 安装ansible 可以使用源码进行安装,也可以使用操作系统软件包工具进行安装。这里我使用的是CentOS7操作系统,通过yum方式安装ansible,需要依赖第三方的epel源。
yum install epel-release -y
下载好yum源之后,就可以直接使用yum命令安装ansible
yum install ansible -y
安装好之后可以查看ansible软件的版本信息。
ansible --version ansible 2.7.0 config file = /etc/ansible/ansible.cfg configured module search path = [u'/root/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules'] ansible python module location = /usr/lib/python2.7/site-packages/ansible executable location = /usr/bin/ansible python version = 2.7.5 (default, Aug 4 2017, 00:39:18) [GCC 4.8.5 20150623 (Red Hat 4.8.5-16)]
ansible主要相关配置文件在/etc/ansible目录下
cd /etc/ansible/ 总用量 24 -rw-r--r--. 1 root root 20269 10月 9 09:34 ansible.cfg #配置文件 -rw-r--r--. 1 root root 1016 10月 9 09:34 hosts #管控主机文件 drwxr-xr-x. 2 root root 6 10月 9 09:34 roles
2 配置主机清单 ansible通过读取默认主机清单/etc/ansible/hosts文件,修改主机与组配置后,可同时连接到多个被管理主机上执行任务。具体配置如下:
vim hosts [web] #被管理主机分类 192.168.199.130 [mysql] #被管理主机分类 192.168.199.131
3 设置SSH无密码登录 为了避免ansible下发指令时输入被管理主机的密码,可以通过证书签名达到SSH无密码登录的效果,使用ssh-keygen产生一对密匙,使用ssh-copy-id来下发生成的公匙 关闭三台服务器的防火墙
systemctl stop firewalld.service setenforce 0
配置秘钥验证
ssh-keygen -t rsa ssh-copy-id [email protected] ssh-copy-id [email protected]
到此,ansible的环境就部署完成了。
边栏推荐
- 【无标题】
- Network security -- Service Vulnerability scanning and utilization
- Go redis pipeline application
- Introduction to single chip microcomputer
- Win10 log in with Microsoft account and open all programs by default with administrator privileges: 2020-12-14
- 网络安全——Web渗透测试
- H5py Quick Start Guide
- 网络安全——中间人攻击渗透测试
- 网络安全——使用Exchange SSRF 漏洞结合NTLM中继进行渗透测试
- Chinese character style transfer --- unsupervised typesetting transmission
猜你喜欢

Network security -- man in the middle attack penetration test

Network security - Web information collection

Network security - Web penetration testing

软链接、硬链接

网络安全——文件上传白名单绕过

Network security - file upload whitelist bypass

HCIP第十三天

Network security - file upload penetration test

在EXCEL表格中如何进行快速换行

网络安全——使用Evil Maid物理访问安全漏洞进行渗透
随机推荐
How to configure webrtc protocol for low latency playback on easycvr platform v2.5.0 and above?
Explain flex layout in detail
Simple order management system small exercise
rhcsa第六次笔记
Notes on Linear Algebra -- lesson 25 -- projection of vectors on axes
Explain the edge cloud in simple terms | 2. architecture
Kunyu installation details
R语言使用sort函数排序向量数据实战、返回实际排序后的数据(默认升序)
Detailed tutorial of ettercap
数据类型二进制字符串类型
软链接、硬链接
Mongodb uses mongotemplate operations to add, delete, modify, query, page, sort, aggregate (including embedded data), file upload and download
网络安全——文件上传白名单绕过
网络安全——文件上传黑名单绕过
交换机链路聚合详解【华为eNSP】
Realize a JS lottery?
FlinkTable&SQL(六)
为什么函数式接口 Comparator 中有 “两个抽象方法”?
Network security - war backdoor deployment
Get (min / max value) of (object array / array)