IT技术博客大学习 共学习 共进步
全部 移动开发 后端 数据库 AI 算法 安全 DevOps 前端 设计 开发者

puppet使用rsync来同步文件教程

MySQLOPS 数据库与运维自动化技术分享 2012-02-26 23:33:04 累计浏览 4,210 次
本机暂存

[导读]

大家都知道,puppet 同步文件都需要使用puppet 文件服务器,且同步大文件的效率比我们运维经常

使用到的rsync效率低且puppet 文件服务器只支持http和puppet 文件传输协议,幸运的是老外给我

们写好了自定义的provider和相关插件,现在我们只需要下载rsync模块就可以来完成.是不是很期待,

一起来跟sky尝试下吧!

[正文]

puppet rsync模块目前可以在   https://github.com/onyxpoint/pupmod-rsync 上下载,查看,这

里要提醒一下大家,这里面的用到了自定义函数一章节,感兴趣的同学可以自己先看看,关于puppet

自定义函数,sky会在下一章节给大家做个介绍.

puppet rysnc 安装需求:看网页上的readme.需要依赖Concat Module 模块.兼容puppet 2.6.其安装方法:

可以直接下载到puppetmaster的模块路径,一般为/etc/puppet/modules/.或者打成rpm包安装.

里面有说明rpmbuild -bb /etc/puppet/modules/rsync/pkg/pupmod-rsync.spec,rpmbuild需要

自已安装.但在QQ 群里有很多同学,还不知道如何把.tar.gz包的打成rpm包,那下次再完整介绍如何把源文件(.tar.gz)

打成rpm包.方便puppet 管理软件包.

[puppet rsync] 安装步骤:

1. cd /etc/puppet/modules/   #进入模块路径

2.git clone https://github.com/onyxpoint/pupmod-concat && mv pupmod-concat concat #下载并重命名Concat module
3.  git clone https://github.com/onyxpoint/pupmod-rsync && mv pupmod-rsync rsync    #.下载并重合名pupmod rsync

说明:我这里是使用git,如果机器没有安装,可以使用yum -y install git 来安装,如不想安装git可以下载zip压缩包.解压到相应目录.

完成后,可以参考该文档来测试基本使用:

[puppet rsync 同步需求简介]

1.本例中rsync server的IP 为192.168.0.12,客户端IP 为192.168.0.10.sky测试的时候是

同步 rsync server端的/home/skywu目录到192.168.0.10的/tmp/test目录下.

[puppet rsync 基本使用配置]
1.在puppetmaster端设置nodes.pp添加以下内容:

1
2
3
4
5
node 'test2.test.com' {     # 需要安装rsync server的主机名,在这里是test2.test.com
include 'rsync::server'     # 执行rsync::server类,具体内容大家可以看代码
rsync::server::global { 'global'# 设置rsync server的主机IP地址
  address => '192.168.0.12'
}

# Now set up some rsync shares

1
2
3
4
5
rsync::server::section { 'default':    #这里不多说,共享目录,大家懂的.
  comment => 'The default file path',
  path => '/home/sky',
  hosts_allow => '192.168.0.10'      #设置允许rsync客户端连接的IP.
}
1
2
3
4
5
6
7
rsync::server::section { 'test':
#   auth_users => 'testuser',  # 设置用于同步的用户名
   comment => 'Test comment',
   path => '/home/skywu',
   hosts_allow => '192.168.0.10',
   outgoing_chmod => 'o-w' #设置权限
  }

2.在所要安装rsync server的主机上,运行

1
puppet agent --test --server  你的puppetmaster主机名

3.我们可以查看/etc/rsyncd.conf

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

4.客户端需要执行rsync类中,我们编辑puppetmaster上的代码文件,添加如下内容:

1
2
3
4
5
6
7
8
vim rsync/manifests/init.pp
rsync { 'test':
  source => '/home/skywu',
  target => '/tmp/test',
  server => $rsync_server
}
  
5.我们在编辑nodes.pp里添加需要安装rsync客户端的主机名.
1
2
3
node 'test1.test.com' {
include 'rsync'
}

6.在客户端运行

1
2
3
4
5
6
7
8
9
10
11
puppet agent --test --server 你的puppetmaster主机名
info: Caching catalog for test1.test.com
notice: /Stage[main]/Rsync/Tidy[/etc/rsync]: Tidying File[/etc/rsync]
info: /File[/etc/rsync]: Duplicate generated resource; skipping
info: Applying configuration version '1329461158'
notice: /Stage[main]//Node[test1.test.com]/Rsync::Server::Section[default]/Concat_fragment[rsync+default.section]/content: executed successfully
notice: /Stage[main]//Node[test1.test.com]/Rsync::Server::Global[global]/Concat_fragment[rsync+global]/content: executed successfully
notice: /Stage[main]//Node[test1.test.com]/Rsync::Server::Section[test]/Concat_fragment[rsync+test.section]/content: executed successfully
notice: /Stage[main]/Rsync::Server/Concat_build[rsync]/order: global,*.section used for ordering
notice: /Rsync[test]/do: executed successfully
notice: Finished catalog run in 1.17 seconds


4.在rsync客户端验证是否同步成功:
ls -l /tmp/test/skywu
总用量 12
-rw-r-r- 1 root root 198 2012-02-17 14:46 2.pp
-rw-r-r- 1 root root 297 2012-02-17 14:46 3.pp
-rw-r-r- 1 root root 317 2012-02-17 14:46 4.pp

可以看到已经成功,在文档中都有例子,以及各个参数的详细说明,就不多说了,大家感兴趣,可以进一步

测试对比,哈哈.

[总结]

本次测试的puppet rsync使用还是比较简单,也是因为时间关系,没有详细的测试,相应大家都了解

rsync的同步效率.有了puppet rsync模块,这样puppet在同步大文件,以及多文件效率低下这个问题,

就可以基本解决,同学们,可以去rsync来同步的web应用程序,图片,享受这一过程吧! 下一章节就详细

介绍下puppet自定义函数,以及provider和自定义fact.

同分类推荐文章

  1. 从零重建 macOS 开发机:可复现的环境初始化流程 (2026-06-14 20:36:00)
  2. 百度物理网络监控工具开源第二弹:毫秒级监控工具 baize,让你的网络问题无处遁形 (2026-06-11 08:10:28)
  3. How to Set Up Homebrew Tap for Private CLI Tools: A Complete Guide (2026-05-27 02:13:03)

查看更多 DevOps 文章 →

建议继续学习

  1. Git log diff config高级进阶 (累计阅读 24,842)
  2. nginx的配置文件 (累计阅读 9,881)
  3. rsync同步的艺术 (累计阅读 9,597)
  4. Zookeeper研究和应用 (累计阅读 9,481)
  5. 使用Apache 和Passenger来运行puppetmaster (累计阅读 8,315)
  6. Linux探索:一次删除一百万个文件的最快方法 (累计阅读 6,860)
  7. 如何让ssh登录更加安全 (累计阅读 5,711)
  8. rsync 的核心算法 (累计阅读 5,604)
  9. 加速scp传输速度 (累计阅读 5,392)
  10. Dropbox差异同步算法rsync及其改进算法原理 (累计阅读 5,225)