当前位置:网站首页>自动化运维之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的环境就部署完成了。
边栏推荐
- Detailed explanation of odoo JS DoAction
- R语言使用epiDisplay包的statStack函数基于因子变量通过分层的方式查看连续变量的统计量(均值、中位数等)以及对应的假设检验、对连续数据进行对数化之后符合参数检验条件自动执行参数检验
- 网络安全——报错注入
- Simple use and difference of symmetric res, AES and asymmetric RSA (JWT)
- 网络安全——文件上传黑名单绕过
- Repair the problem of adding device groups and editing exceptions on easycvr platform
- Basic operation of file
- Aggregation measurement of robot swarm intelligence based on group entropy
- 论文笔记:Swin-Unet: Unet-like Pure Transformer for MedicalImage Segmentation
- AtCoder Beginner Contest 261 F // 树状数组
猜你喜欢

Detailed explanation of odoo JS DoAction

Chinese character style transfer --- unsupervised typesetting transmission

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

【无标题】

Odoo+ test

Why are there "two abstract methods" in the functional interface comparator?

The scroll bar in unity ugui is not displayed from the top when launching the interface in the game

WSDM 22 | graph recommendation based on hyperbolic geometry

网络安全——使用Evil Maid物理访问安全漏洞进行渗透

网络安全——文件上传渗透测试
随机推荐
Network security - Web information collection
Outdoor billboards cannot be hung up if you want! Guangzhou urban management department strengthens the safety management of outdoor advertising
How to verify the domain name after applying for SSL digital certificate?
R语言使用epiDisplay包的dotplot函数通过点图的形式可视化不同区间数据点的频率、使用by参数指定分组参数可视化不同分组的点图分布、使用cex.Y.axis参数指定Y轴分组标签文本的大小
使用Activiti创建数据库表报错,
网络安全——函数绕过注入
Spelling words~
论文笔记:Swin-Unet: Unet-like Pure Transformer for MedicalImage Segmentation
Mongodb uses mongotemplate operations to add, delete, modify, query, page, sort, aggregate (including embedded data), file upload and download
H5py Quick Start Guide
WSDM 22 | 基于双曲几何的图推荐
Get (min / max value) of (object array / array)
网络安全——文件上传竞争条件绕过
Network security - use exchange SSRF vulnerabilities in combination with NTLM trunking for penetration testing
Sringboot-plugin-framework 实现可插拔插件服务
Atcoder beginer contest 261 f / / tree array
Kunyu(坤舆) 安装 详解
rhce第一次作业
Common OJ questions of stack and queue
2022年全国职业院校技能大赛赛项比赛时间、承办校信息统计表(第二批)