系统环境
管理端:外网IP-10.0.0.61 内网IP-172.16.1.61 被控rsync服务端:外网IP-10.0.0.7 内网IP-172.16.1.7 被控rsync客户端:外网IP-10.0.0.51 内网IP-172.16.1.51
[root@m01 file]
CentOS Linux release 7.5.1804 (Core)
[root@m01 file]
3.10.0-862.el7.x86_64
主机清单配置文件
[root@m01 roles]
[rsync_client]
172.16.1.51
[rsync_server]
172.16.1.7
提前准备好的本地配置文件
[root@m01 file]
/etc/ansible/file
[root@m01 file]
total 0
-rw-r--r-- 1 root root 0 Aug 12 17:14 rsyncd.conf
[root@m01 file]
uid = rsync
gid = rsync
port = 873
fake super = yes
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
rsync服务部署流程(服务端)
1)安装rsync软件 2)创建并编写配置文件 3)创建rsync虚拟用户,禁止shell登录,不创建家目录。 4)创建备份目录,设置好属主属组信息。 5)创建密码文件。(用户名和密码) 6)启动rsync服务
rsync客户端部署流程
1)安装rsync软件 2)创建密码文件(只有密码)
yaml文件内容呈现
[root@m01 roles]
- hosts: rsync_server
tasks:
- name: 01-install rsync
yum: name=rsync state=installed
- name: 02-create rsyncd.conf
copy: src=/etc/ansible/file/rsyncd.conf dest=/etc
- name: 03-create user rsync
user: name=rsync create_home=no shell=/sbin/nologin
- name: 04-create /backup directory
file: path=/backup state=directory owner=rsync group=rsync
- name: 05-create password file
copy: content=rsync_backup:oldboy123 dest=/etc/rsync.password mode=600
- name: 06-start rsync service
service: name=rsyncd state=started enabled=yes
- hosts: rsync_client
tasks:
- name: 01-installl rsync
yum: name=rsync state=installed
- name: 02-create password file
copy: content=oldboy123 dest=/etc/rsync.password mode=600
- name: 03-create test file
file: dest=/tmp/test.txt state=touch
- name: 04-test rsync sending
shell: rsync -avz /tmp/test.txt rsync_backup@172.16.1.7::backup --password-file=/etc/rsync.password
yaml文件执行顺序
1)首先检查语法格式是否正确
ansible-playbook --syntax-check rsync.yaml
2)其次模拟执行(模拟成功不代表真正执行一定成功)
ansible-playbook -C rsync.yaml
3)最后真正执行
ansible-playbook rsync.yaml
|