码迷,mamicode.com
首页 > Web开发 > 详细

一键化部署rsync和nfs服务,挂载web服务器到nfs,实现共享目录和备份

时间:2018-02-01 20:33:33      阅读:246      评论:0      收藏:0      [点我收藏+]

标签:login   ice   /etc/   nfs-utils   etc   rpcbind   play   nfs   enable   

使用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 root@172.16.1.$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 rsync_backup@172.16.1.41::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,实现共享目录和备份

标签:login   ice   /etc/   nfs-utils   etc   rpcbind   play   nfs   enable   

原文地址:http://blog.51cto.com/12928749/2067884

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!