当前位置:网站首页>ansible安装与使用
ansible安装与使用
2022-07-02 04:46:00 【浮沫*】
简介:ansible是新出现的自动化运维工具,基于Python开发,集合了众多运维工具(puppet、cfengine、chef、func、fabric)的优点,实现了批量系统配置、批量程序部署、批量运行命令等功能。
本实验由三台主机进行测试,其中一台作为管理机,另外两台被管主机
文章目录
一、ansible安装
1.1 安装epel扩展源
yum install -y epel-release.noarch
1.2 安装ansible
yum install -y ansible

查看ansinle版本
安装完成后,已经多出很多ansible命令了
二、配置主机
2.1 配置hosts文件
添加另外两台主机信息
vi /etc/ansible/hosts

执行ansible命令,其实这种情况把密码明文形式写在配置文件了,不适用
ansible 10.49.33.58 -m ping

第二种配置文件仅一个ip,执行命令要输入一边密码,多主机维护时不方便
ansible 10.49.33.58 -m ping -k
输入密码
第三种情况,可以生成密钥管理,不用输入密码,管理方便
生产密钥
ssh-keygen

生成的密钥默认放在/root/.ssh/
ll /root/.ssh

2.2 管理密钥
id_rsa是私钥
id_rsa.pub是公钥,需要把公钥发送给被管主机
使用模式:
ssh-copy-id [-i [identity_file] ] [[email protected]]machine
-i:指定公钥文件
把本地的ssh公钥文件安装到远程主机对应的账户下:
ssh-copy-id [email protected]
ssh-copy-id -i ~/.ssh/id_rsa.pub [email protected]
ssh-copy-id -i /root/.ssh/id_rsa.pub [email protected]10.49.33.58

执行成功之后,我们在目标机器上查看/root/.ssh目录已经生成,并且多了一个名为authorized_keys的文件,里面保存的正是原机器上ssh-keygen生成的id_rsa.pub的内容
按照系统提示尝试登录10.49.33.58
ssh [email protected]10.49.33.58
直接进入,不再需要密码
同理,把公钥传到10.49.33.59中
ssh-copy-id -i /root/.ssh/id_rsa.pub [email protected]10.49.33.59
公钥认证的相关操作配置完成,可以通过ansible主机免密码连接到这些主机,极大的提高了安全性
2.3 被管主机分组
还可以对不同主机进行分组,默认配置文件也有提示
ansible test -m ping

至此,简单的ansible搭建管理完成
三、ansible组成介绍
3.1 查看ansible目录文件
tree /etc/ansible/
/etc/ansible/
├── ansible.cfg # 配置文件
├── hosts # 主仓库 用来存储需要管理的远程主机的相关信息
└── roles # 存放角色的目录
3.2 Ansible命令参数详解
Ansible命令语法如下:
ansible [-i 主机文件] [-f 批次] [组名] [-m 模块名称] [-a 模块参数]
Ansible详细参数如下:
-i inventory_file——指定了主机文件,如果不指定,则默认为/etc/ansible/hosts文件,在主机文件中,定义了Ansible要控制的主机IP或域名,及其用户、密码
-f 10——表示指定开启同步进程的个数
-m module——表示Ansible要调用的模块
-a ——指定模块的参数,可以是命令等等
-sudo ——表示使用ansible获得sudo权限
-k ——表示ansible使用的SSH密码
-u username——表示指定Ansible执行的用户
-C —— 表示命令测试
3.3 ansible模块功能查看
Ansible的模块有很多,查看所有ansible的模块,使用命令:
ansible-doc -l

有非常多的模块,左边的是模块名称,右边的是对模块功能的描述
详细查看一个模块的功能,并且查看其参数,可以执行命令:
ansible-doc -s [模块名]

3.4 hosts文件
hosts文件一般存放我们的被管理主机信息。主机列表清单,也叫Inventory。所有被管理的主机都需要定义在该文件中。如果不想使用默认清单的话可以用-i选项指定自定义的清单文件,防止多人混合使用一个主机清单。如果没有定义在主机列表文件中,执行命令会提示“No hosts matched”
谢谢
边栏推荐
- Mysql database learning
- 解析少儿编程中的动手搭建教程
- Lm09 Fisher inverse transform inversion mesh strategy
- DC-1靶场搭建及渗透实战详细过程(DC靶场系列)
- Learn AI safety monitoring project from zero [attach detailed code]
- Deep understanding of lambda expressions
- Common errors of dmrman offline backup
- Binary tree problem solving (2)
- Rhcsa --- work on the third day
- Let正版短信测压开源源码
猜你喜欢
![[C language] basic learning notes](/img/d2/1aeb2d37d97b9cfe4b21aa3ac37645.png)
[C language] basic learning notes
![[Yu Yue education] autumn 2021 reference materials of Tongji University](/img/50/5136359b89a5d047fe648637643ad0.jpg)
[Yu Yue education] autumn 2021 reference materials of Tongji University

Win10 disk management compressed volume cannot be started

Why can't you remember when reading? Why can't you remember- My technology learning methodology
![[understand one article] FD_ Use of set](/img/57/276f5ef438adee2cba31dceeabb95c.jpg)
[understand one article] FD_ Use of set

Pytest learning ----- pytest Interface Association framework encapsulation of interface automation testing

Interview question: do you know the difference between deep copy and shallow copy? What is a reference copy?

Getting started with pytest -- description of fixture parameters

Analyze the space occupied by the table according to segments, clusters and pages

Thinkphp内核工单系统源码商业开源版 多用户+多客服+短信+邮件通知
随机推荐
Pytoch --- use pytoch for image positioning
Mysql database learning
10 minute quick start UI automation ----- puppeter
Getting started with pytest -- description of fixture parameters
Summary of common string processing functions in C language
Shenzhen will speed up the cultivation of ecology to build a global "Hongmeng Oula city", with a maximum subsidy of 10million yuan for excellent projects
win10 磁盘管理 压缩卷 无法启动问题
CorelDRAW graphics suite2022 free graphic design software
geotrust ov多域名ssl證書一年兩千一百元包含幾個域名?
Pytoch --- use pytoch to predict birds
【毕业季·进击的技术er】年少有梦,何惧彷徨
阿里云polkit pkexec 本地提权漏洞
C language practice - binary search (half search)
Three years of experience in Android development interview (I regret that I didn't get n+1, Android bottom development tutorial
Introduction to Luogu 3 [circular structure] problem list solution
[graduation season · advanced technology Er] young people have dreams, why are they afraid of hesitation
C - derived classes and constructors
Typescript function details
Embedded-c language-9-makefile/ structure / Consortium
What methods should service define?