广西网站建设哪家好,如何利用国外网站做自媒体,深圳整装装修公司排名,厦门高端网站建设公司目录 ansible-playbook 基础介绍1.YAML三板斧2. ansible playbook 安装apache 示例案例 全网备份 实时备份环境规划目录规划base.yamlrsync.yamlnfs.yamlsersync.yamlweb.yamlmail.yamlansible-playbook 基础介绍 playbook是由一个或多个模块组成的#xff0c;使用多个不同的模… 目录 ansible-playbook 基础介绍1.YAML三板斧2. ansible playbook 安装apache 示例案例 全网备份 实时备份环境规划目录规划base.yamlrsync.yamlnfs.yamlsersync.yamlweb.yamlmail.yaml ansible-playbook 基础介绍 playbook是由一个或多个模块组成的使用多个不同的模块完成一件事情。playbook通过yaml语法识别描述的状态文件。扩展名是yaml 1.YAML三板斧 缩进 YAML使用一个固定的缩进风格表示层级结构,每个缩进由两个空格组成, 不能使用tabs冒号 以冒号结尾的除外其他所有冒号后面所有必须有空格。短横线 表示列表项使用一个短横杠加一个空格。多个项使用同样的缩进级别作为同一列表。安装httpd服务-playbook 1.安装 2.配置 3.启动2. ansible playbook 安装apache 示例 [rootm01 ansible_playbook]# vim webserver.yaml
- hosts: webtasks:- name: Install Httpd Serveryum: namehttpd,httpd-tools stateinstalled- name: Configgure Httpd Servercopy: src./file/httpd.conf dest/etc/httpd/conf/httpd.confnotify: Resart Httpd Server- name: Start Httpd Serverservice: namehttpd statestarted enabledyeshandlers:- name: Resart Httpd Serverservice: namehttpd staterestarted 案例 全网备份 实时备份 环境规划 角色外网IP(NAT)内网IP(LAN)部署软件m01eth0:10.0.0.61eth1:172.16.1.61ansiblebackupeth0:10.0.0.41eth1:172.16.1.41rsyncnfseth0:10.0.0.31eth1:172.16.1.31nfs、Sersyncweb01eth0:10.0.0.7eth1:172.16.1.7httpd目录规划 [rootm01 ansible_playbook]# pwd
/etc/ansible/ansible_playbook
[rootm01 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 [rootm01 ansible_playbook]# vim base.yaml
- hosts: alltasks:- name: clear yum.repos.dfile: path/etc/yum.repos.d/ stateabsent - name: Create yum.repos.dfile: path/etc/yum.repos.d/ statedirectory - name: Install Base Reposget_url: urlhttp://mirrors.aliyun.com/repo/Centos-7.repo dest/etc/yum.repos.d/CentOS-Base.repo - name: Install Epel Reposget_url: urlhttp://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: namersync,nfs-utils stateinstalled- name: Create Group WWWgroup: namewww gid666- name: Create User WWWuser: namewww uid666 group666 create_homeno shell/sbin/nologin- name: Create Rsync_Client_Passcopy: content1 dest/etc/rsync.pass mode600- name: Create Sripts Directoryfile: path/server/scripts/ recurseyes statedirectory - name: Push Scriptscopy: src./scripts/rsync_backup_md5.sh dest/server/scripts/- name: Crontable Scriptscron: namebackup scripts hour01 minute00 job/usr/bin/bash /server/scripts/rsync_backup_md5.sh /dev/nullrsync.yaml [rootm01 ansible_playbook]# cat rsync.yaml
- hosts: backuptasks:- name: Installed Rsync Serveryum: namersync,mailx stateinstalled- name: configure Rsync Servercopy: src/etc/ansible/ansible_playbook/conf/rsyncd.conf dest/etc/rsyncd.confnotify: Restart Rsync Server- name: Create Virt Usercopy: contentrsync_backup:1 dest/etc/rsync.password mode600- name: Create Datefile: path/data statedirectory recurseyes ownerwww groupwww mode755- name: Create Backupfile: path/backup statedirectory recurseyes ownerwww groupwww mode755- name: Start RsyncServerservice: namersyncd statestarted enabledyes- name: Push Check Scriptscopy: src./scripts/rsync_check_backup.sh dest/server/scripts/- name: Crond Check Scriptscron: namecheck scripts hour05 minute00 job/usr/bin/bash /server/scripts/rsync_check_backup.sh /dev/nullhandlers:- name: Restart Rsync Serverservice: namersyncd staterestarted nfs.yaml [rootm01 ansible_playbook]# cat nfs.yaml
- hosts: nfstasks:- name: Installed Nfs Serveryum: namenfs-utils stateinstalled- name: Configure Nfs Servercopy: src./conf/exports dest/etc/exportsnotify: Restart Nfs Server- name: Create Share Datafile: path/data statedirectory recurseyes ownerwww groupwww mode755- name: Start Nfs Serverservice: namenfs-server statestarted enabledyeshandlers:- name: Restart Nfs Serverservice: namenfs-server staterestarted sersync.yaml [rootm01 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 [rootm01 ansible_playbook]# cat web.yaml
- hosts: webtasks:- name: Mount NFS Server Share Datemount: src172.16.1.31:/data path/data fstypenfs optsdefaults statemounted- name: Install Httpd Phpyum: namehttpd,php stateinstalled- 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: namehttpd statestarted enabledyeshandlers:- name: Restart Httpdservice: namehttpd staterestarted mail.yaml [rootm01 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