创建脚本
cat /server/scripts/rsyncd.conf.sh
修改rsync配置文件
cat >>/etc/rsyncd.conf<<EOF
uid = rsyncgid = rsyncuse chroot = nomax connections = 200timeout = 300pid file = /var/run/rsyncd.pidlock file = /var/run/rsync.locklog file = /var/log/rsyncd.logignore errorsread only = falselist = falsehosts allow = 172.16.1.0/24hosts deny = 0.0.0.0/32auth users = rsync_backupsecrets file = /etc/rsync.password[backup]comment = "backup dir by oldboy"path = /backupEOF
一键化剧本
[root@m01 tools]# cat rsync_piliang.yml - hosts: 172.16.1.41 #服务端tasks:- name: yum shell: yum install -y rsync #安装rsync- name: yunmshell: yum -y install sshpass #安装密钥的软件- name: chuangjianmulushell: mkdir -p /server/scripts #创建所在配置的文件- name: peizhicopy: src=/server/scripts/rsyncd.conf.sh dest=/server/scripts/rsyncd.conf.sh- name: yunxing script: /server/scripts/rsyncd.conf.sh #运行脚本- name: guanliyunhushell: useradd -s /sbin/nologin -M rsync #创建rsync虚拟用户- name: anquanwenjianshell: echo "rsync_backup:oldboy123" >/etc/rsync.password #设置密码文件- name: quanxianshell: chmod 600 /etc/rsync.password #给予权限- name: beifenmulushell: mkdir -p /backup && chown -R rsync.rsync /backup- name: qidongshell: rsync --daemon #运行rsync- hosts: 172.16.1.8tasks:- name: yumshell: yum install -y rsync # 客户端- name: chuangjianmulushell: mkdir -p /server/tools/- name: mimawenjianshell: echo "oldboy123" >/etc/rsync.password && chmod 600 /etc/rsync.password- hosts: 172.16.1.31tasks:- name: yumshell: yum install -y rsync #客户端 - name: chuangjianmulushell: mkdir -p /server/tools/- name: mimawenjianshell: echo "oldboy123" >/etc/rsync.password && chmod 600 /etc/rsync.password