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

利用ansible实现一键化部署 rsync服务

时间:2017-10-29 17:34:51      阅读:276      评论:0      收藏:0      [点我收藏+]

标签:linux

创建脚本

cat  /server/scripts/rsyncd.conf.sh

修改rsync配置文件

cat >>/etc/rsyncd.conf<<EOF

uid = rsync
gid = rsync
use chroot = no
max connections = 200
timeout = 300
pid file = /var/run/rsyncd.pid
lock file = /var/run/rsync.lock
log file = /var/log/rsyncd.log
ignore errors
read only = false
list = false
hosts allow = 172.16.1.0/24
hosts deny = 0.0.0.0/32
auth users = rsync_backup
secrets file = /etc/rsync.password
[backup]
comment = "backup dir by oldboy"
path = /backup
EOF

一键化剧本

[root@m01 tools]# cat rsync_piliang.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/scripts #创建所在配置的文件
- name: peizhi
copy: src=/server/scripts/rsyncd.conf.sh dest=/server/scripts/rsyncd.conf.sh
- name: yunxing 
script: /server/scripts/rsyncd.conf.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


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

利用ansible实现一键化部署 rsync服务

标签:linux

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

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