Linux——Ansible 快速入门
来自:入门小站
Ansible是一款简单的运维自动化工具,只需要使用ssh协议连接就可以来进行系统管理,自动化执行命令,部署等任务。
Ansible的优点
不需要安装客户端,不需要运行服务 使用python开发的一套自动执行任务的模块 playbook采用yaml配置,结构清晰
Ansible的组成结构
Ansible:核心命令工具,一次性或临时性执行的操作都由该工具执行 Ansible playbook:任务剧本(又称任务集),编排定义Ansible任务集的配置文件,由Ansible执行,格式是 yaml
Inventory:Ansible管理的主机,在 /etc/ansible/hosts
中配置Modules:Ansible执行命令的功能模块,Ansible2.3版本为止,共有1039个模块。还可以自定义模块。 Plugins:插件,模块功能的补充,常有连接类型插件,循环插件,变量插件,过滤插件,插件功能用的较少。 API:提供给第三方程序调用的应用程序编程接口。
Ansible常用的功能模块
命令模块
command
shell
文件模块
copy
fetch
file
安装模块
yum
服务模块
service
挂载模块
mount
定时任务
cron
用户模块
group
user
压缩解压
unarchive
Ansible安装
> yum install ansible -y
配置主机
> vim /etc/ansible/hosts
[web]
192.168.2.10 ansible_ssh_port=22 ansible_ssh_user=rumenz ansible_ssh_pass="123456"
192.168.2.11 ansible_ssh_port=22 ansible_ssh_user=rumenz ansible_ssh_pass="123456"
我们定义了一个
web
组(可以加很多主机),Ansible
默认使用的是ssh
协议,指定好端口,账号,密码就可以了。除了使用账号,密码的形式配置,我们也可以用秘钥,后面访问。测试
> ansible web -m ping
web
就是上面我们定义的分组,-m
我后面指定模块,这里我们使用ping
模块,用于查看主机是否网络可达。使用Ansible
执行pwd
命令
> ansible web -m shell -a "pwd"
这里我们使用的是
shell
模块,-a
后面跟上需要执行的shell
命令使用Ansible
查看web
分组下nginx
服务是否在运行
> ansible web -m shell -a "ps -ef | grep nginx"
使用Ansible
简单批量安装redis
> ansible web -m shell -a "yum install redis -y"
注意复杂的软件安装,需要编写
Ansible playbook
配置文件,更加灵活。官方站点:www.linuxprobe.com
Linux命令大全:www.linuxcool.com
刘遄老师QQ:5604241
Linux技术交流群:2261840
(新群,火热加群中……)
想要学习Linux系统的读者可以点击"阅读原文"按钮来了解书籍《Linux就该这么学》,同时也非常适合专业的运维人员阅读,成为辅助您工作的高价值工具书!
阅读原文 最新评论
推荐文章
作者最新文章
你可能感兴趣的文章
Copyright Disclaimer: The copyright of contents (including texts, images, videos and audios) posted above belong to the User who shared or the third-party website which the User shared from. If you found your copyright have been infringed, please send a DMCA takedown notice to [email protected]. For more detail of the source, please click on the button "Read Original Post" below. For other communications, please send to [email protected].
版权声明:以上内容为用户推荐收藏至CareerEngine平台,其内容(含文字、图片、视频、音频等)及知识版权均属用户或用户转发自的第三方网站,如涉嫌侵权,请通知[email protected]进行信息删除。如需查看信息来源,请点击“查看原文”。如需洽谈其它事宜,请联系[email protected]。
版权声明:以上内容为用户推荐收藏至CareerEngine平台,其内容(含文字、图片、视频、音频等)及知识版权均属用户或用户转发自的第三方网站,如涉嫌侵权,请通知[email protected]进行信息删除。如需查看信息来源,请点击“查看原文”。如需洽谈其它事宜,请联系[email protected]。