1. 程式人生 > >rsync軟件服務利用ansible實現一鍵化部署

rsync軟件服務利用ansible實現一鍵化部署

一鍵化部署

首先創建一個腳本文件 /server/tools/peizhi.sh

cat /server/tools/peizhi.sh


cat >>/etc/rsyncd.conf<<EOF
#luo
##paichu.sh##

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

一鍵化劇本

[[email protected] tools]# cat rsyncpiliang.yml
- hosts: 172.16.1.141 #服務端
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.108
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.131
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


本文出自 “13029592” 博客,請務必保留此出處http://13039592.blog.51cto.com/13029592/1963543

rsync軟件服務利用ansible實現一鍵化部署