ansible-playbook 实战案例 全网备份 实时备份

目录

  • ansible-playbook 基础介绍
    • 1.YAML三板斧
    • 2. ansible playbook 安装apache 示例
  • 案例 全网备份 实时备份
    • 环境规划
    • 目录规划
    • base.yaml
    • rsync.yaml
    • nfs.yaml
    • sersync.yaml
    • web.yaml
    • mail.yaml

ansible-playbook 基础介绍

playbook是由一个或多个模块组成的,使用多个不同的模块,完成一件事情。
playbook通过yaml语法识别描述的状态文件。扩展名是yaml

1.YAML三板斧

  • 缩进
    • YAML使用一个固定的缩进风格表示层级结构,每个缩进由两个空格组成, 不能使用tabs
  • 冒号
    • 以冒号结尾的除外,其他所有冒号后面所有必须有空格。
  • 短横线
    • 表示列表项,使用一个短横杠加一个空格。
    • 多个项使用同样的缩进级别作为同一列表。
  • 安装httpd服务->playbook
    1.安装
    2.配置
    3.启动

2. ansible playbook 安装apache 示例

[root@m01 ansible_playbook]# vim  webserver.yaml
- hosts: webtasks:- name: Install Httpd Serveryum: name=httpd,httpd-tools state=installed- name: Configgure Httpd Servercopy: src=./file/httpd.conf dest=/etc/httpd/conf/httpd.confnotify: Resart Httpd Server- name: Start Httpd Serverservice: name=httpd state=started enabled=yeshandlers:- name: Resart Httpd Serverservice: name=httpd state=restarted

案例 全网备份 实时备份

环境规划

角色外网IP(NAT)内网IP(LAN)部署软件
m01eth0:10.0.0.61eth1:172.16.1.61ansible
backupeth0:10.0.0.41eth1:172.16.1.41rsync
nfseth0:10.0.0.31eth1:172.16.1.31nfs、Sersync
web01eth0:10.0.0.7eth1:172.16.1.7httpd

目录规划

[root@m01 ansible_playbook]# pwd
/etc/ansible/ansible_playbook
[root@m01 ansible_playbook]# tree
.
├── base.yaml
├── conf
│   ├── confxml.xml
│   ├── exports
│   ├── resolv.conf
│   ├── rsyncd.conf
│   └── web.yaml
├── file
│   └── sersync2.5.4_64bit_binary_stable_final.tar.gz
├── mail.yaml
├── nfs.yaml
├── rsync.retry
├── rsync.yaml
├── scripts
│   ├── rsync_backup_md5.sh
│   └── rsync_check_backup.sh
└── sersync.yaml3 directories, 14 files

base.yaml

[root@m01 ansible_playbook]# vim base.yaml
- hosts: alltasks:- name: clear yum.repos.dfile: path=/etc/yum.repos.d/ state=absent - name: Create yum.repos.dfile: path=/etc/yum.repos.d/ state=directory - name: Install Base Reposget_url: url=http://mirrors.aliyun.com/repo/Centos-7.repo dest=/etc/yum.repos.d/CentOS-Base.repo - name: Install Epel Reposget_url: url=http://mirrors.aliyun.com/repo/Centos-7.repo dest=/etc/yum.repos.d/epel.repo- name: Dns Client copy: src=./conf/resolv.conf dest=/etc/rsolv.conf- name: Install Rsync Nfs-Utilsyum: name=rsync,nfs-utils state=installed- name: Create Group WWWgroup: name=www gid=666- name: Create User WWWuser: name=www uid=666 group=666 create_home=no shell=/sbin/nologin- name: Create Rsync_Client_Passcopy: content='1' dest=/etc/rsync.pass mode=600- name: Create Sripts Directoryfile: path=/server/scripts/ recurse=yes state=directory - name: Push Scriptscopy: src=./scripts/rsync_backup_md5.sh dest=/server/scripts/- name: Crontable Scriptscron: name="backup scripts" hour=01 minute=00 job="/usr/bin/bash /server/scripts/rsync_backup_md5.sh &>/dev/null"

rsync.yaml

[root@m01 ansible_playbook]# cat rsync.yaml
- hosts: backuptasks:- name: Installed Rsync Serveryum: name=rsync,mailx state=installed- name: configure Rsync Servercopy: src=/etc/ansible/ansible_playbook/conf/rsyncd.conf dest=/etc/rsyncd.confnotify: Restart Rsync Server- name: Create Virt Usercopy: content='rsync_backup:1' dest=/etc/rsync.password mode=600- name: Create Datefile: path=/data state=directory recurse=yes owner=www group=www mode=755- name: Create Backupfile: path=/backup state=directory recurse=yes owner=www group=www mode=755- name: Start RsyncServerservice: name=rsyncd state=started enabled=yes- name: Push Check Scriptscopy: src=./scripts/rsync_check_backup.sh dest=/server/scripts/- name: Crond Check Scriptscron: name="check scripts" hour=05 minute=00 job="/usr/bin/bash /server/scripts/rsync_check_backup.sh &>/dev/null"handlers:- name: Restart Rsync Serverservice: name=rsyncd state=restarted

nfs.yaml

[root@m01 ansible_playbook]# cat nfs.yaml
- hosts: nfstasks:- name: Installed Nfs Serveryum: name=nfs-utils state=installed- name: Configure Nfs Servercopy: src=./conf/exports dest=/etc/exportsnotify: Restart Nfs Server- name: Create Share Datafile: path=/data state=directory recurse=yes owner=www group=www mode=755- name: Start Nfs Serverservice: name=nfs-server state=started enabled=yeshandlers:- name: Restart Nfs Serverservice: name=nfs-server state=restarted

sersync.yaml

[root@m01 ansible_playbook]# cat sersync.yaml
- hosts: nfstasks:- name: Scp Sersynccopy: src=./file/sersync2.5.4_64bit_binary_stable_final.tar.gz dest=/usr/local/sersync.tar.gz- name: Zipshell: cd /usr/local && tar xf sersync.tar.gz && mv GNU-Linux-x86 sersyncargs:creates: /usr/local/sersync- name: configure Sersynccopy: src=./conf/confxml.xml dest=/usr/local/sersync/confxml.xmlnotify: kill old sersync and restart new sersync- name: Start Sersyncshell: pgrep sersync;[ $? -eq 0 ] || /usr/local/sersync/sersync2 -dro /usr/local/sersync/confxml.xmlhandlers:- name: kill old sersync and restart new sersyncshell: pgrep sersync | xargs kill -9;/usr/local/sersync/sersync2 -dro /usr/local/sersync/confxml.xml

web.yaml

[root@m01 ansible_playbook]# cat web.yaml
- hosts: webtasks:- name: Mount NFS Server Share Datemount: src=172.16.1.31:/data path=/data fstype=nfs opts=defaults state=mounted- name: Install Httpd Phpyum: name=httpd,php state=installed- name: Configurl copycopy: src=./conf/httpd.conf dest=/etc/httpd/conf/httpd.confnotify: Restart Httpd- name: Unzip kaoshi.zipunarchive: src=./file/kaoshi.zip dest=/data/ creates=/data/index.html- name: Start Httpdservice: name=httpd state=started enabled=yeshandlers:- name: Restart Httpdservice: name=httpd state=restarted

mail.yaml

[root@m01 ansible_playbook]# cat mail.yaml
- import_playbook: base.yaml
- import_playbook: rsync.yaml
- import_playbook: nfs.yaml
- import_playbook: sersync.yaml
- import_playbook: web.yaml

转载于:https://www.cnblogs.com/chengkanghua/p/9645043.html

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/365731.shtml

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

相关文章

iview 级联选择组件_使用 element-ui 级联插件遇到的坑

需求描述【省市区三级联动】组件:Cascader 级联选择器后端需要所选中的地区的名字,如:[北京市, 北京市, 东城区]获取后端省市区具体列表的接口返回数据:// 省 - 参数1 [{value: 1,label: 北京市},... ] // 市 - 参数2 [{value: 1,…

python高级语法装饰器_Python高级编程——装饰器Decorator超详细讲解上

Python高级编程——装饰器Decorator超详细讲解(上篇)送你小心心记得关注我哦!! 进入正文全文摘要 装饰器decorator,是python语言的重要特性,我们平时都会遇到,无论是面向对象的设计或者是使用相…

深入理解CPU和异构计算芯片GPU/FPGA/ASIC (上篇)

王玉伟,腾讯TEG架构平台部平台开发中心基础研发组资深工程师,专注于为数据中心提供高效的异构加速云解决方案。目前,FPGA已在腾讯海量图片处理以及检测领域已规模上线。 随着互联网用户的快速增长,数据体量的急剧膨胀,…

jenkins-基础配置

一,配置远程连接服务器 系统管理 --> 系统设置 SSH remote hosts 二,设置docke的URL(设置jenkins构建镜像时候所连接的docker url ,参考 docker开启远程访问https://www.cnblogs.com/galsnag/articles/10069709.html&#xf…

JSF:直接从页面将参数传递给JSF操作方法,这是JavaEE 6+的一个不错的功能

Java企业版JavaEE 6中提供的JSF 2的一项不错的功能是,您可以将参数传递给任何操作组件(例如commandButton或commandLink组件)的操作方法。 基于此,您可以最大程度地减少托管bean中的方法数量。 另外,为了最小化在bea…

CCF CSP个人题解汇总

趁着这波考CCF热来骗一波访问量 祝自己免修算法RP 区域赛RP 1、2题汇总在这:https://www.cnblogs.com/QAQorz/p/9650890.html 201803-4 棋局评估(对抗搜索):https://www.cnblogs.com/QAQorz/p/9650828.html 201709-4 通信网络&…

海洋主题绘画_深圳举办风帆时代海洋绘画作品展,展出作品600余件

12月12日,第七届《风帆时代海洋绘画作品展》在位于蛇口邮轮中心3楼的深圳大学海洋文化科普教育基地举行开幕仪式。该项目得到深圳市宣传文化事业专项基金支持,由深圳大学海洋艺术研究中心主办,深圳市海洋文化艺术研究会承办。作为开幕式重要环…

不要被约束的意思_不要再奢望你会变得自律了丨“他律”比“自律”更重要

高三寒假和同学打赌一个假期做完400套卷子。否则给他1000元。。。然后每天早上六点晚上12点,春节也没过,最后做完了卷子,我也完成了自己的梦想!!!然而上面这个大神不是我,是我引用的一颗真实栗子…

一篇文章为你深度解析HTTPS 协议

一、前言 微信小程序如期发布,开发者在接入微信小程序过程中,会遇到以下问题: 小程序要求必须通过 HTTPS 完成与服务端通信,若开发者选择自行搭建 HTTPS 服务,那需要自行 SSL 证书申请、部署,完成 https …

Shadow DOM及自定义标签

参考链接:点我 一、什么是Shadow DOM Shadow DOM,直接翻译的话就是 影子 DOM,可以理解为潜藏在 DOM 结构中并且我们无法直接控制操纵的 DOM 结构。类似于下面这种结构 Shadow DOM 可以在浏览器中生成一个独立于DOM树之外的 DOM结构 二、Shado…

二进制逆向工程师_利用Ghidra逆向分析Go二进制程序(下篇)

(接上文)动态分配字符串结构在第一种情况下,字符串结构是在运行时创建的,为此,需要使用一系列汇编指令在字符串操作之前设置相应的结构。由于指令集的不同,不同的架构之间的结构也是不同的。让我们通过几个案例,来展示…

工艺路线和工序有差别吗_你知道吗?市政道路排水工程的主要工序施工工艺是什么...

易筑教育给排水课程火热招生中!张老师微信号:yizhujiaoyu999市政道排工程施工遵循的基本顺序是:先地下,后地上;先深后浅。按照这个顺序,正常的施工顺序为基础处理、排水管道(涵)施工(雨、污水)、道路基层(常…

如何:从Spring 4.0快速入门以构建简单的REST-Like API(演练)

如何:从Spring 4.0快速入门以构建简单的REST-Like API(演练) 关于使用Spring MVC创建Web API的另一篇教程。 不太复杂。 只是一个演练。 生成的应用程序将提供简单的API,将Mongo作为其持久性,并将通过Spring Security进…

01-Web客户端与服务器详解

1、CS与BS 软件使用方式上两种划分  C/S架构 Client/ServerPC客户端、服务器架构 特点:   在服务器当中就主要是一个数据库,把所有的业务逻辑以及界面都交给客户端完成 优点:   较为安全,用户界面丰富,用户体验好…

java之Hibenate中监听事件的重写和二级cache缓存

管理缓存和统计缓存 Cache cache sessionFactory.getCache(); //清除指定的News对象 cache.evictEntity(News.class, id); //清除所有的news对象 cache.evictEntityRegion(News.class); //清除指定id的news所关联的参与者集合属性 cache.evictColleciton("News.actors&q…

axi ps读写pl_PL读写DDR:Datamover能干什么

最近发现工程项目中一直在用AXI-DMA。这玩意儿搬数据倒是没问题,就是用axi-lite配置起来非常反人类。。。简单的办法其实是用datamover ip核。这个ip核能干嘛呢。准备写个文章解析一下。由于好多feature没用过,所以仅仅看文档可能理解有误,欢…

在10分钟内在新Mac中设置Java开发环境(更新)

这只是一个小的更新文章,它引用了2个较旧的条目( a , b ),我将它们合并为一个步骤,就像一步操作,并确保所有功能都在最新的MacOSX 10.9 Mavericks下工作 。 我主要针对的是初次尝试设置其环境的…

linux path 与 classpath 区别

linux path 与 classpath 区别 一、OS依据path中的路径信息来寻找可执行指令; 例如: cat /etc/profile 我们就可以在任意目录执行hadoop / hdfs / yarn / java 等相关命令了 export HADOOP_HOME/opt/hadoop/hadoop-2.6.0 export JAVA_HOME/home/jdk1.8.0…

开启9008端口进入深刷模式

除了前文所述,使用深刷线,还可以用命令开启9008端口,进入深刷模式。 adb reboot edl fastboot oem edl 这个在小米4c上测试ok 下面这个可能用于其他手机。 fastboot reboot emergency http://www.znsjw.net/nd.jsp?id19 小米绕BL锁9008工程…

Vue Webpack常见问题(持续更新)

常识 1.computed计算属性,使用的属性必需在data里面声明。 computed: {canLogin: function(){//注意这里的依赖的属性必需在data里面声明return this.name && this.password;} } Webpack问题 1.模块里面使用JSON.stringify和 typeof,报&#x…