ansible部署rsync+inotify-tools.docx_第1页
ansible部署rsync+inotify-tools.docx_第2页
ansible部署rsync+inotify-tools.docx_第3页
ansible部署rsync+inotify-tools.docx_第4页
ansible部署rsync+inotify-tools.docx_第5页
已阅读5页,还剩5页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

Ansible部署rsync+inotify-tools(by本末, mail: p_)客户端环境:Centos 6.2 x64Rsync版本:3.0.6Ansible版本:1.8功能:部署Rsync 单向同步 or 双向同步roles目录结构:roles/install_rsync|-files|-stop.sh#停止客户端进程脚本|-tasks|-client.yml#配置客户端|-install.yml#配置服务端|-main.yml#主tasks文件-templates|-default_rsync#ubuntu的/etc/default/raync配置文件|-rsync.sh#客户端同步脚本-rsyncd.conf#主配置文件playbook-hosts:hostssudo:yesgather_facts:yesvars:create_server:yes#modulenamemodule_name:test#同步的根路径module_path:/data#认证的用户auth_users:webadmin#服务端认证文件server_secrets_file:/etc/rsyncd_server.secrets#服务端认证文件server_log:/data/logs/rsync/rsync_server.log#认证密码secrets_pass:123123#是否建立客户端“-e”指定create_client:client#客户端对应服务端的IPpeer_ip:peer_ip#客户端日志文件client_log:/data/logs/rsync/rsync_client.log#客户端密码文件client_secrets_file:/data/projects/rsync/rsync_client.secrets#同步的目录,多个目录按照格式加就可以dirs_to_rsync:-/data/projects/roles:-role:install_rsyncroles/install_rsync/tasks/main.yml-include:install.yml-include:client.ymlwhen:create_client=yesroles/install_rsync/tasks/install.yml#ubuntu安装rsync,inotify-tools-name:ubuntu|InstallRsyncandinotify-toolsapt:name=itemstate=latestwith_items:-rsync-inotify-toolswhen:ansible_os_family=Debian#ubuntu上传default下的配置文件-name:Uploaddefaultfiletemplate:src=default_rsyncdest=/etc/default/rsyncmode=0644when:ansible_os_family=Debian#RHEL系列安装rsync,inotify-tools-name:RHEL|InstallRsyncandinotify-toolsyum:name=itemstate=latestwith_items:-rsync-inotify-toolswhen:ansible_os_family=RedHat#创建Rsync的日志目录-name:Createlogsrsyncdirectoryfile:dest=/data/logs/rsyncstate=directoryowner=auth_usersgroup=auth_usersmode=0755#上传主配置文件-name:Uploadrsyncconfigfiletemplate:src=rsyncd.confdest=/etc/rsyncd.confmode=0644when:create_server=yes#创建server端认证文件-name:CreateRsyncserversecretsfilelineinfile:dest=server_secrets_fileline=auth_users:secrets_passowner=rootgroup=rootmode=0600create=yeswhen:create_server=yes#添加开机启动server-name:Addservertorc.locallineinfile:dest=/etc/rc.localline=/usr/bin/rsync-daemon-config=/etc/rsyncd.conf-address=ansible_default_ipv4.addresswhen:ansible_os_family=RedHatandcreate_server=yesroles/install_rsync/tasks/client.yml#检查认证用户是否存在-name:Checkauthusershell:idauth_usersregister:userignore_errors:yes#不存在用户则创建-name:Createauth_usersuseruser:name=auth_usershome=/home/auth_usersshell=/bin/bashwhen:user.rc=1#创建rsync客户端目录和日志目录,这个logs/rsync有点重复了-name:Creatersyncclientdirectoryfile:dest=/data/item/rsyncstate=directoryowner=auth_usersgroup=auth_usersmode=0755with_items:-projects-logs#上传rsync客户端脚本-name:Uploadrsyncscriptsfiletemplate:src=rsync.shdest=/data/projects/rsync/rsync.showner=auth_usersgroup=auth_usersmode=0755#创建客户端认证文件-name:Creatersyncdclientsecretsfilelineinfile:dest=client_secrets_fileline=secrets_passowner=auth_usersgroup=auth_usersmode=0600create=yes#创建同步目录文件,内容的是需要同步的目录-name:Addrsyncdirspathlineinfile:dest=/data/projects/rsync/dirs_to_rsyncline=dirs_to_rsyncmode=0644owner=auth_usersgroup=auth_userscreate=yeswhen:create_client=yesanddirs_to_rsyncisdefined#上传客户端进程kill脚本-name:Copyclientstopscriptscopy:src=stop.shdest=/data/projects/rsync/mode=0755owner=auth_usersgroup=auth_userswhen:create_client=yesroles/install_rsync/templates/rsync.sh(脚本含义就不再解释)#!/bin/bashrsync_user=auth_userspeer_ip=peer_iprsync_module=module_namelog_file=client_logsecrets_file=client_secrets_filedirs_to_sync=$1#-mainpartofscprits-#module_path=module_pathrsync_daemon_opts=-pthr-log-file=$log_file-password-file=$secrets_filersync_by_daemon()dir=$1username=$2des=echo$1|sed-es#$module_path#ghost=$3module=$4file=$5is_dir=echo$event|grepISDIR$event=CREATE|rsync$rsync_daemon_opts$dir$file$username$host:$module/$desdo_watch()dirs_to_sync=$1events=create,attrib,modify,move,close_writeexclude_pattern=/.+.tmp$|/.+.lock$|/./+timefmt=-timefmt%Y-%m-%dT%H:%M/usr/bin/inotifywait-mrq$timefmt-format%T%e%w%f-e$events-excludei$exclude_pattern-fromfile$dirs_to_sync|whilereaddatetimeeventdirfiledorsync_by_daemon$dir$rsync_user$peer_ip$rsync_module$filedone#syncallwhilereadlinedo#display$lineordosomthingwith$line relative_path=echo$line|seds#$module_path#relative_path=dirname$relative_pathrsync$rsync_daemon_opts$line$rsync_user$peer_ip:$rsync_module$relative_pathdone(item=rsync,inotify-tools)TASK:install_rsync|Createlogsrsyncdirectory*changed:website1TASK:install_rsync|Uploadrsyncconfigfile*changed:website1TASK:install_rsync|CreateRsyncserversecretsfile*changed:website1TASK:install_rsync|Addservertorc.local*changed:website1TASK:install_rsync|Checkauthuser*changed:website1TASK:install_rsync|Createauth_usersuser*skipping:website1TASK:install_rsync|Creatersyncclientdirectory*changed:website1=(item=projects)ok:website1=(item=logs)TASK:install_rsync|Uploadrsyncscriptsfile*changed:website1TASK:install_rsync|Creatersyncdclientsecretsfile*changed:website1TASK:install_rsync|Addrsyncdirspath*changed:website1TASK:install_rsync|Copyclientstopscripts*changed:website1PLAYRECAP*website1:ok=12changed=11unreachable=0failed=0website2:ansible-playbookinstall_rsyncd.yml-ehosts=website2client=yespeer_ip=0SSHpassword:sudopassworddefaultstoSSHpassword:PLAYwebsite2*GATHERINGFACTS*ok:website2TASK:install_rsync|ubuntu|InstallRsyncandinotify-tools*skipping:website2TASK:install_rsync|Uploaddefaultfile*skipping:website2TASK:install_rsync|RHEL|InstallRsyncandinotify-tools*changed:website2=(item=rsync,inotify-tools)TASK:install_rsync|Createlogsrsyncdirectory*changed:website2TASK:install_rsync|Uploadrsyncconfigfile*changed:website2TASK:install_rsync|CreateRsyncserversecretsfile*changed:website2TASK:install_rsync|Addservertorc.local*changed:website2TASK:install_rsync|Checkauthuser*changed:website2TASK:install_rsync|Createauth_usersuser*skipping:website2TASK:install_rsync|Creatersyncclientdirectory*changed:website2=(item=projects)ok:website2=(item=logs)TASK:install_rsync|Uploadrsyncscriptsfile*changed:website2TASK:install_rsync|Creatersyncdclientsecretsfile*changed:website2TASK:install_rsync|Addrsyncdirspath*changed:website2TASK:install_rsync|Copyclientstopscripts*changed:website2PLAYRECAP*website2:ok=12changed=11unreachable=0failed=0启动server端服务website1:/usr/bin/rsync-daemon-config=/etc/rsyncd.conf-address=0website2:/usr/bin/rsync-daemon-config=/etc/rsyncd.conf-address=6启动客户端同步脚本website1:website2cd/data/projects/rsync/./rsync.shdirs_to_rsync&测试:website1:webadminwebsite_50$cd/data/projects//webadminwebsite_50$touchindex.htmlwebadminwebsite_50$lltotal0-rw-rw-r-1webadminwebadmin0Dec3117:14index.html查看日志:webadminwebsite_50$tailf/data/logs/rsync/rsync_client.log2014/12/3117:13:1921202buildingfilelist2014/12/3117:13:1921202sent45bytesreceived10bytestotalsize02014/12/3117:14:2621538buildingfilelist2014/12/3117:14:2621538f+index.html到website2上查看webadminwebsite_16rsync$cd/data/projects//webadminwebsite_16$lltotal0-rw-rw-

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论