01_什么是ansible、基本架构、ansible工作机制、Ansible安装、配置主机清单、设置SSH无密码登录等

1.什么是ansible
1.1.基本介绍
1.2.基本架构
1.3.基本特征
1.4.优点
1.5.ansible工作机制
2.Ansible安装
2.1.机器准备
2.2.安装ansible
2.2.1.安装epel源
2.2.2.安装ansible
2.2.3.查看ansible版本
2.2.4.树状结构展示文件夹
2.2.4.1.其中ansible.cfg的内容如下
2.2.4.2.host的默认内容是
2.3.配置主机清单
2.4.设置SSH无密码登录
2.5.参考文章

1.什么是ansible

转自:https://blog.51cto.com/liqingbiao/1875921

1.1.基本介绍

ansible是新出现的自动化运维工具,基于Python开发,集合了众多运维工具(puppet、cfengine、chef、func、fabric)的优点,实现了批量系统配置、批量程序部署、批量运行命令等功能。

ansible是基于 paramiko 开发的,并且基于模块化工作,本身没有批量部署的能力。真正具有批量部署的是ansible所运行的模块,ansible只是提供一种框架。ansible不需要在远程主机上安装client/agents,因为它们是基于ssh来和远程主机通讯的。ansible目前已经已经被红帽官方收购,是自动化运维工具中大家认可度最高的,并且上手容易,学习简单。是每位运维工程师必须掌握的技能之一。主要包括:

  • (1)、连接插件connection plugins:负责和被监控端实现通信;
  • (2)、host inventory:指定操作的主机,是一个配置文件里面定义监控的主机;
  • (3)、各种模块核心模块、command模块、自定义模块;
  • (4)、借助于插件完成记录日志邮件等功能;
  • (5)、playbook:剧本执行多个任务时,非必需可以让节点一次性运行多个任务。

1.2.基本架构

在这里插入图片描述

1.3.基本特征

(1)、no agents:不需要在被管控主机上安装任何客户端;
(2)、no server:无服务器端,使用时直接运行命令即可;
(3)、modules in any languages:基于模块工作,可使用任意语言开发模块;
(4)、yaml,not code:使用yaml语言定制剧本playbook;
(5)、ssh by default:基于SSH工作;
(6)、strong multi-tier solution:可实现多级指挥。

1、部署简单,只需在主控端部署Ansible环境,被控端无需做任何操作;
2、默认使用SSH协议对设备进行管理;
3、有大量常规运维操作模块,可实现日常绝大部分操作。
4、配置简单、功能强大、扩展性强;
5、支持API及自定义模块,可通过Python轻松扩展;
6、通过Playbooks来定制强大的配置、状态管理;
7、轻量级,无需在客户端安装agent,更新时,只需在操作机上进行一次更新即可;
8、提供一个功能强大、操作性强的Web管理界面和REST API接口——AWX平台。

1.4.优点

(1)、轻量级,无需在客户端安装agent,更新时,只需在操作机上运行一次更新即可;
(2)、批量任务执行可以写成脚本,而且不用分发到远程就可以执行。
(3)、使用python编写,维护更简单,ruby语法过于复杂
(4)、支持sudo

1.5.ansible工作机制

在这里插入图片描述

2.Ansible安装

2.1.机器准备

本次使用docker进行虚拟化:
docker相关的命令是:

docker commit d74af80aa35a centos7.5.1804.v0.2

将镜像保存
docker save -o xxx.tar containerId

将镜像导入
docker load < xxx.tar
============================================================

docker run -itd --restart=always --name node2 --hostname node2 -v D:/dockerworkspace/node2/hosts:/etc/hosts -v D:/dockerworkspace/node2/hostname:/etc/hostname -v D:/dockerworkspace/node2/data:/data -v D:/dockerworkspace/node2/profile:/etc/profile -v D:/dockerworkspace/node2/software:/root/software -v D:/dockerworkspace/node2/installed:/root/installed -v D:/dockerworkspace/node2/workspace:/root/workspace -p 20022:22 --ip 172.17.0.2 1694ea743590 /usr/sbin/sshd -D

docker run -itd --restart=always --name node3 --hostname node3 -v D:/dockerworkspace/node3/hosts:/etc/hosts -v D:/dockerworkspace/node3/hostname:/etc/hostname -v D:/dockerworkspace/node3/data:/data -v D:/dockerworkspace/node3/profile:/etc/profile -v D:/dockerworkspace/node3/software:/root/software -v D:/dockerworkspace/node3/installed:/root/installed -v D:/dockerworkspace/node3/workspace:/root/workspace -p 30022:22 --ip 172.17.0.3  1694ea743590 /usr/sbin/sshd -D

docker run -itd --restart=always --name node4 --hostname node4 -v D:/dockerworkspace/node4/hosts:/etc/hosts -v D:/dockerworkspace/node4/hostname:/etc/hostname -v D:/dockerworkspace/node4/data:/data -v D:/dockerworkspace/node4/profile:/etc/profile -v D:/dockerworkspace/node4/software:/root/software -v D:/dockerworkspace/node4/installed:/root/installed -v D:/dockerworkspace/node4/workspace:/root/workspace -p 40022:22 --ip 172.17.0.4 1694ea743590 /usr/sbin/sshd -D

docker run -itd --restart=always --name node5 --hostname node5 -v D:/dockerworkspace/node5/hosts:/etc/hosts -v D:/dockerworkspace/node5/hostname:/etc/hostname -v D:/dockerworkspace/node5/data:/data -v D:/dockerworkspace/node5/profile:/etc/profile -v D:/dockerworkspace/node5/software:/root/software -v D:/dockerworkspace/node5/installed:/root/installed -v D:/dockerworkspace/node5/workspace:/root/workspace -p 50022:22 --ip 172.17.0.5 1694ea743590 /usr/sbin/sshd -D

docker run -itd --restart=always --name node6 --hostname node6 -v D:/dockerworkspace/node6/hosts:/etc/hosts -v D:/dockerworkspace/node6/hostname:/etc/hostname -v D:/dockerworkspace/node6/data:/data -v D:/dockerworkspace/node6/profile:/etc/profile -v D:/dockerworkspace/node6/software:/root/software -v D:/dockerworkspace/node6/installed:/root/installed -v D:/dockerworkspace/node6/workspace:/root/workspace -p 60022:22 --ip 172.17.0.6 1694ea743590 /usr/sbin/sshd -D
主机名IP安装软件组名
node2(管理机器)172.17.0.2Ansible
node3(被管理机器)172.17.0.3abc
node4(被管理机器)172.17.0.4abc
node5(备用)172.17.0.5
node6(备用)172.17.0.6

2.2.安装ansible

在管理机器上安装ansible

2.2.1.安装epel源

[root@node2 ~]# yum install -y epel-release
Loaded plugins: fastestmirror, ovl
Determining fastest mirrors
 * base: mirrors.163.com
 * extras: mirrors.163.com
 * updates: mirrors.163.com
base                                                                                                                     | 3.6 kB  00:00:00
extras                                                                                                                   | 2.9 kB  00:00:00
updates                                                                                                                  | 2.9 kB  00:00:00
(1/2): extras/7/x86_64/primary_db                                                                                        | 243 kB  00:00:00
(2/2): updates/7/x86_64/primary_db                                                                                       |  11 MB  00:00:01
Resolving Dependencies
--> Running transaction check
---> Package epel-release.noarch 0:7-11 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

================================================================================================================================================
 Package                                Arch                             Version                         Repository                        Size
================================================================================================================================================
Installing:
 epel-release                           noarch                           7-11                            extras                            15 k

Transaction Summary
================================================================================================================================================
Install  1 Package

Total download size: 15 k
Installed size: 24 k
Downloading packages:
epel-release-7-11.noarch.rpm                                                                                             |  15 kB  00:00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : epel-release-7-11.noarch                                                                                                     1/1
  Verifying  : epel-release-7-11.noarch                                                                                                     1/1

Installed:
  epel-release.noarch 0:7-11

Complete!
[root@node2 ~]#

2.2.2.安装ansible

[root@node2 ~]# yum install ansible -y
Loaded plugins: fastestmirror, ovl
Loading mirror speeds from cached hostfile
epel/x86_64/metalink                                                                                                     | 3.9 kB  00:00:00
 * base: mirrors.163.com
 * epel: ftp.jaist.ac.jp
 * extras: mirrors.163.com
 * updates: mirrors.163.com
epel                                                                                                                     | 4.7 kB  00:00:00
(1/3): epel/x86_64/group_gz                                                                                              |  96 kB  00:00:00
(2/3): epel/x86_64/updateinfo                                                                                            | 1.0 MB  00:00:01
xxxxxxxxxxxxxxxxxxxxxxxxx
--> Running transaction check
---> Package python-backports.x86_64 0:1.0-8.el7 will be installed
---> Package python-pycparser.noarch 0:2.14-1.el7 will be installed
--> Processing Dependency: python-ply for package: python-pycparser-2.14-1.el7.noarch
--> Running transaction check
Complete!
[root@node2 ~]#

2.2.3.查看ansible版本

[root@node2 ~]# ansible --version
ansible 2.9.25
  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, Apr 11 2018, 07:36:10) [GCC 4.8.5 20150623 (Red Hat 4.8.5-28)]
[root@node2 ~]#

2.2.4.树状结构展示文件夹

# ansible --version          //查看ansible版本
# yum install tree -y
# tree /etc/ansible/         //树状结构展示文件夹
	/etc/ansible/
  	├── ansible.cfg        #ansible的配置文件
  	├── hosts            #ansible的主仓库,用于存储需要管理的远程主机的相关信息
  	└── roles             #角色(这是一个目录)

2.2.4.1.其中ansible.cfg的内容如下

在这里插入图片描述

2.2.4.2.host的默认内容是

[root@node2 ansible]# cat hosts
# This is the default ansible 'hosts' file.
#
# It should live in /etc/ansible/hosts
#
#   - Comments begin with the '#' character
#   - Blank lines are ignored
#   - Groups of hosts are delimited by [header] elements
#   - You can enter hostnames or ip addresses
#   - A hostname/ip can be a member of multiple groups

# Ex 1: Ungrouped hosts, specify before any group headers.

## green.example.com
## blue.example.com
## 192.168.100.1
## 192.168.100.10

# Ex 2: A collection of hosts belonging to the 'webservers' group

## [webservers]
## alpha.example.org
## beta.example.org
## 192.168.1.100
## 192.168.1.110

# If you have multiple hosts following a pattern you can specify
# them like this:

## www[001:006].example.com

# Ex 3: A collection of database servers in the 'dbservers' group

## [dbservers]
##
## db01.intranet.mydomain.net
## db02.intranet.mydomain.net
## 10.25.1.56
## 10.25.1.57

# Here's another example of host ranges, this time there are no
# leading 0s:

## db-[99:101]-node.example.com

[root@node2 ansible]#

2.3.配置主机清单

[root@node2 ansible]# cd /etc/ansible
[root@node2 ansible]# vim hosts
[abc]              # 自定义一个组名
172.17.0.3         # 添加被管理主机的IP

[aaa]
172.17.0.4

[bbb]
172.17.0.5
172.17.0.6

2.4.设置SSH无密码登录

[root@node2 ansible]# ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
Created directory '/root/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:sZtXen524PUZoQP5C76faiL/Rpx9IOUIFpVB7SIjymM root@node2
The key's randomart image is:
+---[RSA 2048]----+
|         .+++    |
|         o . o   |
|        o . *    |
|       . = * + . |
|    . . S + O o .|
|     E   o B =.o.|
|    . . o = o.+o+|
|       . o * .=.o|
|        o.=+== . |
+----[SHA256]-----+
[root@node2 ansible]#

yum -y install openssh-clients (此命令是在出现了-bash: ssh-copy-id: command not found之后执行)

ssh-copy-id root@172.17.0.3
ssh-copy-id root@172.17.0.4
ssh-copy-id root@172.17.0.5
ssh-copy-id root@172.17.0.6

免交互代理:
[root@node2 ansible]# ssh-agent bash
[root@node2 ansible]# ssh-add

[root@node2 ansible]# ssh-copy-id -i /root/.ssh/id_rsa.pub root@172.17.0.3
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub"
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
root@172.17.0.3's password:

Number of key(s) added: 1

Now try logging into the machine, with:   "ssh 'root@172.17.0.3'"
and check to make sure that only the key(s) you wanted were added.

[root@node2 ansible]# ssh-copy-id -i /root/.ssh/id_rsa.pub root@172.17.0.4
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub"
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
root@172.17.0.4's password:

Number of key(s) added: 1

Now try logging into the machine, with:   "ssh 'root@172.17.0.4'"
and check to make sure that only the key(s) you wanted were added.

[root@node2 ansible]# ssh-copy-id -i /root/.ssh/id_rsa.pub root@172.17.0.5
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub"
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
root@172.17.0.5's password:

Number of key(s) added: 1

Now try logging into the machine, with:   "ssh 'root@172.17.0.5'"
and check to make sure that only the key(s) you wanted were added.

[root@node2 ansible]# ssh-copy-id -i /root/.ssh/id_rsa.pub root@172.17.0.6
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub"
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
root@172.17.0.6's password:

Number of key(s) added: 1

Now try logging into the machine, with:   "ssh 'root@172.17.0.6'"
and check to make sure that only the key(s) you wanted were added.

[root@node2 ansible]#

2.5.参考文章

https://blog.51cto.com/u_13630803/2153392
https://www.cnblogs.com/cyleon/p/11164344.html
https://blog.51cto.com/u_13630803/2153820

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mfbz.cn/a/65155.html

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

24届近5年上海大学自动化考研院校分析

今天给大家带来的是上海大学控制考研分析 满满干货&#xff5e;还不快快点赞收藏 一、上海大学 学校简介 上海大学是上海市属的综合性研究型大学&#xff0c;是教育部与上海市人民政府共建高校&#xff0c;是国家“211 工程”重点建设高校、上海市高水平地方大学建设高校&a…

【Kubernetes部署篇】基于Ubuntu20.04操作系统搭建K8S1.23版本集群

文章目录 一、集群架构规划信息二、系统初始化准备(所有节点同步操作)三、安装kubeadm(所有节点同步操作)四、初始化K8S集群(master节点操作)五、添加Node节点到K8S集群中六、安装Calico网络插件七、测试CoreDNS可用性 一、集群架构规划信息 pod网段&#xff1a;10.244.0.0/16…

中断子系统--硬件层(GICv3)

目录 综述 硬件层--GICV3 中断类型 中断状态 Distributor组件 中断使能配置 中断触发方式配置 中断优先级配置  中断分组标记 GIC处理中断流程 综述 由上面的block图&#xff0c;我们可知linux kernel的中断子系统分成4个部分&#xff1a; 硬件层&#xff1a;最下层…

Abaqus 中最常用的子程序有哪些 硕迪科技

在ABAQUS中&#xff0c;用户定义的子程序是一种重要的构件&#xff0c;可以将其插入到Abaqus分析中以增强该软件的功能和灵活性。这些子程序允许用户在分析过程中添加自定义材料模型、边界条件、初始化、加载等特定操作&#xff0c;以便更精准地模拟分析中的现象和现象。ABAQUS…

小研究 - MySQL 分区技术在海量系统日志中的应用

随着信息技术的飞速发展&#xff0c;系统的业务功能不断扩大&#xff0c;产生的日志与日俱增&#xff0c;导致应用软件的运行速度越来越慢&#xff0c;不能很好地满足用户对软件性能的需求。基于此&#xff0c;重点研究了 MySQL 分区技术在大数据量软件日志中的应用&#xff0c…

解决Vue+Element-UI 进行From表单校验时出现了英文提示问题

说明&#xff1a;该篇博客是博主一字一码编写的&#xff0c;实属不易&#xff0c;请尊重原创&#xff0c;谢谢大家&#xff01; 问题描述 在使用form表单时&#xff0c;往往会对表单字段进行校验&#xff0c;字段为必填项时会添加required属性&#xff0c;此时自定义rules规则…

伪原创小发猫怎么样【php源码】

大家好&#xff0c;小编为大家解答初学者自学python哪本书好的问题。很多人还不知道自学python需要什么基础&#xff0c;现在让我们一起来看看吧&#xff01; 火车头采集ai伪原创插件截图&#xff1a; 目前python可以说是一门非常火爆的编程语言&#xff0c;应用范围也非常的广…

Python web实战之Django的文件上传和处理详解

概要 关键词&#xff1a;Python Web开发、Django、文件上传、文件处理 今天分享一下Django的文件上传和处理。 1. 上传文件的基本原理 在开始深入讲解Django的文件上传和处理之前&#xff0c;先了解一下文件上传的基本原理。当用户选择要上传的文件后&#xff0c;该文件会被发…

C++动态规划经典试题解析之打家劫舍系列

1.前言 力扣上有几道与打家劫舍相关的题目,算是学习动态规划时常被提及的经典试题,很有代表性,常在因内大大小小的社区内看到众人对此类问题的讨论。 学习最好的方式便是归纳总结、借鉴消化,基于这个目的,本文对此类问题也做了讲解,在一些优秀思想的基础上添加了个人观…

网络安全进阶学习第十二课——SQL手工注入3(Access数据库)

文章目录 注入流程&#xff1a;1、判断数据库类型2、判断表名3、判断列名4、判断列数1&#xff09;判断显示位 5、判断数据长度6、爆破数据内容 注入流程&#xff1a; 判断数据库类型 ——> 判断表名 ——> 判断列名 ——> 判断列名长度 ——> 查出数据。 asp的网…

【flink】Checkpoint expired before completing.

使用flink同步数据出现错误Checkpoint expired before completing. 11:32:34,455 WARN org.apache.flink.runtime.checkpoint.CheckpointFailureManager [Checkpoint Timer] - Failed to trigger or complete checkpoint 4 for job 1b1d41031ea45d15bdb3324004c2d749. (2 con…

用excel格式书写的接口用例执行脚本

创建测试用例和测试结果集文件夹&#xff1a; excel编写的接口测试用例如下&#xff1a; 1 encoding 响应的编码格式。所测项目大部分是utf-8&#xff0c;有一个特殊项目是utf-8-sig 2 params 对应requests的params 3 data&#xff0c;对应requests的data 有些参数是动态的&a…

JVM分析工具JProfiler介绍及安装

目录 一、什么是JProfiler&#xff1f; 二、JProfiler 功能结构 1、分析代理 2、记录数据 3、快照 三、安装 一、什么是JProfiler&#xff1f; JProfiler是一个专业的工具&#xff0c;用于分析运行中的JVM内部发生的事情。当您的生产系统出现问题时&#xff0c;您可以…

Kotlin基础(十一):反射和注解

前言 本文主要讲解kotlin反射和注解。 Kotlin文章列表 Kotlin文章列表: 点击此处跳转查看 目录 1.1 kotlin反射 1.1.1 kotlin反射概念和常见使用场景 在Kotlin中&#xff0c;反射是一种能够在运行时动态地获取、检查和操作类、属性、方法等结构的能力。Kotlin为反射提供了一…

整数规划——第七章 分支定界算法

整数规划——第七章 分支定界算法 目前大部分整数规划商业软件如CPLEX&#xff0c;Gurobi和BARON等都是基于分枝定界算法框架的。 7.1 最优性条件和界 考虑下列一般线性整数规划问题&#xff1a; (IP) min ⁡ c T x , s . t . A x ≤ b , x ∈ Z n (7.1) \text{(IP)}\quad…

接口测试——postman接口测试(三)

目录 1. postman介绍与安装 2. postman发送get请求 3. postman发送post请求 1. postman介绍与安装 安装网址&#xff1a;Postman安装教程&#xff1a;留言找我要即可 2. postman发送get请求 import pymysql from flask import Flask,request# 这里是mysql的基本连接信息 c…

excel行转列

1.选中要转的内容&#xff0c;ctrlc 2.选择对应的大小&#xff0c;右击&#xff0c;点转置 3.ok

观察者模式——对象间的联动

1、简介 1.1、概述 在软件系统中&#xff0c;有些对象之间也存在类似交通信号灯和汽车之间的关系。一个对象的状态或行为的变化将导致其他对象的状态或行为也发生改变&#xff0c;它们之间将产生联动&#xff0c;正所谓“触一而牵百发”。为了更好地描述对象之间存在的这种一…

Cocos基本介绍

一、下载Dashboard Cocos Creator 3.8 手册 - 安装和启动 二、编辑器结构 1.资源管理器&#xff1a;显示了项目资源文件夹(assets)中的所有资源 2.场景编译器&#xff1a;用于展示和编辑场景中可是内容的工作区域 3.层级管理器&#xff1a;用树状列表的形式展示场景中的所有…

pytest测试框架之mark标记功能详细介绍

mark标记 ​ 在实际工作中&#xff0c;我们要写的自动化用例会比较多&#xff0c;也不会都放在一个py文件中&#xff0c;如果有几十个py文件&#xff0c;上百个方法&#xff0c;而我们只想运行当中部分的用例时怎么办&#xff1f; ​ pytest提供了一个非常好用的mark功能&…