王杰

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

10-AnsiblePlaybook-2综合实验

10-AnsiblePlaybook-2综合实验

 

1.环境规划 

角色 外网IP 内网IP 部署软件
manager01 39.98.50.126 eth0:172.26.73.199 ansible
backup 172.26.73.200 eth0:172.26.73.200 rsync
nfs   eth0:172.26.73.197 nfs、sersync
web 39.98.79.144 eth0:172.26.73.198 httpd

 

 

 

 

 

 

 

2.配置ansible对应的主机

[root@manager ~]# cat /etc/ansible/hosts
# This is the default ansible 'hosts' file.
#
# It should live in /etc/ansible/hosts
#
#   - Comments begin with the '#' character
#   - Blank lines are ignored
#   - Groups of hosts are delimited by [header] elements
#   - You can enter hostnames or ip addresses
#   - A hostname/ip can be a member of multiple groups

[backup]
172.26.73.200

[nfs]
172.26.73.197
[nfs:vars]
file_name=bgx_filename

[web]
172.26.73.198


# Ex 1: Ungrouped hosts, specify before any group headers.

## green.example.com
## blue.example.com
## 192.168.100.1
## 192.168.100.10

# Ex 2: A collection of hosts belonging to the 'webservers' group

## [webservers]
## alpha.example.org
## beta.example.org
## 192.168.1.100
## 192.168.1.110

# If you have multiple hosts following a pattern you can specify
# them like this:

## www[001:006].example.com

# Ex 3: A collection of database servers in the 'dbservers' group

## [dbservers]
## 
## db01.intranet.mydomain.net
## db02.intranet.mydomain.net
## 10.25.1.56
## 10.25.1.57

# Here's another example of host ranges, this time there are no
# leading 0s:

## db-[99:101]-node.example.com

3.检查对应的主机组和规划的IP是否一致

[root@manager ~]# ansible web --list-host
  hosts (1):
    172.26.73.198
[root@manager ~]# ansible backup --list-host
  hosts (1):
    172.26.73.200
[root@manager ~]# ansible nfs --list-host
  hosts (1):
    172.26.73.197
[root@manager ~]# ansible all --list-host
  hosts (3):
    172.26.73.197
    172.26.73.200
    172.26.73.198
[root@manager ~]# 

4.建立对应的目录站点,用于存放anisble-playbook 文件

[root@manager playbook]# mkdir -p /etc/ansible/playbook/files -p

5.编写基础模块的playbook

  0.基础仓库准备

  1.安装rsync

  2.安装nfs-utils

  3.创建www用户指定uid、gid

  4.准备rsync客户端密码文件

 

1.建立基础环境的yaml

[root@manager playbook]# cat base.yml 
---
- hosts: all
  remote_user: root

  tasks:
    - name: Add Base Yum Repository
      yum_repository:
        name: bash
        description: Bash Aliyun Repository
        baseurl: http://mirrors.aliyun.com/centos/$releasever/os/$basearch/
        gpgcheck: yes
        gpgkey: http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7

    #- name: Add Epel Yum Repository
    #  yum_repository:
    #    name: epel
    #    description: Epel Aliyun Repository
    #    baseurl: http://mirrors.cloud.aliyuncs.com/epel/7/$basearch
    #   gpgccheck: no

    - name: Installed Packages
      yum: name={{ item }} state=present
      with_items:
        - rsync
        - nfs-utils
        - inotify-tools

    - name: Stop Firewalld Service
      service: name=firewalld state=stopped enabled=no

    - name: Disable Selinux
      selinux: state=disabled

    - name: Configure SSH Server
      copy: src=./files/sshd.template dest=/etc/ssh/sshd_config
      notify: Restart SSHD Server

    - name: Add Group WWW
      group: name=www gid=666

    - name: Add User WWW
      user: name=www uid=666 group=www create_home=no shell=/sbin/nologin

    - name: Copy Rsync Backup Scripts
      copy: src=./files/push_data_rsync.sh dest=/server/scripts/ mode=755
      when: (ansible_hostname != "backup")

    - name: Configure Crontab
      cron:
        name: Rsync Backup
        minute: 00
        hour: 01
        job: /bin/bash /server/scripts/push_data_rsync.sh &>/dev/null
      when: (ansible_hostname != "backup")     
 
  handlers:
    - name: Restart SSHD Server
      service: name=sshd state=restarted
[root@manager playbook]# 

2.使用 ansible-playbook 检测语法,并进行模拟执行

检测语法
[root@manager playbook]# ansible-playbook --syntax-check base.yml 

playbook: base.yml

模拟执行
[root@manager playbook]# ansible-playbook -C base.yml 

 

6.编写应用模块 rsync 的 playbook

1.安装rsync

2.配置rsync

3.启动rsync

4.准备对应数据存储仓库 /backup/data 授权为 www

5.准备虚拟用户和密码文件,权限600

6.变更配置,重载服务

 

1.准备对应的配置文件存放至 /etc/ansible/ansible_playbook/files

[root@manager files]# cat rsyncd.conf.template 
uid = www
gid = www
port = 873
fake super = yes
use chroot = no
max connections = 200
timeout = 600
ignore errors
read only = false
list = false
auth users = rsync_backup
secrets file = /etc/rsync.passwd
log file = /var/log/rsyncd.log
######################################
[backup]
path = /backup

[data]
path = /data
[root@manager files]# 

 

2.编写rsync 安装的 yaml 语法

[root@manager playbook]# cat rsync.yml 
---
- hosts: rsync
  remote_user: root
  
tasks:
- name: Installed Rsync Server yum: name=rsync,mailx state=present - name: Configure Rsync Server copy: src={{ item.src }} dest={{ item.dest }} mode={{ item.mode }} with_items: - {src: './files/rsyncd.conf.template', dest: '/etc/rsyncd.conf' , mode: '0644'} - {src: './files/rsyncd.passwd.template', dest: '/etc/rsync.passwd' , mode: '0600'} notify: Restart Rsyncd Server - name: Create Directory file: path={{ item }} state=directory owner=www group=www mode=755 with_items: - /backup - /data - name: Service Rsync Server service: name=rsyncd state=started enabled=yes - name: Push Mail Configure copy: src=./files/check_client_data.sh dest=/server/scripts/ mode=755 - name: Check Scripts Crontab cron: name: 'Check Backup Scripts' minute: '*/10' hour: 05 job: /bin/bash /server/scripts/check_client_data.sh &>/dev/null - name: OutPut Rsync Status shell: netstat -lntp|grep rsync register: Rsync_Status ignore_errors: yes - name: Print Rsync Status debug: msg={{ Rsync_Status.stdout_lines }} ignore_errors: yes handlers: - name: Restart Rsyncd Server service: name=rsyncd state=restarted [root@manager playbook]#

 

[root@manager files]# cat /etc/ansible/playbook/files/push_data_rsync.sh
#!/usr/bin/bash
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin

Path=/backup
Host=$(hostname)
Addr=$(ifconfig eth0|awk 'NR==2{print $2}')
Date=$(date +%F)
Dest=${Host}_${Addr}_${Date}

#1、创建存储数据的目录
[ -d $Path/$Dest ] || mkdir -pv  $Path/$Dest

#2、打包文件并存储至对应的目录中
cd / && \
[ -f $Path/$Dest/sys.tar.gz ] || tar czf $Path/$Dest/sys.tar.gz etc/fstab etc/hosts var/spool/cron/root && \
[ -f $Path/$Dest/other.tar.gz ] || tar czf $Path/$Dest/other.tar.gz server/scripts/  && \

#3、增加标记
[ -f $Path/$Dest/flag ] || md5sum $Path/$Dest/*.tar.gz > $Path/$Dest/flag

#4、将数据推送到备份服务器
export RSYNC_PASSWORD=1
rsync -az $Path/ rsync@172.26.73.200::backup

#5、保留最近7天的数据
find $Path/ -type d -mtime +7 | xargs rm -rf

#模拟30天的日期
#for i in {1..30};do date -s "2019/12$i" && sh /server/scripts/push_data_rsync.sh;done
[root@manager files]# 

 

 

7.编写应用模块 nfs 的 playbook

  1.安装 nfs

  2.配置nfs

  3.启动nfs

  4.准备对应数据存储仓库 /data 授权为 www

  5.变更配置,重载服务

1.准备 nfs 配置文件 exports

[root@manager playbook]# cat files/exports.template 
{{ nfs_dir }} {{ nfs_ip }}(rw,sync,all_squash,anonuid={{ nfs_id }},anongid={{ nfs_id }})

 

2.编写 nfs 安装与配置的 yaml

[root@manager playbook]# cat nfs.yml 
---
- hosts: nfs
  remote_user: root
  vars:
    - nfs_dir: /data
    - nfs_ip: 172.26.73.0/24
    - nfs_id: 666
  tasks:

    - name: Installed NFS Server
      yum: name=nfs-utils state=present

    - name: Configure NFS Server
      template: src=./files/exports.template dest=/etc/exports
      notify: Restart NFS Server

    - name: Create Directory
      file: path={{ nfs_dir }} state=directory owner=www group=www recurse=yes mode=755

    - name: Start NFS Server
      service: name=nfs-server state=started enabled=yes 
    
    - name: Check NFS Server
      shell: cat /var/lib/nfs/etab
      register: NFS_Status

    - name: Out NFS Server
      debug: msg={{ NFS_Status.stdout_lines }}
handlers:
- name: Restart NFS Server service: name=nfs-server state=restarted [root@manager playbook]#

 

8.编写应用模块 sersync 的 playbook

  1.安装sersync

  2.配置sersync

  3.启动sersync

 

1.下载 Sersync 软件包

[root@manager playbook]# ll /etc/ansible/playbook/files/
-rw-r--r-- 1 root root   426 2月  22 01:19 sersync.tar.gz

2. 准备 sersync 实时同步的配置文件

[root@manager files]# cat confxml.xml 
<?xml version="1.0" encoding="ISO-8859-1"?>
<head version="2.5">
    <host hostip="localhost" port="8008"></host>
    <debug start="false"/>
    <fileSystem xfs="true"/>
    <filter start="false">
        <exclude expression="(.*)\.svn"></exclude>
        <exclude expression="(.*)\.gz"></exclude>
        <exclude expression="^info/*"></exclude>
        <exclude expression="^static/*"></exclude>
    </filter>
    <inotify>
        <delete start="true"/>
        <createFolder start="true"/>
        <createFile start="true"/>
        <closeWrite start="true"/>
        <moveFrom start="true"/>
        <moveTo start="true"/>
        <attrib start="true"/>
        <modify start="true"/>
    </inotify>

    <sersync>
        <localpath watch="/data">
            <remote ip="172.26.73.200" name="/data"/>
            <!--<remote ip="192.168.8.39" name="tongbu"/>-->
            <!--<remote ip="192.168.8.40" name="tongbu"/>-->
        </localpath>
        <rsync>
            <commonParams params="-az"/>
            <auth start="true" users="rsync_backup" passwordfile="/etc/rsync.pass"/>
            <userDefinedPort start="false" port="874"/><!-- port=874 -->
            <timeout start="true" time="100"/><!-- timeout=100 -->
            <ssh start="false"/>
        </rsync>
        <failLog path="/tmp/rsync_fail_log.sh" timeToExecute="60"/><!--default every 60mins execute once-->
        <crontab start="false" schedule="600"><!--600mins-->
            <crontabfilter start="false">
                <exclude expression="*.php"></exclude>
                <exclude expression="info/*"></exclude>
            </crontabfilter>
        </crontab>
        <plugin start="false" name="command"/>
    </sersync>

    <plugin name="command">
        <param prefix="/bin/sh" suffix="" ignoreError="true"/>  <!--prefix /opt/tongbu/mmm.sh suffix-->
        <filter start="false">
            <include expression="(.*)\.php"/>
            <include expression="(.*)\.sh"/>
        </filter>
    </plugin>

    <plugin name="socket">
        <localpath watch="/opt/tongbu">
            <deshost ip="192.168.138.20" port="8009"/>
        </localpath>
    </plugin>
    <plugin name="refreshCDN">
        <localpath watch="/data0/htdocs/cms.xoyo.com/site/">
            <cdninfo domainname="ccms.chinacache.com" port="80" username="xxxx" passwd="xxxx"/>
            <sendurl base="http://pic.xoyo.com/cms"/>
            <regexurl regex="false" match="cms.xoyo.com/site([/a-zA-Z0-9]*).xoyo.com/images"/>
        </localpath>
    </plugin>
</head>
[root@manager files]# 

3.编写 sersync 应用的 yaml

[root@manager files]# ansible-playbook --syntax-check ../sersync.yml 

playbook: ../sersync.yml
[root@manager files]# cat ../sersync.yml 
---
- hosts: nfs
  tasks:

#1.安装sersync
    - name: Install Sersync Server
      get_url:
        url: https://raw.githubusercontent.com/wsgzao/sersync/master/sersync2.5.4_64bit_binary_stable_final.tar.gz
        dest: /usr/local/sersync.tar.gz

    - name: Unzip Sersync Server
      unarchive: 
        src: /usr/local/sersync.tar.gz 
        dest: /usr/local/
        remote_src: yes
        creates: /usr/local/GNU-Linux-x86

#2.配置sersync
    - name: Configure Sersync Server
      copy: src={{ item.src }} dest={{ item.dest }} mode{{ item.mode }}
      with_items:
        - {src: './files/confxml.xml', dest: '/usr/local/GNU-Linux-x86/', mode: '0644'}
        - {src: './files/rsync.pass', dest: '/etc/rsync.pass', mode: '0600'}
      notify: Restart Sersync Server

#3.启动sersync
    - name: Start Serrsync Server
      shell: ./sersync2 -dro confxml.xml && touch sersync_file
      args:
        chdir: /usr/local/GNU-Linux-x86/
        creates: /usr/local/GNU-Linux-x86/sersync_file
        
  
  handlers:
    - name: Restart Sersync Server
      shell: pkill sersync && ./sersync2 -dro confxml.xml
      args:
        chdir: /usr/local/GNU-Linux-x86/

 

 

9.编写 web 应用模块的 playbook[root@manager playbook]# cat web.yml 

---
- hosts: web
  remote_user: root
  vars:
    - httpd_user: www
    - httpd_port: 80
    - remote_nfs_ip: 172.16.1.31
- local_dir: /var/www/html
tasks:
- name: Install Httpd Server yum: name={{ item }} state=present with_items: - httpd - php - zip - unzip - name: Configure Httpd Server template: src=./files/httpd.conf.template dest=/etc/httpd/conf/httpd.conf notify: Restart Httpd Server - name: Mount NFS Data Directory mount: path=/var/www/html/ src=172.26.73.197:/data fstype=nfs opts=defaults state=mounted - name: Push exam.zip unarchive: src=./files/exam.zip dest=/var/www/html/ creates=/var/www/html/index.html - name: Start Httpd Server service: name=httpd state=started enabled=yes handlers: - name: Restart Httpd Server service: name=httpd state=restarted

 

# httpd配置文件中引入变量的使用,所以在yml 文件中需要提前定义

Listen {{ http_port }}

[root@manager playbook]# cat files/httpd.conf.template 
#
# This is the main Apache HTTP server configuration file.  It contains the
# configuration directives that give the server its instructions.
# See <URL:http://httpd.apache.org/docs/2.4/> for detailed information.
# In particular, see 
# <URL:http://httpd.apache.org/docs/2.4/mod/directives.html>
# for a discussion of each configuration directive.
#
# Do NOT simply read the instructions in here without understanding
# what they do.  They're here only as hints or reminders.  If you are unsure
# consult the online docs. You have been warned.  
#
# Configuration and logfile names: If the filenames you specify for many
# of the server's control files begin with "/" (or "drive:/" for Win32), the
# server will use that explicit path.  If the filenames do *not* begin
# with "/", the value of ServerRoot is prepended -- so 'log/access_log'
# with ServerRoot set to '/www' will be interpreted by the
# server as '/www/log/access_log', where as '/log/access_log' will be
# interpreted as '/log/access_log'.

#
# ServerRoot: The top of the directory tree under which the server's
# configuration, error, and log files are kept.
#
# Do not add a slash at the end of the directory path.  If you point
# ServerRoot at a non-local disk, be sure to specify a local disk on the
# Mutex directive, if file-based mutexes are used.  If you wish to share the
# same ServerRoot for multiple httpd daemons, you will need to change at
# least PidFile.
#
ServerRoot "/etc/httpd"

#
# Listen: Allows you to bind Apache to specific IP addresses and/or
# ports, instead of the default. See also the <VirtualHost>
# directive.
#
# Change this to Listen on specific IP addresses as shown below to 
# prevent Apache from glomming onto all bound IP addresses.
#
#Listen 12.34.56.78:80
Listen 80

#
# Dynamic Shared Object (DSO) Support
#
# To be able to use the functionality of a module which was built as a DSO you
# have to place corresponding `LoadModule' lines at this location so the
# directives contained in it are actually available _before_ they are used.
# Statically compiled modules (those listed by `httpd -l') do not need
# to be loaded here.
#
# Example:
# LoadModule foo_module modules/mod_foo.so
#
Include conf.modules.d/*.conf

#
# If you wish httpd to run as a different user or group, you must run
# httpd as root initially and it will switch.  
#
# User/Group: The name (or #number) of the user/group to run httpd as.
# It is usually good practice to create a dedicated user and group for
# running httpd, as with most system services.
#
User www
Group www

# 'Main' server configuration
#
# The directives in this section set up the values used by the 'main'
# server, which responds to any requests that aren't handled by a
# <VirtualHost> definition.  These values also provide defaults for
# any <VirtualHost> containers you may define later in the file.
#
# All of these directives may appear inside <VirtualHost> containers,
# in which case these default settings will be overridden for the
# virtual host being defined.
#

#
# ServerAdmin: Your address, where problems with the server should be
# e-mailed.  This address appears on some server-generated pages, such
# as error documents.  e.g. admin@your-domain.com
#
ServerAdmin root@localhost

#
# ServerName gives the name and port that the server uses to identify itself.
# This can often be determined automatically, but we recommend you specify
# it explicitly to prevent problems during startup.
#
# If your host doesn't have a registered DNS name, enter its IP address here.
#
#ServerName www.example.com:80

#
# Deny access to the entirety of your server's filesystem. You must
# explicitly permit access to web content directories in other 
# <Directory> blocks below.
#
<Directory />
    AllowOverride none
    Require all denied
</Directory>

#
# Note that from this point forward you must specifically allow
# particular features to be enabled - so if something's not working as
# you might expect, make sure that you have specifically enabled it
# below.
#

#
# DocumentRoot: The directory out of which you will serve your
# documents. By default, all requests are taken from this directory, but
# symbolic links and aliases may be used to point to other locations.
#
DocumentRoot "/var/www/html"

#
# Relax access to content within /var/www.
#
<Directory "/var/www">
    AllowOverride None
    # Allow open access:
    Require all granted
</Directory>

# Further relax access to the default document root:
<Directory "/var/www/html">
    #
    # Possible values for the Options directive are "None", "All",
    # or any combination of:
    #   Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
    #
    # Note that "MultiViews" must be named *explicitly* --- "Options All"
    # doesn't give it to you.
    #
    # The Options directive is both complicated and important.  Please see
    # http://httpd.apache.org/docs/2.4/mod/core.html#options
    # for more information.
    #
    Options Indexes FollowSymLinks

    #
    # AllowOverride controls what directives may be placed in .htaccess files.
    # It can be "All", "None", or any combination of the keywords:
    #   Options FileInfo AuthConfig Limit
    #
    AllowOverride None

    #
    # Controls who can get stuff from this server.
    #
    Require all granted
</Directory>

#
# DirectoryIndex: sets the file that Apache will serve if a directory
# is requested.
#
<IfModule dir_module>
    DirectoryIndex index.html
</IfModule>

#
# The following lines prevent .htaccess and .htpasswd files from being 
# viewed by Web clients. 
#
<Files ".ht*">
    Require all denied
</Files>

#
# ErrorLog: The location of the error log file.
# If you do not specify an ErrorLog directive within a <VirtualHost>
# container, error messages relating to that virtual host will be
# logged here.  If you *do* define an error logfile for a <VirtualHost>
# container, that host's errors will be logged there and not here.
#
ErrorLog "logs/error_log"

#
# LogLevel: Control the number of messages logged to the error_log.
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
#
LogLevel warn

<IfModule log_config_module>
    #
    # The following directives define some format nicknames for use with
    # a CustomLog directive (see below).
    #
    LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
    LogFormat "%h %l %u %t \"%r\" %>s %b" common

    <IfModule logio_module>
      # You need to enable mod_logio.c to use %I and %O
      LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %I %O" combinedio
    </IfModule>

    #
    # The location and format of the access logfile (Common Logfile Format).
    # If you do not define any access logfiles within a <VirtualHost>
    # container, they will be logged here.  Contrariwise, if you *do*
    # define per-<VirtualHost> access logfiles, transactions will be
    # logged therein and *not* in this file.
    #
    #CustomLog "logs/access_log" common

    #
    # If you prefer a logfile with access, agent, and referer information
    # (Combined Logfile Format) you can use the following directive.
    #
    CustomLog "logs/access_log" combined
</IfModule>

<IfModule alias_module>
    #
    # Redirect: Allows you to tell clients about documents that used to 
    # exist in your server's namespace, but do not anymore. The client 
    # will make a new request for the document at its new location.
    # Example:
    # Redirect permanent /foo http://www.example.com/bar

    #
    # Alias: Maps web paths into filesystem paths and is used to
    # access content that does not live under the DocumentRoot.
    # Example:
    # Alias /webpath /full/filesystem/path
    #
    # If you include a trailing / on /webpath then the server will
    # require it to be present in the URL.  You will also likely
    # need to provide a <Directory> section to allow access to
    # the filesystem path.

    #
    # ScriptAlias: This controls which directories contain server scripts. 
    # ScriptAliases are essentially the same as Aliases, except that
    # documents in the target directory are treated as applications and
    # run by the server when requested rather than as documents sent to the
    # client.  The same rules about trailing "/" apply to ScriptAlias
    # directives as to Alias.
    #
    ScriptAlias /cgi-bin/ "/var/www/cgi-bin/"

</IfModule>

#
# "/var/www/cgi-bin" should be changed to whatever your ScriptAliased
# CGI directory exists, if you have that configured.
#
<Directory "/var/www/cgi-bin">
    AllowOverride None
    Options None
    Require all granted
</Directory>

<IfModule mime_module>
    #
    # TypesConfig points to the file containing the list of mappings from
    # filename extension to MIME-type.
    #
    TypesConfig /etc/mime.types

    #
    # AddType allows you to add to or override the MIME configuration
    # file specified in TypesConfig for specific file types.
    #
    #AddType application/x-gzip .tgz
    #
    # AddEncoding allows you to have certain browsers uncompress
    # information on the fly. Note: Not all browsers support this.
    #
    #AddEncoding x-compress .Z
    #AddEncoding x-gzip .gz .tgz
    #
    # If the AddEncoding directives above are commented-out, then you
    # probably should define those extensions to indicate media types:
    #
    AddType application/x-compress .Z
    AddType application/x-gzip .gz .tgz

    #
    # AddHandler allows you to map certain file extensions to "handlers":
    # actions unrelated to filetype. These can be either built into the server
    # or added with the Action directive (see below)
    #
    # To use CGI scripts outside of ScriptAliased directories:
    # (You will also need to add "ExecCGI" to the "Options" directive.)
    #
    #AddHandler cgi-script .cgi

    # For type maps (negotiated resources):
    #AddHandler type-map var

    #
    # Filters allow you to process content before it is sent to the client.
    #
    # To parse .shtml files for server-side includes (SSI):
    # (You will also need to add "Includes" to the "Options" directive.)
    #
    AddType text/html .shtml
    AddOutputFilter INCLUDES .shtml
</IfModule>

#
# Specify a default charset for all content served; this enables
# interpretation of all content as UTF-8 by default.  To use the 
# default browser choice (ISO-8859-1), or to allow the META tags
# in HTML content to override this choice, comment out this
# directive:
#
AddDefaultCharset UTF-8

<IfModule mime_magic_module>
    #
    # The mod_mime_magic module allows the server to use various hints from the
    # contents of the file itself to determine its type.  The MIMEMagicFile
    # directive tells the module where the hint definitions are located.
    #
    MIMEMagicFile conf/magic
</IfModule>

#
# Customizable error responses come in three flavors:
# 1) plain text 2) local redirects 3) external redirects
#
# Some examples:
#ErrorDocument 500 "The server made a boo boo."
#ErrorDocument 404 /missing.html
#ErrorDocument 404 "/cgi-bin/missing_handler.pl"
#ErrorDocument 402 http://www.example.com/subscription_info.html
#

#
# EnableMMAP and EnableSendfile: On systems that support it, 
# memory-mapping or the sendfile syscall may be used to deliver
# files.  This usually improves server performance, but must
# be turned off when serving from networked-mounted 
# filesystems or if support for these functions is otherwise
# broken on your system.
# Defaults if commented: EnableMMAP On, EnableSendfile Off
#
#EnableMMAP off
EnableSendfile on

# Supplemental configuration
#
# Load config files in the "/etc/httpd/conf.d" directory, if any.
IncludeOptional conf.d/*.conf
[root@manager playbook]# 

 

10.将所有编写好的yaml引入至一个文件中,这样便于一次执行

[root@manager playbook]# cat include.yml 
- include: base.yml
- include: rsync.yml
- include: nfs.yml
- include: sersync.yml
- include: web.yml

[root@manager playbook]# cat main.yaml 
- import_playbook: base.yaml
- import_playbook: rsync.yaml
- import_playbook: nfs.yaml
- import_playbook: sersync.yaml
- import_playbook: web.yaml

 

11.测试

1.先测试web是否能同步数据至nfs存储

2.nfs是否实时同步室 rsync 的 /data

3.使用客户端测试能否推送数据到 rsync 的 backup

 

[root@manager playbook]# vim check_client_data.sh
[root@manager playbook]# 
[root@manager playbook]# 
[root@manager playbook]# 
[root@manager playbook]# cat check_client_data.sh 
#!/usr/bin/bash
#1.定义变量
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
Path=/backup
Date=$(data +%F)

#2.校验数据
md5sum -C $Path/*_{Date}/flag > $Path/result_${Date}

#3.发邮件
mail -s "Rsync Backup ${Date}" 63595627@qq.com < $Path/result_${Date}

#4.保留最近180天的数据
find $Path/ -type d -mtime +180 | xargs rm -rf
find $Path/ -type f -name "result*" -mtime +7 -exec rm -f { } /;
[root@manager playbook]# 

 

posted on 2020-05-07 23:21  Sunjingjing  阅读(202)  评论(0)    收藏  举报