使用playbook实现一键部署rsync
环境
| 主机名 | wanIP | lanIP | 服务 | 角色 |
|---|---|---|---|---|
| m01 | 10.0.0.61 | 172.16.1.61 | Ansible | 控制端 |
| backup | 10.0.0.41 | 172.16.1.41 | rsync服务端 | 被控端 |
| web01 | 10.0.0.7 | 172.16.1.7 | rsync客户端 | 被控端 |
| web02 | 10.0.0.8 | 172.16.1.8 | rsync客户端 | 被控端 |
| nfs | 10.0.0.31 | 172.16.131 | rsync客户端 | 被控端 |
流程分析
1.安装ansible 2.优化ansible 3.推送公钥 4.开启防火墙 5.开启80 443 873 nfs等端口和服务白名单 6.关闭selinux 7.创建同一的用户 1.web backup nfs 安装rsync 2.拷贝rsync配置文件 3.创建服务端backup的备份目录 4.copy密码文件 5.把客户端密码加入环境全局变量文件 6.启动rsync,并加入开机自启动
配置主机清单
mkdir /root/ansible/rsync -p && vim /root/ansible/rsync/hosts [web_group] web01 ansible_ssh_host=172.16.1.7 asible_ssh_user=root ansible_ssh_port=22 web02 ansible_ssh_host=172.16.1.8 asible_ssh_user=root ansible_ssh_port=22 [nfs_group] nfs ansible_ssh_host=172.16.1.31 asible_ssh_user=root ansible_ssh_port=22 [backup_group] backup ansible_ssh_host=172.16.1.41 asible_ssh_user=root ansible_ssh_port=22
rsync配置文件
vim /root/ansible/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 = backup secrets file = /etc/rsync.passwd log file = /var/log/rsyncd.log [backup] comment = welcome to oldboyedu backup! path = /backup
yml
vim /root/ansible/rsync/rsync.yml
- hosts: all
tasks:
- name: Install Rsync Server
yum:
name: rsync
state: present
- name: selicent pass
copy:
content: "export RSYNC_PASSWORD=123"
dest: /etc/profile.d/rsync.pass
owner: root
group: root
mode: 0600
when: ansible_hostname is match "web*"
- name: sourse
shell: "source /etc/profile.d/rsync.pass"
when: ansible_hostname is match "web*"
- name: selicent pass
copy:
content: "export RSYNC_PASSWORD=123"
dest: /etc/profile.d/rsync.pass
owner: root
group: root
mode: 0600
when: ansible_hostname is match "nfs*"
- name: sourse
shell: "source /etc/profile.d/rsync.pass"
when: ansible_hostname is match "nfs*"
- name: Configure Rsync Conf
copy:
src: /root/ansible/rsync/rsyncd.conf
dest: /etc/rsyncd.conf
owner: root
group: root
mode: 0644
when: ansible_hostname is match "backup*"
- name: Create Backup Dir
file:
path: /backup
recurse: yes
owner: www
group: www
mode: 0755
state: directory
when: ansible_hostname is match "backup*"
- name: Create PASS File
copy:
content: backup:123
dest: /etc/rsync.passwd
owner: root
group: root
mode: 0600
when: ansible_hostname is match "backup*"
- hosts: all
tasks:
- name: Start Rsync Server
service:
name: rsyncd
state: started
enabled: true执行
1.执行base.yml [ ~]# ansible-playbook ansible/base.yml 2.执行rsync.yml [ ~]# ansible-playbook ansible/rsync/rsync.yml -i /root/ansible/rsync/hosts
相关推荐
awoyaoc 2020-06-12
xiaoemo0 2020-06-17
wiseMale 2020-05-31
会哭的雨 2020-05-30
ITlover00 2020-05-26
plusz 2020-05-09
深井兮兮 2020-05-01
jiangtie 2020-04-30
净无邪 2020-04-26
Wytheme 2020-02-16
secondid 2020-02-03
秋风瑟瑟 2020-01-06
会哭的雨 2019-12-12
insularisland 2019-12-06
leodengzx 2019-12-03
博小瑾 2014-03-18
ourtimes 2015-05-02
云计算和大数据 2019-11-12
周公周金桥 2015-07-01