分类: LINUX

环境说明:

OS :    CentOS5.4                         i686
puppet版本:                               2.7.14
puppetmaster.manzuoinfo.com            192.168.0.12
puppet1.manzuoinfo.com                 192.168.0.64
rsync server                           192.168.0.12

同步需求简介:

需要把 rsync server 192.168.0.12 上的 /tmp/default 和  /tmp/test 目录 分别同步到 puppet1.manzuinfo.com 192.168.0.12 上的 /tmp/test1 下和/tmp/test。

点击(此处)折叠或打开

  1. [root@puppetmaster test]# cd /tmp/
  2. [root@puppetmaster tmp]# ls
  3. default test
  4. [root@puppetmaster tmp]# cd test
  5. /tmp/test
  6. [root@puppetmaster test]# ls -l
  7. total 4
  8. -rw-r--r-- 1 root root 0 Sep 22 17:32 10.txt
  9. -rw-r--r-- 1 root root 0 Sep 22 17:32 1.txt
  10. -rw-r--r-- 1 root root 0 Sep 22 17:32 2.txt
  11. -rw-r--r-- 1 root root 0 Sep 22 17:32 3.txt
  12. -rw-r--r-- 1 root root 0 Sep 22 17:32 4.txt
  13. -rw-r--r-- 1 root root 0 Sep 22 17:32 5.txt
  14. -rw-r--r-- 1 root root 0 Sep 22 17:32 6.txt
  15. -rw-r--r-- 1 root root 0 Sep 22 17:32 7.txt
  16. -rw-r--r-- 1 root root 0 Sep 22 17:32 8.txt
  17. -rw-r--r-- 1 root root 0 Sep 22 17:32 9.txt
  18. -rw-r--r-- 1 root root 17 Sep 22 17:32 test.txt
  19. [root@puppetmaster default]# pwd
  20. /tmp/default
  21. [root@puppetmaster default]# ls
  22. de.txt

一、下载安装rsync 模块

puppet 的rsync 模块在GitHub位置 https://github.com/onyxpoint/pupmod-rsync ,大家可以上去查看。

点击(此处)折叠或打开

  1. [root@puppetmaster ~]# cd /etc/puppet/modules/
  2. [root@puppetmaster modules]# git clone https://github.com/onyxpoint/pupmod-concat && mv pupmod-concat concat
  3. [root@puppetmaster modules]# git clone https://github.com/onyxpoint/pupmod-rsync && mv pupmod-rsync rsync

说明:我这里是使用git,如果机器没有安装,可以使用yum -y install git 来安装,如不想安装git可以下载zip压缩包.解压到相应目录.
注意:在server, clent 端都下载安装concat 和rsync 模块。

二、服务端配置文件

1). 新建node.pp

点击(此处)折叠或打开

  1. [root@puppetmaster manifests]# pwd
  2. /etc/puppet/manifests
  3. [root@puppetmaster manifests]# cat node.pp
  4. node 'puppetmaster.manzuoinfo.com' {
  5. include 'rsync::server'
  6. rsync::server::global { 'global':
  7. address => '192.168.0.12'
  8. }
  9. rsync::server::section { 'default':
  10. comment => 'The default file path',
  11. path => '/tmp/default',
  12. hosts_allow => '192.168.0.64'
  13. }
  14. rsync::server::section { 'test':
  15. # auth_users => 'testuser',
  16. comment => 'Test comment',
  17. path => '/tmp/test',
  18. hosts_allow => '192.168.0.64',
  19. outgoing_chmod => 'o-w'
  20. }
  21. }
  22. node 'puppet1.manzuoinfo.com' {
  23. include 'rsync'
  24. }

2). 新建modules.pp 载入rsync 模块

点击(此处)折叠或打开

  1. [root@puppetmaster manifests]# pwd
  2. /etc/puppet/manifests
  3. [root@puppetmaster manifests]# cat modules.pp
  4. import "rsync"

3). 把 node.pp modules.pp 包进site.pp

点击(此处)折叠或打开

  1. [root@puppetmaster test]# cat /etc/puppet/manifests/site.pp
  2. import 'node.pp'
  3. import 'modules.pp'

4). 测试配置文件

点击(此处)折叠或打开

  1. [root@puppetmaster manifests]# puppet agent --server=puppetmaster.manzuoinfo.com --test -v
  2. info: Caching catalog for puppetmaster.manzuoinfo.com
  3. info: /Stage[main]/Rsync/Tidy[/etc/rsync]: File does not exist
  4. info: Applying configuration version '1379830750'
  5. notice: /Stage[main]/Rsync/File[/etc/rsync]/ensure: created
  6. notice: /Stage[main]//Node[puppetmaster.manzuoinfo.com]/Rsync::Server::Section[default]/Concat_fragment[rsync+default.section]/content: content changed '' to '[default]
  7. comment = The default file path
  8. path = /home/sky
  9. use chroot = false
  10. max connections = 0
  11. max verbosity = 1
  12. lock file = /var/run/rsyncd.lock
  13. read only = true
  14. write only = false
  15. list = false
  16. uid = root
  17. gid = root
  18. outgoing chmod = o-w
  19. ignore nonreadable = true
  20. transfer logging = true
  21. log format = "%o %h [%a] %m (%u) %f %l"
  22. dont compress = *.gz *.tgz *.zip *.z *.rpm *.deb *.iso *.bz2 *.tbz *.rar *.jar *.pdf *.sar *.war
  23. hosts allow = 192.168.0.64
  24. hosts deny = *
  25. '
  26. notice: /Stage[main]//Node[puppetmaster.manzuoinfo.com]/Rsync::Server::Global[global]/Concat_fragment[rsync+global]/content: content changed '' to 'pid file = /var/run/rsyncd.pid
  27. syslog facility = daemon
  28. port = 873
  29. address = 192.168.0.12
  30. '
  31. notice: /Stage[main]//Node[puppetmaster.manzuoinfo.com]/Rsync::Server::Section[test]/Concat_fragment[rsync+test.section]/content: content changed '' to '[test]
  32. comment = Test comment
  33. path = /home/skywu
  34. use chroot = false
  35. max connections = 0
  36. max verbosity = 1
  37. lock file = /var/run/rsyncd.lock
  38. read only = true
  39. write only = false
  40. list = false
  41. uid = root
  42. gid = root
  43. outgoing chmod = o-w
  44. ignore nonreadable = true
  45. transfer logging = true
  46. log format = "%o %h [%a] %m (%u) %f %l"
  47. dont compress = *.gz *.tgz *.zip *.z *.rpm *.deb *.iso *.bz2 *.tbz *.rar *.jar *.pdf *.sar *.war
  48. hosts allow = 192.168.0.64
  49. hosts deny = *
  50. '
  51. notice: /Stage[main]/Rsync::Server/Concat_build[rsync]/target: global*.section used for ordering
  52. notice: /Stage[main]/Rsync::Server/File[/etc/rsyncd.conf]/mode: mode changed '0644' to '0400'
  53. notice: /Stage[main]/Rsync::Server/File[/etc/rsyncd.conf]/content: audit change: newly-recorded value {md5}2148062cf8d2f7220279fd0ca07b9329
  54. info: /Stage[main]/Rsync::Server/File[/etc/rsyncd.conf]: Scheduling refresh of Service[rsync]
  55. notice: /Stage[main]/Rsync::Server/Service[rsync]/ensure: ensure changed 'stopped' to 'running'
  56. err: /Stage[main]/Rsync::Server/Service[rsync]: Failed to call refresh: Could not stop Service[rsync]: Execution of '/bin/kill `cat \`grep "pid file" /etc/rsyncd.conf | cut -f4 -d' '\``' returned 1: at /etc/puppet/modules/rsync/manifests/server.pp:56
  57. info: Creating state file /var/lib/puppet/state/state.yaml
  58. notice: Finished catalog run in 2.70 seconds
  59. [root@puppetmaster manifests]#

注意:err: 这里出现了一个错误,请根据自己的情况来修改停止rsync,例如:
    stop => "ps -ef | grep [r]sync |awk '{print $2}'|xargs kill -9",

5). 在server 端生成rsync配置

点击(此处)折叠或打开

  1. [root@puppetmaster manifests]# puppetd --test --server puppetmaster.manzuoinfo.com
  2. info: Caching catalog for puppetmaster.manzuoinfo.com
  3. notice: /Stage[main]/Rsync/Tidy[/etc/rsync]: Tidying File[/etc/rsync]
  4. info: /File[/etc/rsync]: Duplicate generated resource; skipping
  5. info: Applying configuration version '1379837152'
  6. notice: /Stage[main]//Node[puppetmaster.manzuoinfo.com]/Rsync::Server::Section[default]/Concat_fragment[rsync+default.section]/content: content changed '[default]
  7. comment = The default file path
  8. path = /home/sky
  9. use chroot = false
  10. max connections = 0
  11. max verbosity = 1
  12. lock file = /var/run/rsyncd.lock
  13. read only = true
  14. write only = false
  15. list = false
  16. uid = root
  17. gid = root
  18. outgoing chmod = o-w
  19. ignore nonreadable = true
  20. transfer logging = true
  21. log format = "%o %h [%a] %m (%u) %f %l"
  22. dont compress = *.gz *.tgz *.zip *.z *.rpm *.deb *.iso *.bz2 *.tbz *.rar *.jar *.pdf *.sar *.war
  23. hosts allow = 192.168.0.64
  24. hosts deny = *
  25. ' to '[default]
  26. comment = The default file path
  27. path = /tmp/default
  28. use chroot = false
  29. max connections = 0
  30. max verbosity = 1
  31. lock file = /var/run/rsyncd.lock
  32. read only = true
  33. write only = false
  34. list = false
  35. uid = root
  36. gid = root
  37. outgoing chmod = o-w
  38. ignore nonreadable = true
  39. transfer logging = true
  40. log format = "%o %h [%a] %m (%u) %f %l"
  41. dont compress = *.gz *.tgz *.zip *.z *.rpm *.deb *.iso *.bz2 *.tbz *.rar *.jar *.pdf *.sar *.war
  42. hosts allow = 192.168.0.64
  43. hosts deny = *
  44. '
  45. notice: /Stage[main]//Node[puppetmaster.manzuoinfo.com]/Rsync::Server::Section[test]/Concat_fragment[rsync+test.section]/content: content changed '[test]
  46. comment = Test comment
  47. path = /home/skywu
  48. use chroot = false
  49. max connections = 0
  50. max verbosity = 1
  51. lock file = /var/run/rsyncd.lock
  52. read only = true
  53. write only = false
  54. list = false
  55. uid = root
  56. gid = root
  57. outgoing chmod = o-w
  58. ignore nonreadable = true
  59. transfer logging = true
  60. log format = "%o %h [%a] %m (%u) %f %l"
  61. dont compress = *.gz *.tgz *.zip *.z *.rpm *.deb *.iso *.bz2 *.tbz *.rar *.jar *.pdf *.sar *.war
  62. hosts allow = 192.168.0.64
  63. hosts deny = *
  64. ' to '[test]
  65. comment = Test comment
  66. path = /tmp/test
  67. use chroot = false
  68. max connections = 0
  69. max verbosity = 1
  70. lock file = /var/run/rsyncd.lock
  71. read only = true
  72. write only = false
  73. list = false
  74. uid = root
  75. gid = root
  76. outgoing chmod = o-w
  77. ignore nonreadable = true
  78. transfer logging = true
  79. log format = "%o %h [%a] %m (%u) %f %l"
  80. dont compress = *.gz *.tgz *.zip *.z *.rpm *.deb *.iso *.bz2 *.tbz *.rar *.jar *.pdf *.sar *.war
  81. hosts allow = 192.168.0.64
  82. hosts deny = *
  83. '
  84. notice: /Stage[main]/Rsync::Server/Concat_build[rsync]/target: global*.section used for ordering
  85. notice: /Stage[main]/Rsync::Server/File[/etc/rsyncd.conf]/mode: mode changed '0644' to '0400'
  86. notice: /Stage[main]/Rsync::Server/File[/etc/rsyncd.conf]/content: audit change: previously recorded value {md5}2148062cf8d2f7220279fd0ca07b9329 has been changed to {md5}8063eb4c3129b055fb0106eb2cfd7912
  87. info: /Stage[main]/Rsync::Server/File[/etc/rsyncd.conf]: Scheduling refresh of Service[rsync]
  88. info: /Stage[main]/Rsync::Server/File[/etc/rsyncd.conf]: Scheduling refresh of Service[rsync]
  89. notice: /Stage[main]/Rsync::Server/Service[rsync]/ensure: ensure changed 'stopped' to 'running'
  90. notice: /Stage[main]/Rsync::Server/Service[rsync]: Triggered 'refresh' from 2 events
  91. notice: Finished catalog run in 3.66 seconds

注意:/etc/rsyncd.conf 是生成的,而不是手动创建的。

内容如下:

点击(此处)折叠或打开

  1. [root@puppetmaster manifests]# cat /etc/rsyncd.conf
  2. pid file = /var/run/rsyncd.pid
  3. syslog facility = daemon
  4. port = 873
  5. address = 192.168.0.12
  6. [default]
  7. comment = The default file path
  8. path = /tmp/default
  9. use chroot = false
  10. max connections = 0
  11. max verbosity = 1
  12. lock file = /var/run/rsyncd.lock
  13. read only = true
  14. write only = false
  15. list = false
  16. uid = root
  17. gid = root
  18. outgoing chmod = o-w
  19. ignore nonreadable = true
  20. transfer logging = true
  21. log format = "%o %h [%a] %m (%u) %f %l"
  22. dont compress = *.gz *.tgz *.zip *.z *.rpm *.deb *.iso *.bz2 *.tbz *.rar *.jar *.pdf *.sar *.war
  23. hosts allow = 192.168.0.64
  24. hosts deny = *
  25. [test]
  26. comment = Test comment
  27. path = /tmp/test
  28. use chroot = false
  29. max connections = 0
  30. max verbosity = 1
  31. lock file = /var/run/rsyncd.lock
  32. read only = true
  33. write only = false
  34. list = false
  35. uid = root
  36. gid = root
  37. outgoing chmod = o-w
  38. ignore nonreadable = true
  39. transfer logging = true
  40. log format = "%o %h [%a] %m (%u) %f %l"
  41. dont compress = *.gz *.tgz *.zip *.z *.rpm *.deb *.iso *.bz2 *.tbz *.rar *.jar *.pdf *.sar *.war
  42. hosts allow = 192.168.0.64
  43. hosts deny = *
  44. [root@puppetmaster manifests]#

6). 启动rsync 服务

点击(此处)折叠或打开

  1. [root@puppetmaster manifests]# /etc/init.d/xinetd restart
  2. Stopping xinetd: [ OK ]
  3. Starting xinetd: [ OK ]
  4. [root@puppetmaster manifests]# ps -ef | grep rsync
  5. root 13227 1 0 16:16 ? 00:00:00 /usr/bin/rsync --daemon --config=/etc/rsyncd.conf
  6. root 13266 3142 0 16:19 pts/0 00:00:00 grep rsync

7). 客户端需要执行rsync类中,我们编辑puppetmaster上的代码文件,添加default 和test。

点击(此处)折叠或打开

  1. [root@puppetmaster manifests]# vim /etc/puppet/modules/rsync/manifests/init.pp
  2. class rsync {
  3. package { "rsync": ensure => "latest" }
  4. # This define provides a useful abstraction for common rsync client side
  5. # activities.
  6. exec { "rsync_stub":
  7. command => "/bin/true",
  8. refreshonly => true
  9. }
  10. file { '/etc/rsync':
  11. ensure => 'directory',
  12. owner => 'root',
  13. group => 'root',
  14. mode => '750'
  15. }
  16. tidy { '/etc/rsync':
  17. size => "0b",
  18. recurse => 'true',
  19. rmdirs => 'true'
  20. }
  21. rsync { 'default':
  22. source => 'default',
  23. target => '/tmp/test1',
  24. server => '192.168.0.12'
  25. }
  26. rsync { 'test':
  27. source => 'test',
  28. target => '/tmp/test',
  29. server => '192.168.0.12'
  30. }
  31. }

三、puppet1 客户端测试

点击(此处)折叠或打开

  1. [root@puppet1 tmp]# puppetd --test --server puppetmaster.manzuoinfo.com
  2. info: Caching catalog for puppet1.manzuoinfo.com
  3. notice: /Stage[main]/Rsync/Tidy[/etc/rsync]: Tidying File[/etc/rsync]
  4. info: /File[/etc/rsync]: Duplicate generated resource; skipping
  5. info: Applying configuration version '1379841152'
  6. notice: /Stage[main]/Rsync/Rsync[test]/do: executed successfully
  7. notice: Finished catalog run in 0.75 seconds
  8. 或者用命令:
  9. [root@puppet1 tmp]# puppet agent --test --server puppetmaster.manzuoinfo.com

点击(此处)折叠或打开

  1. [root@puppet1 test1]# pwd
  2. /tmp/test1
  3. [root@puppet1 test1]# ls
  4. de.txt
  5. [root@puppet1 test]# pwd
  6. /tmp/test
  7. [root@puppet1 test]# ls -l
  8. total 4
  9. -rw-r--r-- 1 root root 0 Sep 23 11:42 10.txt
  10. -rw-r--r-- 1 root root 0 Sep 23 11:42 1.txt
  11. -rw-r--r-- 1 root root 0 Sep 23 11:42 2.txt
  12. -rw-r--r-- 1 root root 0 Sep 23 11:42 3.txt
  13. -rw-r--r-- 1 root root 0 Sep 23 11:42 4.txt
  14. -rw-r--r-- 1 root root 0 Sep 23 11:42 5.txt
  15. -rw-r--r-- 1 root root 0 Sep 23 11:42 6.txt
  16. -rw-r--r-- 1 root root 0 Sep 23 11:42 7.txt
  17. -rw-r--r-- 1 root root 0 Sep 23 11:42 8.txt
  18. -rw-r--r-- 1 root root 0 Sep 23 11:42 9.txt
  19. -rw-r--r-- 1 root root 17 Sep 23 11:42 test.txt

在客户端查看/tmp/test 和 /tmp/test1 目录及文件已经同步过来了。

puppet使用rsync模块同步目录和文件的更多相关文章

  1. puppet使用rsync模块

    puppet使用rsync模块同步目录和文件   环境说明: OS :    CentOS5.4                         i686puppet版本:               ...

  2. rsync 排除指定目录或文件进行同步

    很常见的情况:我想同步/myweb下的 一些php文件 ,  但是不想复制/myweb/log/里边的一些日志文件,因为这些文件太大了,备份也是没有意义的. 现在如果想避开某个路径  直接添加—exc ...

  3. 使用rsync, 向另外一台服务器同步目录和文件的脚本

    #!/bin/bash #亚特兰蒂斯-同步目录#定时任务ini_file="/usr/local/sunlight/conf/rsync-file.ini"target_ip=&q ...

  4. Linux同步目录 保留文件修改时间和权限 rsync

    scp copy文件夹的时候,会强行覆盖文件,导致增量同步的时候不方便,而rsync则能很好解决这个问题. rsync -avz ubuntu@192.168.1.208:/home/ubuntu/m ...

  5. 记一次rsync增量同步远程服务器文件

    rsync remote shell 增量方式同步数据 rsync同步文件有两种方式,一种是daemon的方式(rsync daemon)另一种方式是通过远程shell方式(rsync remote ...

  6. rsync用于同步目录

    rsync是unix/linux下同步文件的一个高效算法,它能同步更新两处计算机的文件与目录,并适当利用查找文件中的不同块以减少数据传输.rsync中一项与其他大部分类似程序或协定中所未见的重要特性是 ...

  7. 类unix系统同步目录,却不同步目录中文件

    rsync -av --del -f '+ */' -f '- *' src/ dst/;用此条命令即可同步同主机间不同目录到一个位置,或是同步道不同主机同位置. 或是用以下命令: ssh 10.18 ...

  8. Python shutil模块(目录和文件操作)

    import shutil #导入shutil模块 copyfileobj方法 将类文件对象fsrc的内容复制到类文件对象fdst shutil.copyfileobj(fsrc, fdst[, le ...

  9. Linux实战教学笔记21:Rsync数据同步工具

    第二十一节 Rsync数据同步工具 标签(空格分隔): Linux实战教学笔记-陈思齐 ---本教学笔记是本人学习和工作生涯中的摘记整理而成,此为初稿(尚有诸多不完善之处),为原创作品,允许转载,转载 ...

随机推荐

  1. 山东省第十届ACM省赛参赛后的学期总结

    5.11,5.12两天的济南之旅结束了,我也参加了人生中第一次正式的acm比赛,虽然是以友情队的身份,但是我依旧十分兴奋. 其实一直想写博客来增加自己的能力的,但是一直拖到现在,正赶上老师要求写一份总 ...

  2. 5分钟学会maven入门

    一.背景 1.定位:Maven是优秀的构建工具 2.意义:自动化构建,即节约了我们每天有相当一部分时间花在编 译.运行单元测试.生成文档.打包和部署等烦琐且不起眼的时间. 3.三要素:目标(Targe ...

  3. 1 基于梯度的攻击——FGSM

    FGSM原论文地址:https://arxiv.org/abs/1412.6572 1.FGSM的原理 FGSM的全称是Fast Gradient Sign Method(快速梯度下降法),在白盒环境 ...

  4. Python全栈开发之2、数据类型-数值、字符串、列表、字典、元组和文件处理

    一.Python 运算符 1.算术运算: 2.比较运算: 3.赋值运算: 4.逻辑运算: 5.成员运算: 二.基本数据类型 1.数字整型 int(整型) 在32位机器上,整数的位数为32位,取值范围为 ...

  5. 索引及explain 详解

    索引的分类: 普通索引:仅加速查询 唯一索引:加速查询 + 列值唯一(可以有null) 主键索引:加速查询 + 列值唯一(不可以有null)+ 表中只有一个 组合索引:多列值组成一个索引,专门用于组合 ...

  6. 设计模式:策略模式(Stratege)

    首先我们需要知道策略模式与状态模式是如此的相似,就犹如一对双胞胎一样.只不过状态模式是通过改变对象内部的状态来帮助对象控制自己的行为,而策略模式则是围绕可以互换的算法来创建成功业务的.两者都可用于解决 ...

  7. java的hashCode和equals为什么要同时重写?

    原因: java规范:相等的对象必须具有相等的散列码(hashCode) 同时对于HashSet和HashMap这些基于散列值(hash)实现的类.key的判断是通过hashCode完成,且散列也是通 ...

  8. [转]C#集合类型大揭秘

    作者:撸码那些事 来源:https://www.cnblogs.com/songwenjie/p/9185790.html 集合是.NET FCL(Framework Class Library)的重 ...

  9. CSS(下)

    目录 CSS(下) CSS属性相关 宽和高 字体属性 背景属性 边框 border-radius display属性 CSS盒子模型 margin外边距 padding内填充 浮动(float) 限制 ...

  10. JS中的继承(下)

    JS中的继承(下) 在上一篇 JS中的继承(上) 我们介绍了3种比较常用的js继承方法,如果你没看过,那么建议你先看一下,因为接下来要写的内容, 是建立在此基础上的.另外本文作为我个人的读书笔记,才疏 ...