Ansible-完成rsync远程备份服务搭建

1.roles/rsync/tasks/main.yml

# rsync 服务端
# 修改配置文件
echo '
uid = www
gid = www
port = 873
fake super = yes
use chroot = no
max connections = 200
timeout = 600
ignore errors
read only = false 
list = false
auth users = rsync_backup 
secrets file = /etc/rsync.passwd
[data]  
path = /data
' > /etc/rsyncd.conf

# 创建虚拟验证密码文件
echo '
rsync_backup:1
' > /etc/rsync.passwd
chmod 600 /etc/rsync.passwd

# 创建备份目录
mkdir /data
chown www.www /data

# 启动服务并加入开机自启
systemctl start rsyncd
systemctl enable rsyncd
- name: Modify rsync_server configure
  template:
    src: rsyncd.conf.j2
    dest: /etc/rsyncd.conf
  notify: Restart rsyncd

- name: Create virtual user_password_file
  template:
    src: rsync.passwd.j2
    dest: /etc/rsync.passwd
    mode: '600'

- name: Create backup_directory
  file:
    path: /data
    state: directory
    owner: www
    group: www

- name: Start rsyncd server
  systemd:
    name: rsyncd
    state: started
    enabled: yes

2.roles/rsync/handlers/main.yml

# 重启rsync服务端,使配置文件生效
systemctl restart rsyncd
- name: Restart rsyncd
  systemd:
    name: rsyncd
    state: restarted

3.roles/rsync/templates/rsyncd.conf.j2

# 此为rsync虚拟用户的密码验证文件
rsync_backup:1

4.roles/rsync/templates/rsync.passwd.j2

uid = www
gid = www
port = 873
fake super = yes
use chroot = no
max connections = 200
timeout = 600
ignore errors
read only = false 
list = false
auth users = rsync_backup 
secrets file = /etc/rsync.passwd
[data]  
path = /data

猜你喜欢

转载自www.cnblogs.com/IMSCZ/p/12133351.html