One-click deployment of Rsync and NFS services, mounting Web servers to NFS, implementing shared Directories and backups

Source: Internet
Author: User
Tags rsync

Use Ansible services to achieve batch management
The first step is to distribute the public key and implement ansible without password control.
#!/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

Step two, write the script, implement the installation Rsync,nfs, and mount the NFS shared directory and backup in real time
#安装相应软件

  • 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并且配置密码文件 to implement push data without password
  • hosts:172.16.1.31
    Tasks:
    • name:passfile
      Shell:echo ' 123456 ' >/etc/rsync.password && CHM OD 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< Br>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/co Nfxml.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

One-click deployment of Rsync and NFS services, mounting Web servers to NFS, implementing shared Directories and backups

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.