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 -Ddocker 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 -Ddocker 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 -Ddocker 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 -Ddocker 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 ResolutionDependencies Resolved================================================================================================================================================Package                                Arch                             Version                         Repository                        Size
================================================================================================================================================
Installing:epel-release                           noarch                           7-11                            extras                            15 kTransaction Summary
================================================================================================================================================
Install  1 PackageTotal 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 transactionInstalling : epel-release-7-11.noarch                                                                                                     1/1Verifying  : epel-release-7-11.noarch                                                                                                     1/1Installed:epel-release.noarch 0:7-11Complete!
[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.25config file = /etc/ansible/ansible.cfgconfigured module search path = [u'/root/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']ansible python module location = /usr/lib/python2.7/site-packages/ansibleexecutable location = /usr/bin/ansiblepython 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: 1Now 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: 1Now 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: 1Now 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: 1Now 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.mzph.cn/news/28409.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

springboot调用webservice简便方式

此方法不建议在需要高并发或者是批量调用webservice接口时使用&#xff0c;比较吃内存。仅在管理系统后台中&#xff0c;或者是用户量少时可以采用此取巧方案。 直接上核心代码&#xff1a; package com.dhc.minboot.api;import org.slf4j.Logger; import org.slf4j.LoggerFa…

SQL笔记-正态分布函数(二)

在Oracle数据库中&#xff0c;并没有直接提供计算正态分布函数&#xff08;累积分布函数&#xff09;的内置函数。不过&#xff0c;你可以使用PL/SQL编程语言来实现一个自定义的正态分布函数。下面是一个简单的示例&#xff1a; CREATE OR REPLACE FUNCTION normdist(x NUMBER…

jmeter 二次开发详解

目录 背景&#xff1a; 自定义 BeanShell 功能 自定义请求编写&#xff08;Java Sampler&#xff09; 实现 Java Sampler 功能的两种方式 案例&#xff1a;使用 JavaSampler 重写 HTTP 的 POST 请求 自定义函数助手 背景&#xff1a; JMeter 是一个功能强大的性能测试工具…

The ‘kotlin-android-extensions‘ Gradle plugin is no longer supported.

Android使用kotlin开发&#xff0c;运行报错 The kotlin-android-extensions Gradle plugin is no longer supported. Please use this migration guide (https://goo.gle/kotlin-android-extensions-deprecation) to start working with View Binding (https://developer.an…

linux umask 详解

1. umask 定义 在 linux 系统中&#xff0c;umask 被定义在 /etc/profile 配置文件中&#xff0c;有一段 shell 脚本对 umask 是这么定义的。在 shell 会话输入命令&#xff1a; $ cat /etc/profile # 查看 /etc/profile 配置文件的内容 if [ $UID -gt 199 ] &&…

Codeforces の 动态规划

Codeforces Round 785 (Div. 2) - C. Palindrome Basis dp(9/100) 题目链接 思路&#xff1a;整数划分基础上加一个判断回文的条件 整数划分思路&#xff1a;背包容量为n&#xff0c;物品有体积为1~n n种&#xff0c;每种无数个&#xff0c;求使背包恰好装满的方案数——完全背…

Vue3中v-model在原生元素和自定义组件上的使用

目录 前言 一、原生元素上的用法 1. 输入框(input) 2. 多行文本域(textarea) 3. 单选按钮(radio) 4. 多选框(checkbox) 5. 下拉选择框(select) 二、自定义组件上的用法 1. 定义一个名为 modelValue 的 props 属性和一个名为 update:modelValue 的事件 2.使用一个可…

工具箱:在线免费使用的文档工具:(PDF转换,图片压缩等)

这些都是博主亲自使用过的&#xff0c;可以使用。 PDF转换器&#xff1a; http://www.pdfdo.com/ 图片压缩&#xff1a; 免费在线图片/视频压缩工具 | 图片压缩 | 免费 JPG PNG GIF 图像压缩 (yalijuda.com)

网络编程 tcp udp http编程流程 网络基础知识

讲解 网络基础知识网络编程tcp编程流程图示理解bind和accept函数理解监视套接字和链接套接字理解linux和window下的编程实现tcp特点 udp编程流程图示理解udp特点 http编程流程图示理解编程实现-网站服务器 网络基础知识 OSI分层&#xff1a;应用层 表示层 会话层 传输层 网络层…

springBoot集成caffeine,自定义缓存配置 CacheManager

目录 springboot集成caffeine Maven依赖 配置信息&#xff1a;properties文件 config配置 使用案例 Caffeine定制化配置多个cachemanager springboot集成redis并且定制化配置cachemanager springboot集成caffeine Caffeine是一种基于服务器内存的缓存库。它将数据存储在…

96 | Python 小项目—— 学生成绩管理系统

文章目录 项目概述功能点2. 登录界面3. 主页面4. 数据录入界面5. 数据删除界面6. 数据修改界面7. 数据查询界面8. 成绩排名界面9. 成绩分析界面10. 学生信息查询界面11. 运行和测试总结项目概述 学生成绩管理系统是一个简单的学生课程管理系统,旨在帮助学校或教育机构轻松管理…

【MongoDB】解决ProxmoxVE下CentOS7虚拟机安装MongoDB6后启动失败的问题

目录 安装步骤&#xff1a; 2.1 配置yum源 2.2 安装MongoDB 2.3 启 动MongoDB ProxmoxVE上新装的CentOS7.4虚拟机&#xff0c;安装MongoDB6。 安装步骤&#xff1a; 2.1 配置yum源 # 创建mongodb yum源&#xff08;https://www.mongodb.com/docs/manual/tutorial/insta…

clickhouse调研报告2

由Distributed表发送分片数据 clickhouse分区目录合并 clickhouse副本协同流程 clickhouse索引查询逻辑 clickhouse一级索引生成逻辑(两主键) clickhouse的data目录下包含如下目录: [root@brfs-stress-01 201403_10_10_0]# ll /data01/clickhouse/data total 4 drwxr-x---…

【set】个人练习-Leetcode-817. Linked List Components

题目链接&#xff1a;https://leetcode.cn/problems/linked-list-components/description/ 题目大意&#xff1a;给出一个vector<int> nums&#xff0c;其中有一些数字。再给出一个链表的头指针head&#xff0c;链表内的元素各不相同。如果链表中有某一段&#xff08;长…

【Vue3】插槽全家桶

插槽&#xff08;Slots&#xff09;是 Vue.js 框架中的一个功能&#xff0c;允许在组件内部预留一些可替换的内容。通过插槽&#xff0c;可以给父组件填充模板代码&#xff0c;让父组件向子组件传递自定义的内容&#xff0c;以便在子组件中进行展示或处理。 1. 匿名插槽 Son.…

PostgreSql 参数配置

一、访问控制参数配置 https://xiaosonggong.blog.csdn.net/article/details/124264877 二、数据库参数配置 2.1 概述 PostgreSQL 的参数配置参数是在 postgresql.conf 文件中集中管理的&#xff0c;类似于 Oracle 的 pfile 文件&#xff0c;除此之外&#xff0c;PostgreSQL…

【HBZ分享】ES中的Reindex重建索引

Reindex如何实现索引重建&#xff1f; 滚动索引 批量复制 Reindex存在的问题 如果新的索引没有提前创建好&#xff0c;并指定字段类型&#xff0c;那么重建后的新索引类型极有可能会和旧的索引不一致&#xff0c;因为ES他会推断类型&#xff0c;而推断错误率从实战来说那是…

Nginx反向代理服务配置和负载均衡配置

nginx反向代理服务配置 node1&#xff1a;128 node2&#xff1a;135 node3&#xff1a;130 node4&#xff1a;132 node2、node3、node4已安装nginx nginx安装可查看https://blog.csdn.net/HealerCCX/article/details/132089836?spm1001.2014.3001.5502 [rootnode3 ~]# yum i…

初次使用GPU云服务器

前言&#xff1a; 在体验了GPU云服务器&#xff08;GPU Cloud Computing&#xff0c;GPU&#xff09;后&#xff0c;我认为这是一个非常强大的弹性计算服务。它为深度学习、科学计算、图形可视化、视频处理等多种应用场景提供了强大的GPU算力&#xff0c;能够满足各类用户的计算…

机器人静力学与刚度模型学习笔记

总算进行到刚度模型了。。。 ❤ 2023.8.6 ❤ 机器人静力学 学习资料 →→→【4-10机器人的静力分析】 机器人末端广义力 F [ f m ] [ f x f y f z m x m y m z ] F\left[\begin{matrix}f\\m\\\end{matrix}\right]\left[\begin{matrix}f_x\\f_y\\f_z\\m_x\\m_y\\m_z\\\end{…