码迷,mamicode.com
首页 > 其他好文 > 详细

利用ansible一键化部署nfs&rsync并实时同步

时间:2017-10-29 17:36:53      阅读:313      评论:0      收藏:0      [点我收藏+]

标签:linux

管理端 :

[root@m01 tools]# cat quanwang.sh
#!/bin/bash
sh /server/scripts/piliangceshimiyao.sh
ansible-playbook /server/tools/rsyncpiliang.yml
ansible-playbook /server/tools/nfspiliang.yml
ansible-playbook /server/tools/quanwang.yml


1./server/scripts/piliangceshimiyao.sh

[root@m01 tools]# cat /server/scripts/piliangceshimiyao.sh
#!/bin/bash
#生成密钥
\rm -f /root/.ssh/id_dsa*
ssh-keygen -t dsa -f /root/.ssh/id_dsa -P "" -q

#发送密钥
for ip in 61 8 31 41
do
echo "==== 现在分发 172.16.1.$ip=========="
sshpass -p123456 ssh-copy-id -i /root/.ssh/id_dsa.pub "-o StrictHostKeyChecking=no root@172.16.1.$ip"
echo "==============end======="
echo
done

 

2.ansible-playbook /server/tools/rsyncpiliang.yml

- hosts: 172.16.1.41 #服务端
tasks:
- name: yum 
shell: yum install -y rsync #安装rsync
- name: yunm
shell: yum -y install sshpass #安装密钥的软件
- name: chuangjianmulu
shell: mkdir -p /server/tools/ #创建所在配置的文件
- name: peizhi
copy: src=/server/tools/peizhi.sh dest=/server/tools/peizhi.sh
- name: yunxing 
script: /server/tools/peizhi.sh #运行脚本
- name: guanliyunhu
shell: useradd -s /sbin/nologin -M rsync #创建rsync虚拟用户
- name: anquanwenjian
shell: echo "rsync_backup:oldboy123" >/etc/rsync.password #设置密码文件
- name: quanxian
shell: chmod 600 /etc/rsync.password #给予权限
- name: beifenmulu
shell: mkdir -p /backup && chown -R rsync.rsync /backup
- name: qidong
shell: rsync --daemon #运行rsync
- hosts: 172.16.1.8
tasks:
- name: yum
shell: yum install -y rsync # 客户端
- name: chuangjianmulu
shell: mkdir -p /server/tools/
- name: mimawenjian
shell: echo "oldboy123" >/etc/rsync.password && chmod 600 /etc/rsync.password
- hosts: 172.16.1.31
tasks:
- name: yum
shell: yum install -y rsync #客户端 
- name: chuangjianmulu
shell: mkdir -p /server/tools/
- name: mimawenjian
shell: echo "oldboy123" >/etc/rsync.password && chmod 600 /etc/rsync.password

 

 

3.ansible-playbook /server/tools/nfspiliang.yml

- hosts: 172.16.1.31 #服务端
tasks:
- name: yum 
shell: yum install -y nfs-utils rpcbind #安装nfs
- name: yunm
shell: yum -y install sshpass #安装密钥的软件
- name: chuangjianmulu
shell: mkdir -p /server/tools/ #创建所在配置的文件
- name: peizhi
copy: src=/server/tools/nfspeizhi.sh dest=/server/tools/nfspeizhi.sh
- name: yunxingjiaoben 
script: /server/tools/nfspeizhi.sh #运行脚本
- name: guanlimulu
shell: mkdir -p /data && chown -R nfsnobody.nfsnobody /data
- name: qidong 
shell: /etc/init.d/rpcbind start && /etc/init.d/nfs start #启动
- name: kaijiqidong
shell: chkconfig rpcbind on && chkconfig nfs on
#设置密码文件
- hosts: 172.16.1.8
tasks:
- name: yum
shell: yum install -y nfs-utils rpcbind # 客户端
# - name: gui
# shell: umount -f /mnt
- name: guazai
shell: mount -t nfs 172.16.1.31:/data /mnt
- hosts: 172.16.1.41
tasks:
- name: yumh
shell: yum install -y nfs-utils rpcbind #客户端 
# - name: guih
# shell: umount -f /mnt 
- name: guazaih
shell: mount -t nfs 172.16.1.31:/data /mnt

 

4.ansible-playbook /server/tools/quanwang.yml

- hosts: 172.16.1.61
tasks:
# - name: anzhuangrsync
# shell: /server/scripts/piliangceshimiyao.sh
# - name: anzhuangrsync
# shell: /server/tools/rsyncpiliang.yml
# - name: anzhuangnfs
# shell: /server/tools/nfspiliang.yml
- hosts: 172.16.1.41
tasks: 
- name: chuangjianmulu41
shell: mkdir -p /server/tools/ #创建所在配置的文件
- name: peizhi41
copy: src=/server/tools/quanwangrsync.sh dest=/server/tools/quanwangrsync.sh
- name: rsyncdajian41
script: /server/tools/quanwangrsync.sh
- hosts: 172.16.1.8
tasks:
- name: chuangjianmulu8
shell: mkdir -p /server/tools/ #创建所在配置的文件
- name: peizhi8
copy: src=/server/tools/quanwangweb.sh dest=/server/tools/quanwangweb.sh
- name: quanwangweb8
script: /server/tools/quanwangweb.sh
- hosts: 172.16.1.31
tasks:
- name: chuangjianmulu31
shell: mkdir -p /server/tools/ #创建所在配置的文件
- name: peizhi31
copy: src=/server/tools/quanwangnfs.sh dest=/server/tools/quanwangnfs.sh
- name: quanwangnfs.sh31
script: /server/tools/quanwangnfs.sh


本文出自 “shine” 博客,请务必保留此出处http://2690403167.blog.51cto.com/13190873/1977178

利用ansible一键化部署nfs&rsync并实时同步

标签:linux

原文地址:http://2690403167.blog.51cto.com/13190873/1977178

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