1. 程式人生 > >一鍵化部署rsync和nfs服務,掛載web服務器到nfs,實現共享目錄和備份

一鍵化部署rsync和nfs服務,掛載web服務器到nfs,實現共享目錄和備份

sts backup 批量 1.7 ict util local install user

使用ansible服務,實現批量管理
第一步,先分發公鑰,實現ansible無密碼進行控制
#!/bin/bash

#mk key 2
rm -f /root/.ssh/id*
ssh-keygen -t dsa -f /root/.ssh/id_dsa -P "" -q

#fenfa

for ip in 41 7 31
do
echo ================fs host 172.16.1.$ip======================
sshpass -p123456 ssh-copy-id -i /root/.ssh/id_dsa.pub "-o StrictHostKeyChecking=no [email protected].$ip"

echo ================fs end 172.16.1.$ip=====================
done

第二步,編寫劇本,實現安裝rsync,nfs,以及掛載nfs共享目錄並且實時備份
#安裝相應軟件

  • hosts: yxd
    tasks:
    • name: yum rsync,nfs and rpcbind
      yum: name=rsync,nfs-utils,rpcbind state=installed
      #配置rsync服務
  • hosts: 172.16.1.41
    tasks:
    • name: rsync conf
      copy: src=/etc/ansible/ansible_playbook/rsyncd.conf dest=/etc/rsyncd.conf
    • name: mk user
      user: name=rsync shell=/sbin/nologin createhome=no
    • name: mk dir
      file: path=/backup mode=0755 owner=rsync group=rsync state=directory
    • name: passfile
      shell: echo ‘rsync_backup:123456‘ >/etc/rsync.password && chmod 0600 /etc/rsync.password
    • name: server on
      shell: rsync --daemon && echo ‘rsync --daemon‘ >>/etc/rc.local
      #部署NFS並且配置密碼文件,實現推數據無密碼
  • hosts: 172.16.1.31
    tasks:
    • name: passfile
      shell: echo ‘123456‘ >/etc/rsync.password && chmod 0600 /etc/rsync.password
    • name: rsync
      shell: /usr/bin/rsync -az /etc/hosts [email protected]::backup --password-file=/etc/rsync.password
    • name: mk nfsdir
      file: path=/nfs state=directory owner=nfsnobody group=nfsnobody
    • name: nfs.conf
      copy: src=/etc/ansible/ansible_playbook/nfs.conf dest=/etc/exports backup=yes
    • name: rpcbind on
      service: name=rpcbind state=started enabled=yes
    • name: nfs on
      service: name=nfs state=started enabled=yes
    • name: sersync backup
      copy: src=/tmp/sersync/ dest=/sersync/
    • name: sersync on
      shell: chmod +x /sersync/bin/sersync && /sersync/bin/sersync -dro /sersync/conf/confxml.xml
      #掛載客戶端到nfs共享目錄
  • hosts: 172.16.1.7 172.16.1.8
    tasks:
    • name: mount nfs
      mount: state=mounted fstype=nfs src=‘172.16.1.31:/nfs‘ path=/mnt

一鍵化部署rsync和nfs服務,掛載web服務器到nfs,實現共享目錄和備份