码迷,mamicode.com
首页 > 其他好文 > 详细

使用playbook实现一键部署rsync

时间:2020-06-14 01:20:41      阅读:75      评论:0      收藏:0      [点我收藏+]

标签:yml   secret   super   ldb   directory   figure   lan   present   start   

环境

主机名 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
[root@m01 ~]# ansible-playbook ansible/base.yml 

2.执行rsync.yml
[root@m01 ~]# ansible-playbook ansible/rsync/rsync.yml -i /root/ansible/rsync/hosts

使用playbook实现一键部署rsync

标签:yml   secret   super   ldb   directory   figure   lan   present   start   

原文地址:https://www.cnblogs.com/syy1757528181/p/13122264.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!