----------------------------------------------
1.写出rsync手动部署的步骤
1)安装rsync服务
yum -y install rsync
2)配置rsync服务 提前将配置文件收集到ansible管理主机
[root@ansible ~]# scp 10.0.0.41:/etc/rsyncd.conf .
3)根据配置创建必要数据
创建www用户
创建密码文件/etc/rsync.passwd
密码权限600
创建目录
/backup
修改目录权限属主属组www
4)启动rsync服务
systemctl start rsyncd
systemctl enable rsyncd
-----------------------------------------------
2.将rsync写入到ansible主机清单(记得先恢复快照)
[root@ansible ~]# ssh-copy-id -i .ssh/id_rsa.pub 10.0.0.41
[root@ansible ~]# cat /etc/ansible/hosts
[nfs]
10.0.0.31
[webs]
web01 ansible_ssh_host=10.0.0.7
web02 ansible_ssh_host=10.0.0.8
[backups]
backup ansible_ssh_host=10.0.0.41
测试ping
[root@ansible ~]# ansible backup -m ping
3.通过ansible单条命令实现远程部署rsync服务
1)安装rsync 使用yum模块
语法:
ansible backup -m 指定模块名 -a 具体动作
[root@ansible ~]# ansible backup -m yum -a 'name=rsync state=present'
卸载rsync服务:
[root@ansible ~]# ansible backup -m yum -a 'name=rsync state=absent'
yum模块:
2)配置rsync服务端
---------------------
将rsync配置文件拷贝到目标位置/etc/rsyncd.conf
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
log file = /var/log/rsyncd.log
#####################################
[backup]
path = /backup
[root@ansible ~]# ansible backup -m copy -a 'src=rsyncd.conf dest=/etc/rsyncd.conf'
欢迎来撩 : 汇总all