做网站项目时 需求分析的内容,郑州市惠济区建设局网站,网站建设全包哪家便宜,做暧暖的免费网站自动化运维Devops-Ansible
Ansible是新出现的自动化运维工具#xff0c;基于Python 开发#xff0c;集合了众多运维工具#xff08;puppet 、cfengine、chef、func、fabric#xff09;的优点#xff0c;实现了批量系统配置 、批量程序部署、批量运行命令 等功能。Ansible…自动化运维Devops-Ansible
Ansible是新出现的自动化运维工具基于Python 开发集合了众多运维工具puppet 、cfengine、chef、func、fabric的优点实现了批量系统配置 、批量程序部署、批量运行命令 等功能。Ansible架构相对比较简单仅需通过SSH 连接客户机 执行任务即可
测试环境 操作系统版本 IP地址 主机名 Centos7.6 192.168.68.133 manage Centos7.6 192.168.68.134 node01 Centos7.6 192.168.68.135 node02 Ansible常用模块 Ansible模块共计3387个
Ansible执行命令的结果颜色含义
绿色命令执行成功但是状态没有变化(软件已经安装过)
黄色命令执行成功状态发生改变(首次安装)
紫色warning警告信息ansible提升有更合适的用法
红色命令错误执行失败
蓝色详细的执行过程
Command模块
Command是ansible默认的末流也就是默认指定 -m -command
Command模块执行命令只支持简单命令执行不得使用变量(%HOME),不得出现特殊符号、、|、;、
ansible node01 -m command -a free -m ansible node01 -a free -m ansible node01 -a touch /opt/test001.log 获取负载信息
ansible node01 -a uptime 备份一份日志
ansible node01 -a cp /opt/test001.log /var/log chdir/
ansible node01 -a ls -l /var/log chdir/ 如果文件夹不存在则不执行操作
ansible node01 -a cp /opt/tt/test001.log /var/log chdir/ removes/opt/ Shell模块
Shell模块可以在linux上执行任何复杂的命令
使用重定向符号创建文件
ansible node01 -m shell -a date /opt/datetest01.log
ansible node01 -m shell -a cat /opt/datetest01.log chdir/ 过滤mysql进程信息
ansible node01 -m shell -a ps -ef|grep mysql ansible node01 -m shell -a date %F %T /opt/datetest01.log
一条命令执行多个命令1、创建文件夹 2、生成sh脚本文件 3、赋予脚本可执行权限 4、执行脚本
ansible node01 -m shell -a mkdir /opt/ansibletest/;echo ps -ef /opt/ansibletest/pstest.sh;chmod x /opt/ansibletest/pstest.sh;bash /opt/ansibletest/pstest.sh
忽略warning信息
ansible node01 -m shell -a mkdir /opt/ansibletest/;echo ps -ef /opt/ansibletest/pstest.sh;chmod x /opt/ansibletest/pstest.sh;bash /opt/ansibletest/pstest.sh; warnfalse
Copy模块
Copy模式是远程推送数据模块只能把数据推送给节点主机无法拉取数据到本地。
Manage-Node Node!- Manage 简单发送文件
src源文件绝对路径 dest目的路径
ansible node01 -m copy -a src/opt/cpu_per.sh dest/opt/
发送文件并修改文件权限
ansible node01 -m copy -a src/opt/linux_Inspection.sh dest/opt/linux_Inspection.sh mode700
创建一个备份文件(若目标文件内存不同另外生成加上时间戳)
ansible node01 -m copy -a src/opt/cpu_per.sh dest/opt/ backupyes 将指定数据写入远程文件中
覆盖原有内容
ansible node01 -m copy -a contenthello word dest/opt/test001.log
ansible node01 -m shell -a cat /opt/test001.log 开启备份
ansible node01 -m copy -a contenthello word dest/opt/test001.log backupyes 复制文件夹
拷贝/opt/下所有内容至目标虚拟机
ansible node01 -m copy -a src/opt/ dest/opt/copyDemo
拷贝/opt整个目录到目标虚拟机
ansible node01 -m copy -a src/opt dest/opt/copyDemo
File模块
File模块用于创建文档、目录数据、及文件、目录权限修改
文档帮助ansible-doc -s file
创建文件
ansible node01 -m file -a path/opt/ansibleTest.log statetouch
修改文件属性并设定权限
ansible node01 -m file -a path/opt/linux-ansible.log statetouch owneradm groupadm mode700 创建文件夹
ansible node01 -m file -a path/opt/ansibleDemo statedirectory
创建软连接文件
ansible node01 -m file -a src/opt/ansibleTest.log dest/opt/ansibleDemo/ansibleTest.log statelink
强制创建软连接文件
ansible node01 -m file -a src/opt/ansible1234 dest/opt/ansibleDemo/ansibleTest123.log statelink forceyes
Ping模块 ansible node01 -m ping ansible all -m ping Script模块
将本地脚本在远程节点并执行
ansible node01 -m script -a /opt/cpu_per.sh 查看命令执行详细过程
ansible node01 -vvvv -m script -a /opt/cpu_per.sh