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