可以做简单小活动的网站,phpstudy 网站空白,施工企业工作分解结构,如何自建网站?#x1f468;#x1f393;博主简介 #x1f3c5;云计算领域优质创作者   #x1f3c5;华为云开发者社区专家博主   #x1f3c5;阿里云开发者社区专家博主 #x1f48a;交流社区#xff1a;运维交流社区 欢迎大家的加入#xff01; #x1f40b; 希望大家多多支… 博主简介   云计算领域优质创作者   华为云开发者社区专家博主   阿里云开发者社区专家博主 交流社区运维交流社区 欢迎大家的加入  希望大家多多支持我们一起进步 如果文章对你有帮助的话欢迎 点赞  评论  收藏 ⭐️ 加关注 文章目录 一、自动化运维1.1 什么是自动化运维1.2 运维自动化解决的问题1.3 自动化运维分类工具1.4 自动化运维工具对比 二、Ansible2.1 Ansible简介2.2 Ansible的优势2.3 Ansible的架构2.4 Ansible模式2.5 Ansible部署2.5.1 Ansible参数2.5.2 Ansible主机清单2.5.3 主机清单配置规则  三、相关文章 一、自动化运维 
1.1 什么是自动化运维 自动化运维是指将日常运维的、大量的重复性工作自动化把手工执行的工作通过梳理分析进行逻辑分解借助平台或工具转为自动化操作。自动化是IT运维工作的升华IT运维自动化不单纯是一个维护过程更是一个管理的提升过程是运维的更高层次也是未来的发展趋势。 
1.2 运维自动化解决的问题 项目整体工作效率提升   减少人为误操作   方便信息传递配置类信息聚合信息链更完整   事务留痕方便跟踪追述   运维工作更加轻松、灵动   提升运维工作价值管理更多资源更多服务对象  
1.3 自动化运维分类工具 系统安装PXECobbler  应用程序配置PuppetAnsibleSaltstack  命令执行与控制FabricFuncAnsible  程序发布git/svn(版本管理)Jenkins/Gitlab-runner(持续集成)   
1.4 自动化运维工具对比 
此处只对比PuppetAnsibleSaltstack 
PuppetSaltstackAnsible开发语言Ruby语言Python语言Python语言是否支持客户端有有salt-ssh无客户端无是否支持二次开发不支持支持支持通信加密标准的SSL加密AES加密OpenSSH平台支持AIX , BSD, HP-UX, Linux , Mac OSX , Solaris, WindowsBSD, Linux , Mac OS X , Solaris, WindowsAIX , BSD , HP-UX , Linux , Mac OS X , Solaris是否提供web UI是是商用提供配置文件语法Ruby语法格式YAMLYAML命令行执行不支持配置实现支持支持 
二、Ansible 
2.1 Ansible简介 Ansible是一款使用Python开发模块化依赖于ssh协议实现的自动化统一配置管理工具自动化主要体现在Ansible集成了丰富模块以及功能组件可以通过一个命令完成一系列的操作进而能减少重复性的工作和维护成本可以提高工作效率。 官网地址www.ansible.com 2.2 Ansible的优势 安装部署简单(主控端安装ansible不需要额外安装客户端) 基于ssh现有协议实现的 (1.3以上) Ansible没有守护进程不需要启动 日志集中在主控端方便错误排查 简单易用不需要有编程基础 通过模块实现功能强大 
2.3 Ansible的架构 1、主机清单Inventory定义Ansible需要操作主机的范围 
2、剧本Playbook Ansible的配置文件,将多个任务定义在剧本中由ansible自动执行 
3、核心模块Core Modules连接主机实现操作 它依赖于具体的模块来做具体的事情 
4、自定义模块Custom Modules根据自己的需求编写具体的模块 
5、连接插件Connection Plugins用于连接主机 用来连接被管理端 
6、插件Plugins完成模块功能的补充 
最重要的一点是Ansible是模块化的它所有的操作都依赖于模块。 
2.4 Ansible模式 
Ansible中有两种模式分别是ad-hoc模式和playbook模式 ad-hoc简而言之就是“临时命令”不会保存  playbook翻译过来就是剧本在文件中保存执行的流程  
Ansible与SaltStack对比: 相同点: 1.都是使用python语言开发的 2.都具有二次开发的特性 3.执行命令都支持Ad-hoc模式 (临时命令执行完就返回) 4.都可以通过YAML格式文件批量执行 5.返回的结果都是JSON数据便于后续处理 不同点: 1.Ansible部署更简单没有客户端而Saltstack有客户端 2.Saltstack的响应速度要比Ansible更快Ansible通过SSH协议实现Saltstack使用了ZeroMQ实现通信; 3.Ansible更加安全SSH加密传输 4.Saltstack对于Windows支持更友好Ansible通过Power Shell来管理Windows 5.Ansible维护简单没有客户端没有守护进程saltstack需要有Master和minion,主机要启动一个守护进程。 2.5 Ansible部署 
Ansible部署时直接使用阿里云的基础源与epel扩展源可以直接安装 
# 先拉取epel扩展源
wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo# 更新yum源
yum makecache fast# 安装Ansible
yum -y install ansible# 查看Ansible版本
[rootlocalhost ~]# ansible --versionansible 2.9.27config 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, Aug  7 2019, 00:51:29) [GCC 4.8.5 20150623 (Red Hat 4.8.5-39)]2.5.1 Ansible参数 
常用参数 
-m          #指定使用的模块名称不指定默认使用command模块
-a          #使用的模块参数模块的具体动作指定要执行的具体命令
--syntax-check      #验证语法不常用参数 
#不常用参数
--version   #ansible版本信息
-v          #显示详细信息
-i          #主机清单文件路径默认是在/etc/ansible/hosts
-k          #提示输入ssh密码而不使用基于ssh的密钥认证
-C          #模拟执行测试但不会真的执行
-T          #执行命令的超时
-f  		#一次返回几个结果ansible帮助命令 
ansible-doc 		#帮助命令 
ansible-doc -l   	#列出所以的模块
ansible-doc 模块名   #查看模块的详细信息
ansible-doc 模块名 -s  #查看模块的选项使用说明2.5.2 Ansible主机清单 
主机资产清单用于定义被管理主机的认证信息 例如ssh登录用户名、密码以及key相关信息。 
# 查看ansible配置文件路径
[rootlocalhost ~]# rpm -qc ansible
/etc/ansible/ansible.cfg
/etc/ansible/hosts主机清单位置默认是/etc/ansible/hosts ansible -i 指定主机清单 在ansible配置文件ansible.cfg中指定默认的主机清单文件文件路径/etc/ansible/ansible.cfg ansible.cfg常用配置解析 
[defaults]
#inventory       /etc/ansible/hosts      #主机列表配置文件
#library         /usr/share/my_modules/  #库文件存放目录
#remote_tmp      ~/.ansible/tmp          #临时py文件存放在远程主机目录
#local_tmp       ~/.ansible/tmp          #本机的临时执行目录
#forks           5                       #默认并发数
#sudo_user       root                    #默认sudo用户
#ask_sudo_pass  True                     #每次执行是否询问sudo的ssh密码
#ask_pass       True                     #每次执行是否询问ssh密码
#remote_port     22                      #远程主机端口
host_key_checking  False                 #跳过检查主机指纹
log_path  /var/log/ansible.log           #ansible日志#普通用户提权操作
[privilege_escalation]
#becomeTrue
#become_methodsudo
#become_userroot
#become_ask_passFalse如果不配置host_key_checking  和 log_path会导致报错 不配置host_key_checking 会导致执行ansible命令的时候报错 
172.16.11.209 | FAILED | rc-1 
Using a SSH password instead of a key is not possible because Host Key checking is enabled and sshpass does not support this.  Please add this hosts fingerprint to your known_hosts file to manage this host.配置 log_path 是为了更好的排查问题所在 
2.5.3 主机清单配置规则 
在/etc/ansible/hosts中配置 
主机: 
1.可以使用主机名(域名)或IP地址 
2.支持主机名通配以及正则表达式 
3.支持指定主机定义不同的变量包括密码端口号用户等等 
1单主机配置 
# 方式一 ip  端口  用户名  用户密码
[rootlocalhost ansible]# vim /etc/ansible/hosts 
[web01]
172.16.11.209 ansible_ssh_port22 ansible_ssh_userroot ansible_ssh_pass123123
[web02]
172.16.10.232 ansible_ssh_port22 ansible_ssh_userroot ansible_ssh_pass123123# 测试ansible 主机名 -m 指定模块
[rootlocalhost ansible]# ansible web01 -m ping
172.16.11.209 | SUCCESS  {ansible_facts: {discovered_interpreter_python: /usr/bin/python}, changed: false, ping: pong
}[rootlocalhost ansible]# ansible web02 -m ping
172.16.10.232 | SUCCESS  {ansible_facts: {discovered_interpreter_python: /usr/bin/python}, changed: false, ping: pong
}如果遇到以下报错 在ansible.cfg配置文件中开启这两个将注释注销了 host_key_checking  False #跳过检查主机指纹 log_path  /var/log/ansible.log #ansible日志 # 方式二 ip  用户密码
[rootlocalhost ansible]# vim /etc/ansible/hosts 
[web01]
172.16.11.209 ansible_ssh_pass123123
[web02]
172.16.10.232 ansible_ssh_pass123123# 测试ansible 主机名 -m 指定模块
[rootlocalhost ansible]# ansible web01 -m ping
172.16.11.209 | SUCCESS  {ansible_facts: {discovered_interpreter_python: /usr/bin/python}, changed: false, ping: pong
}
[rootlocalhost ansible]# ansible web02 -m ping
172.16.10.232 | SUCCESS  {ansible_facts: {discovered_interpreter_python: /usr/bin/python}, changed: false, ping: pong
}#没有定义用户时默认使用当前登录用户2多主机配置 
#IP端口密码
[rootlocalhost ansible]# vim /etc/ansible/hosts 
[web]
172.16.11.209 ansible_ssh_port22 ansible_ssh_userroot ansible_ssh_pass123123
172.16.10.232 ansible_ssh_port22 ansible_ssh_userroot ansible_ssh_pass123123# 测试ansible 主机名 -m 指定模块
[rootlocalhost ansible]# ansible web -m ping
172.16.10.232 | SUCCESS  {ansible_facts: {discovered_interpreter_python: /usr/bin/python}, changed: false, ping: pong
}
172.16.11.209 | SUCCESS  {ansible_facts: {discovered_interpreter_python: /usr/bin/python}, changed: false, ping: pong
}主机组 
1.嵌套 [组名:children] 
2.对组定义变量 [组名:vars] 
#主机组变量主机密码
[rootlocalhost ansible]# vim /etc/ansible/hosts 
[web_group]
172.16.11.209
172.16.10.232[web_group:vars]
ansible_ssh_pass123123# 测试ansible 主机名 -m 指定模块
[rootlocalhost ansible]# ansible web_group -m ping
172.16.10.232 | SUCCESS  {ansible_facts: {discovered_interpreter_python: /usr/bin/python}, changed: false, ping: pong
}
172.16.11.209 | SUCCESS  {ansible_facts: {discovered_interpreter_python: /usr/bin/python}, changed: false, ping: pong
}#定义多组多组嵌套# webservers组包括两个子组[apache,nginx]
[rootlocalhost ansible]# vim /etc/ansible/hosts 
#定义总ip
[web_group]
172.16.11.209
172.16.10.232
172.16.10.129#apache有两台
[apache]
172.16.11.209
172.16.10.232#nginx有一台
[nginx]
172.16.10.129 ansible_ssh_passcsnginx123#定义密码
[apache:vars]
ansible_ssh_pass123123[web_group:children]
apache
nginx# 测试ansible 主机名 -m 指定模块
[rootlocalhost ansible]# ansible web_group -m ping
172.16.11.209 | SUCCESS  {ansible_facts: {discovered_interpreter_python: /usr/bin/python}, changed: false, ping: pong
}
172.16.10.232 | SUCCESS  {ansible_facts: {discovered_interpreter_python: /usr/bin/python}, changed: false, ping: pong
}
172.16.10.129 | SUCCESS  {ansible_facts: {discovered_interpreter_python: /usr/bin/python}, changed: false, ping: pong
}[rootlocalhost ansible]# ansible apache -m ping
172.16.11.209 | SUCCESS  {ansible_facts: {discovered_interpreter_python: /usr/bin/python}, changed: false, ping: pong
}
172.16.10.232 | SUCCESS  {ansible_facts: {discovered_interpreter_python: /usr/bin/python}, changed: false, ping: pong
}[rootlocalhost ansible]# ansible nginx -m ping
172.16.10.129 | SUCCESS  {ansible_facts: {discovered_interpreter_python: /usr/bin/python}, changed: false, ping: pong
}除了可以使用密码连接也可以配置秘钥实现免密登陆此时主机配置文件中不需要指定密码 
1.生成密钥对
[rootlocalhost ansible]# ssh-keygen2.推送公钥
[rootlocalhost ansible]# ssh-copy-id 172.16.11.209
[rootlocalhost ansible]# ssh-copy-id 172.16.10.232这时候配置hosts时就不需要指定密码了。 
三、相关文章 
文章标题文章链接Ansible自动化运维一简介及部署、清单https://liucy.blog.csdn.net/article/details/133769300Ansible自动化运维二ad-hoc 模式详解https://liucy.blog.csdn.net/article/details/133772023Ansible自动化运维三Playbook 模式详解https://liucy.blog.csdn.net/article/details/133899966Ansible自动化运维四jinja2 模板、Roles角色详解https://liucy.blog.csdn.net/article/details/133994509 文章转载自: http://www.morning.kmlmf.cn.gov.cn.kmlmf.cn http://www.morning.phxns.cn.gov.cn.phxns.cn http://www.morning.kpxzq.cn.gov.cn.kpxzq.cn http://www.morning.pjwml.cn.gov.cn.pjwml.cn http://www.morning.fznj.cn.gov.cn.fznj.cn http://www.morning.pxrfm.cn.gov.cn.pxrfm.cn http://www.morning.kzxlc.cn.gov.cn.kzxlc.cn http://www.morning.dnphd.cn.gov.cn.dnphd.cn http://www.morning.rfbt.cn.gov.cn.rfbt.cn http://www.morning.jjnry.cn.gov.cn.jjnry.cn http://www.morning.skrcn.cn.gov.cn.skrcn.cn http://www.morning.gpryk.cn.gov.cn.gpryk.cn http://www.morning.snlxb.cn.gov.cn.snlxb.cn http://www.morning.flxgx.cn.gov.cn.flxgx.cn http://www.morning.csnch.cn.gov.cn.csnch.cn http://www.morning.tbqbd.cn.gov.cn.tbqbd.cn http://www.morning.kaweilu.com.gov.cn.kaweilu.com http://www.morning.pclgj.cn.gov.cn.pclgj.cn http://www.morning.ndtmz.cn.gov.cn.ndtmz.cn http://www.morning.tjkth.cn.gov.cn.tjkth.cn http://www.morning.fpxsd.cn.gov.cn.fpxsd.cn http://www.morning.qgxnw.cn.gov.cn.qgxnw.cn http://www.morning.pkrtz.cn.gov.cn.pkrtz.cn http://www.morning.xyhql.cn.gov.cn.xyhql.cn http://www.morning.bpmnx.cn.gov.cn.bpmnx.cn http://www.morning.kfwrq.cn.gov.cn.kfwrq.cn http://www.morning.gfqj.cn.gov.cn.gfqj.cn http://www.morning.xsklp.cn.gov.cn.xsklp.cn http://www.morning.rmmz.cn.gov.cn.rmmz.cn http://www.morning.nqyfm.cn.gov.cn.nqyfm.cn http://www.morning.mhpkz.cn.gov.cn.mhpkz.cn http://www.morning.kzhxy.cn.gov.cn.kzhxy.cn http://www.morning.trkhx.cn.gov.cn.trkhx.cn http://www.morning.kzqpn.cn.gov.cn.kzqpn.cn http://www.morning.rcntx.cn.gov.cn.rcntx.cn http://www.morning.cczrw.cn.gov.cn.cczrw.cn http://www.morning.pjrql.cn.gov.cn.pjrql.cn http://www.morning.jkcpl.cn.gov.cn.jkcpl.cn http://www.morning.nxfwf.cn.gov.cn.nxfwf.cn http://www.morning.fnwny.cn.gov.cn.fnwny.cn http://www.morning.qpmmg.cn.gov.cn.qpmmg.cn http://www.morning.lpzyq.cn.gov.cn.lpzyq.cn http://www.morning.hgbzc.cn.gov.cn.hgbzc.cn http://www.morning.mkpkz.cn.gov.cn.mkpkz.cn http://www.morning.npqps.cn.gov.cn.npqps.cn http://www.morning.xhhzn.cn.gov.cn.xhhzn.cn http://www.morning.bgpb.cn.gov.cn.bgpb.cn http://www.morning.nrftd.cn.gov.cn.nrftd.cn http://www.morning.smsjx.cn.gov.cn.smsjx.cn http://www.morning.phxns.cn.gov.cn.phxns.cn http://www.morning.fnrkh.cn.gov.cn.fnrkh.cn http://www.morning.kpmxn.cn.gov.cn.kpmxn.cn http://www.morning.rgqnt.cn.gov.cn.rgqnt.cn http://www.morning.tpbhf.cn.gov.cn.tpbhf.cn http://www.morning.wqsjx.cn.gov.cn.wqsjx.cn http://www.morning.mzqhb.cn.gov.cn.mzqhb.cn http://www.morning.cyysq.cn.gov.cn.cyysq.cn http://www.morning.lgznc.cn.gov.cn.lgznc.cn http://www.morning.klcdt.cn.gov.cn.klcdt.cn http://www.morning.fdwlg.cn.gov.cn.fdwlg.cn http://www.morning.fcftj.cn.gov.cn.fcftj.cn http://www.morning.bnxfj.cn.gov.cn.bnxfj.cn http://www.morning.mjmtm.cn.gov.cn.mjmtm.cn http://www.morning.tqpnf.cn.gov.cn.tqpnf.cn http://www.morning.yhwyh.cn.gov.cn.yhwyh.cn http://www.morning.zcqtr.cn.gov.cn.zcqtr.cn http://www.morning.fdwlg.cn.gov.cn.fdwlg.cn http://www.morning.hkcjx.cn.gov.cn.hkcjx.cn http://www.morning.ryzgp.cn.gov.cn.ryzgp.cn http://www.morning.ygkq.cn.gov.cn.ygkq.cn http://www.morning.pttrs.cn.gov.cn.pttrs.cn http://www.morning.gyylt.cn.gov.cn.gyylt.cn http://www.morning.nkyqh.cn.gov.cn.nkyqh.cn http://www.morning.gktds.cn.gov.cn.gktds.cn http://www.morning.nkmw.cn.gov.cn.nkmw.cn http://www.morning.xdfkrd.cn.gov.cn.xdfkrd.cn http://www.morning.cbynh.cn.gov.cn.cbynh.cn http://www.morning.prkdl.cn.gov.cn.prkdl.cn http://www.morning.wnqbf.cn.gov.cn.wnqbf.cn http://www.morning.fzlk.cn.gov.cn.fzlk.cn