技术头条 - 一个快速在微博传播文章的方式     搜索本站
您现在的位置首页 --> 系统运维 --> puppet使用rsync来同步文件教程

puppet使用rsync来同步文件教程

浏览:3128次  出处信息

[导读]

大家都知道,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. rsync同步的艺术    (阅读:8126)
  2. 使用Apache 和Passenger来运行puppetmaster    (阅读:6515)
  3. Linux探索:一次删除一百万个文件的最快方法    (阅读:5717)
  4. rsync 的核心算法    (阅读:4404)
  5. Dropbox差异同步算法rsync及其改进算法原理    (阅读:4269)
  6. rsync自动输入密码实现数据备份    (阅读:3981)
  7. 自动化运维之企业实际案例分析    (阅读:3640)
  8. 使用 rsync 或 unison 备份或同步支持 ssh 的 web 主机    (阅读:3181)
  9. rsync主动同步代码    (阅读:3059)
  10. SHELL TIPS: rsync 和 crontab 变量    (阅读:2813)
QQ技术交流群:445447336,欢迎加入!
扫一扫订阅我的微信号:IT技术博客大学习
© 2009 - 2024 by blogread.cn 微博:@IT技术博客大学习

京ICP备15002552号-1