puppet使用rsync模块同步目录和文件
分类: 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。
点击(此处)折叠或打开
- [root@puppetmaster test]# cd /tmp/
- [root@puppetmaster tmp]# ls
- default test
- [root@puppetmaster tmp]# cd test
- /tmp/test
- [root@puppetmaster test]# ls -l
- total 4
- -rw-r--r-- 1 root root 0 Sep 22 17:32 10.txt
- -rw-r--r-- 1 root root 0 Sep 22 17:32 1.txt
- -rw-r--r-- 1 root root 0 Sep 22 17:32 2.txt
- -rw-r--r-- 1 root root 0 Sep 22 17:32 3.txt
- -rw-r--r-- 1 root root 0 Sep 22 17:32 4.txt
- -rw-r--r-- 1 root root 0 Sep 22 17:32 5.txt
- -rw-r--r-- 1 root root 0 Sep 22 17:32 6.txt
- -rw-r--r-- 1 root root 0 Sep 22 17:32 7.txt
- -rw-r--r-- 1 root root 0 Sep 22 17:32 8.txt
- -rw-r--r-- 1 root root 0 Sep 22 17:32 9.txt
- -rw-r--r-- 1 root root 17 Sep 22 17:32 test.txt
- [root@puppetmaster default]# pwd
- /tmp/default
- [root@puppetmaster default]# ls
- de.txt
一、下载安装rsync 模块
puppet 的rsync 模块在GitHub位置 https://github.com/onyxpoint/pupmod-rsync ,大家可以上去查看。
点击(此处)折叠或打开
- [root@puppetmaster ~]# cd /etc/puppet/modules/
- [root@puppetmaster modules]# git clone https://github.com/onyxpoint/pupmod-concat && mv pupmod-concat concat
- [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
点击(此处)折叠或打开
- [root@puppetmaster manifests]# pwd
- /etc/puppet/manifests
- [root@puppetmaster manifests]# cat node.pp
- node 'puppetmaster.manzuoinfo.com' {
- include 'rsync::server'
- rsync::server::global { 'global':
- address => '192.168.0.12'
- }
- rsync::server::section { 'default':
- comment => 'The default file path',
- path => '/tmp/default',
- hosts_allow => '192.168.0.64'
- }
- rsync::server::section { 'test':
- # auth_users => 'testuser',
- comment => 'Test comment',
- path => '/tmp/test',
- hosts_allow => '192.168.0.64',
- outgoing_chmod => 'o-w'
- }
- }
- node 'puppet1.manzuoinfo.com' {
- include 'rsync'
- }
2). 新建modules.pp 载入rsync 模块
点击(此处)折叠或打开
- [root@puppetmaster manifests]# pwd
- /etc/puppet/manifests
- [root@puppetmaster manifests]# cat modules.pp
- import "rsync"
3). 把 node.pp modules.pp 包进site.pp
点击(此处)折叠或打开
- [root@puppetmaster test]# cat /etc/puppet/manifests/site.pp
- import 'node.pp'
- import 'modules.pp'
4). 测试配置文件
点击(此处)折叠或打开
- [root@puppetmaster manifests]# puppet agent --server=puppetmaster.manzuoinfo.com --test -v
- info: Caching catalog for puppetmaster.manzuoinfo.com
- info: /Stage[main]/Rsync/Tidy[/etc/rsync]: File does not exist
- info: Applying configuration version '1379830750'
- notice: /Stage[main]/Rsync/File[/etc/rsync]/ensure: created
- notice: /Stage[main]//Node[puppetmaster.manzuoinfo.com]/Rsync::Server::Section[default]/Concat_fragment[rsync+default.section]/content: content changed '' to '[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.64
- hosts deny = *
- '
- 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
- syslog facility = daemon
- port = 873
- address = 192.168.0.12
- '
- notice: /Stage[main]//Node[puppetmaster.manzuoinfo.com]/Rsync::Server::Section[test]/Concat_fragment[rsync+test.section]/content: content changed '' to '[test]
- comment = Test comment
- path = /home/skywu
- 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.64
- hosts deny = *
- '
- notice: /Stage[main]/Rsync::Server/Concat_build[rsync]/target: global*.section used for ordering
- notice: /Stage[main]/Rsync::Server/File[/etc/rsyncd.conf]/mode: mode changed '0644' to '0400'
- notice: /Stage[main]/Rsync::Server/File[/etc/rsyncd.conf]/content: audit change: newly-recorded value {md5}2148062cf8d2f7220279fd0ca07b9329
- info: /Stage[main]/Rsync::Server/File[/etc/rsyncd.conf]: Scheduling refresh of Service[rsync]
- notice: /Stage[main]/Rsync::Server/Service[rsync]/ensure: ensure changed 'stopped' to 'running'
- 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
- info: Creating state file /var/lib/puppet/state/state.yaml
- notice: Finished catalog run in 2.70 seconds
- [root@puppetmaster manifests]#
注意:err: 这里出现了一个错误,请根据自己的情况来修改停止rsync,例如:
stop => "ps -ef | grep [r]sync |awk '{print $2}'|xargs kill -9",
5). 在server 端生成rsync配置
点击(此处)折叠或打开
- [root@puppetmaster manifests]# puppetd --test --server puppetmaster.manzuoinfo.com
- info: Caching catalog for puppetmaster.manzuoinfo.com
- notice: /Stage[main]/Rsync/Tidy[/etc/rsync]: Tidying File[/etc/rsync]
- info: /File[/etc/rsync]: Duplicate generated resource; skipping
- info: Applying configuration version '1379837152'
- notice: /Stage[main]//Node[puppetmaster.manzuoinfo.com]/Rsync::Server::Section[default]/Concat_fragment[rsync+default.section]/content: content changed '[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.64
- hosts deny = *
- ' to '[default]
- comment = The default file path
- path = /tmp/default
- 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.64
- hosts deny = *
- '
- notice: /Stage[main]//Node[puppetmaster.manzuoinfo.com]/Rsync::Server::Section[test]/Concat_fragment[rsync+test.section]/content: content changed '[test]
- comment = Test comment
- path = /home/skywu
- 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.64
- hosts deny = *
- ' to '[test]
- comment = Test comment
- path = /tmp/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.64
- hosts deny = *
- '
- notice: /Stage[main]/Rsync::Server/Concat_build[rsync]/target: global*.section used for ordering
- notice: /Stage[main]/Rsync::Server/File[/etc/rsyncd.conf]/mode: mode changed '0644' to '0400'
- notice: /Stage[main]/Rsync::Server/File[/etc/rsyncd.conf]/content: audit change: previously recorded value {md5}2148062cf8d2f7220279fd0ca07b9329 has been changed to {md5}8063eb4c3129b055fb0106eb2cfd7912
- info: /Stage[main]/Rsync::Server/File[/etc/rsyncd.conf]: Scheduling refresh of Service[rsync]
- info: /Stage[main]/Rsync::Server/File[/etc/rsyncd.conf]: Scheduling refresh of Service[rsync]
- notice: /Stage[main]/Rsync::Server/Service[rsync]/ensure: ensure changed 'stopped' to 'running'
- notice: /Stage[main]/Rsync::Server/Service[rsync]: Triggered 'refresh' from 2 events
- notice: Finished catalog run in 3.66 seconds
注意:/etc/rsyncd.conf 是生成的,而不是手动创建的。
内容如下:
点击(此处)折叠或打开
- [root@puppetmaster manifests]# 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 = /tmp/default
- 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.64
- hosts deny = *
- [test]
- comment = Test comment
- path = /tmp/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.64
- hosts deny = *
- [root@puppetmaster manifests]#
6). 启动rsync 服务
点击(此处)折叠或打开
- [root@puppetmaster manifests]# /etc/init.d/xinetd restart
- Stopping xinetd: [ OK ]
- Starting xinetd: [ OK ]
- [root@puppetmaster manifests]# ps -ef | grep rsync
- root 13227 1 0 16:16 ? 00:00:00 /usr/bin/rsync --daemon --config=/etc/rsyncd.conf
- root 13266 3142 0 16:19 pts/0 00:00:00 grep rsync
7). 客户端需要执行rsync类中,我们编辑puppetmaster上的代码文件,添加default 和test。
点击(此处)折叠或打开
- [root@puppetmaster manifests]# vim /etc/puppet/modules/rsync/manifests/init.pp
- class rsync {
- package { "rsync": ensure => "latest" }
- # This define provides a useful abstraction for common rsync client side
- # activities.
- exec { "rsync_stub":
- command => "/bin/true",
- refreshonly => true
- }
- file { '/etc/rsync':
- ensure => 'directory',
- owner => 'root',
- group => 'root',
- mode => '750'
- }
- tidy { '/etc/rsync':
- size => "0b",
- recurse => 'true',
- rmdirs => 'true'
- }
- rsync { 'default':
- source => 'default',
- target => '/tmp/test1',
- server => '192.168.0.12'
- }
- rsync { 'test':
- source => 'test',
- target => '/tmp/test',
- server => '192.168.0.12'
- }
- }
三、puppet1 客户端测试
点击(此处)折叠或打开
- [root@puppet1 tmp]# puppetd --test --server puppetmaster.manzuoinfo.com
- info: Caching catalog for puppet1.manzuoinfo.com
- notice: /Stage[main]/Rsync/Tidy[/etc/rsync]: Tidying File[/etc/rsync]
- info: /File[/etc/rsync]: Duplicate generated resource; skipping
- info: Applying configuration version '1379841152'
- notice: /Stage[main]/Rsync/Rsync[test]/do: executed successfully
- notice: Finished catalog run in 0.75 seconds
- 或者用命令:
- [root@puppet1 tmp]# puppet agent --test --server puppetmaster.manzuoinfo.com
点击(此处)折叠或打开
- [root@puppet1 test1]# pwd
- /tmp/test1
- [root@puppet1 test1]# ls
- de.txt
- [root@puppet1 test]# pwd
- /tmp/test
- [root@puppet1 test]# ls -l
- total 4
- -rw-r--r-- 1 root root 0 Sep 23 11:42 10.txt
- -rw-r--r-- 1 root root 0 Sep 23 11:42 1.txt
- -rw-r--r-- 1 root root 0 Sep 23 11:42 2.txt
- -rw-r--r-- 1 root root 0 Sep 23 11:42 3.txt
- -rw-r--r-- 1 root root 0 Sep 23 11:42 4.txt
- -rw-r--r-- 1 root root 0 Sep 23 11:42 5.txt
- -rw-r--r-- 1 root root 0 Sep 23 11:42 6.txt
- -rw-r--r-- 1 root root 0 Sep 23 11:42 7.txt
- -rw-r--r-- 1 root root 0 Sep 23 11:42 8.txt
- -rw-r--r-- 1 root root 0 Sep 23 11:42 9.txt
- -rw-r--r-- 1 root root 17 Sep 23 11:42 test.txt
在客户端查看/tmp/test 和 /tmp/test1 目录及文件已经同步过来了。
puppet使用rsync模块同步目录和文件的更多相关文章
- puppet使用rsync模块
puppet使用rsync模块同步目录和文件 环境说明: OS : CentOS5.4 i686puppet版本: ...
- rsync 排除指定目录或文件进行同步
很常见的情况:我想同步/myweb下的 一些php文件 , 但是不想复制/myweb/log/里边的一些日志文件,因为这些文件太大了,备份也是没有意义的. 现在如果想避开某个路径 直接添加—exc ...
- 使用rsync, 向另外一台服务器同步目录和文件的脚本
#!/bin/bash #亚特兰蒂斯-同步目录#定时任务ini_file="/usr/local/sunlight/conf/rsync-file.ini"target_ip=&q ...
- Linux同步目录 保留文件修改时间和权限 rsync
scp copy文件夹的时候,会强行覆盖文件,导致增量同步的时候不方便,而rsync则能很好解决这个问题. rsync -avz ubuntu@192.168.1.208:/home/ubuntu/m ...
- 记一次rsync增量同步远程服务器文件
rsync remote shell 增量方式同步数据 rsync同步文件有两种方式,一种是daemon的方式(rsync daemon)另一种方式是通过远程shell方式(rsync remote ...
- rsync用于同步目录
rsync是unix/linux下同步文件的一个高效算法,它能同步更新两处计算机的文件与目录,并适当利用查找文件中的不同块以减少数据传输.rsync中一项与其他大部分类似程序或协定中所未见的重要特性是 ...
- 类unix系统同步目录,却不同步目录中文件
rsync -av --del -f '+ */' -f '- *' src/ dst/;用此条命令即可同步同主机间不同目录到一个位置,或是同步道不同主机同位置. 或是用以下命令: ssh 10.18 ...
- Python shutil模块(目录和文件操作)
import shutil #导入shutil模块 copyfileobj方法 将类文件对象fsrc的内容复制到类文件对象fdst shutil.copyfileobj(fsrc, fdst[, le ...
- Linux实战教学笔记21:Rsync数据同步工具
第二十一节 Rsync数据同步工具 标签(空格分隔): Linux实战教学笔记-陈思齐 ---本教学笔记是本人学习和工作生涯中的摘记整理而成,此为初稿(尚有诸多不完善之处),为原创作品,允许转载,转载 ...
随机推荐
- Python-数据库索引浅谈
检索原理 检索初识 索引在MySQL中是一种"键",是存储引擎用于快速找到记录的一种数据结构.索引对于良好的检索性能,非常关键,尤其是当表中的数据量越大,索引对于性能的提升越显 ...
- python学习之数据类型(int,bool,str)
第三章 数据类型 3.1 Python基本数据类型 类型 含义 描述 int 整数 主要用来进⾏数学运算 str 字符串 可以保存少量数据并进⾏相应的操作 bool 布尔值 判断真假,True,Fal ...
- 二 MyBatis 从入门到进阶 2 Maven 入门
1 Maven 的使用 1.1 本地仓库与中央仓库 本地仓库:Window \ Preferences \ Maven \ User Settings \ Local Repository 中央仓库: ...
- python 将分词结果写入txt文件
首先我运用的分词工具是结巴分词 import jieba 然后调用jieba.cut( ) 但是jieba.cut 返回的是一个generator的迭代器 他可以显示分词结果 但是无法将结果写入t ...
- [c++] 幂法求特征向量
幂法的原理可参考此篇论文:http://d.wanfangdata.com.cn/Periodical/hnnydxxb2001Z1023 本文求解的是 3 阶矩阵最大特征值及其特征向量 下面是其 C ...
- [转帖]忘记了MariaDB root密码的解决办法
忘记了MariaDB root密码的解决办法 https://www.cnblogs.com/liaojie970/p/6126322.html 貌似跟 mysql 是一样的. 1.停掉mariaDB ...
- ORA-00911: invalid character解决方法
今天在搭建VLS系统后,登录系统测试时发现点击菜单提示错误“ORA-00911:???”.网上很多是因为语句中带分号导致的,但是这次是点开菜单就报错,怀疑是字符集设置的问题. 参考网上的解决方案,添加 ...
- Dedesql数据库类详解(二次开发必备教程)
其实数据库类织梦之前就有一个介绍,http://help.dedecms.com/v53/archives/functions/db/,这篇文章讲解了数据库类的一些常见的使用方法,不过没有结合例子去介 ...
- CVE-2017-17558漏洞学习
简介 这是USB core中的一个拒绝服务漏洞.带有精心设计的描述符的恶意USB设备可以通过在配置描述符中设置过高的bNumInterfaces值来导致内核访问未分配的内存.虽然在解析期间调整了该值, ...
- 如何在LinuxKernel中操作file(set_fs與get_fs)
在Kernel 中,照理說能存取至 0 ~ 4GB.但是實作層面卻是只能讓我們使用到3GB ~ 4GB 這會導致我們無法使用open(),write()這些在user space下的function. ...