一键化部署rsync和nfs服务,挂载web服务器到nfs,实现共享目录和备份
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了一键化部署rsync和nfs服务,挂载web服务器到nfs,实现共享目录和备份相关的知识,希望对你有一定的参考价值。
使用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服务
- name: yum rsync,nfs and rpcbind
- 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并且配置密码文件,实现推数据无密码
- name: rsync conf
- 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共享目录
- name: passfile
- 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
- name: mount nfs
以上是关于一键化部署rsync和nfs服务,挂载web服务器到nfs,实现共享目录和备份的主要内容,如果未能解决你的问题,请参考以下文章