puppet使用rsync模块
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 目录及文件已经同步过来了。
参考文档:http://www.mysqlops.com/2012/02/20/puppet-rsync.html
puppet使用rsync模块的更多相关文章
- puppet使用rsync模块同步目录和文件
puppet使用rsync模块同步目录和文件 2013-09-23 14:28:57 分类: LINUX 环境说明: OS : CentOS5.4 ...
- Puppet主机、模块、类、资源、变量、参数、标签命名规范
Puppet命名规范: 约定说明: 小写字母:"a-z" 大写字母:"A-Z" 数字: "0-9" 句号: "." 下划 ...
- puppet工作原理之模块使用
一.模块介绍 1.什么是模块 通常情况把manifest文件分解成易于理解得结构,例如类文件,配置文件分类存放,并通过某种机制整合使用,这种机制就是模块,有助于结构化.层次化的方式使用puppet,p ...
- 自动化运维工具之Puppet模块
前文我们了解来puppet的变量.流程控制.正则表达式.类和模板的相关话题,回顾请参考https://www.cnblogs.com/qiuhom-1874/p/14079208.html:今天我们来 ...
- Puppet
一个完整的自动化运维包括系统安装.配置管理.服务监控三个方面.那今天咱们大家一起来学习一下Puppet实际运维中的案例.仅供参考,欢迎大家提更多的意见! 一.应用背景 某公司新到500台服务器,需要安 ...
- Puppet的搭建和应用
Puppet的部署与应用 1. 案例概述 作为一名系统管理员,维护服务器正常运行是最基本的职责,在管理几台到几十台服务器时,大部分管理员喜欢自己写小工具来维护,但随着服务器的数量曾多,任务量也逐渐增多 ...
- puppet自动化运维
Puppet实现自动化运维 一.案例分析 1.案例概述: 随着服务器数量的增多,系统管理员任务量也逐渐增加,这时就需要简洁的.强大的框架来完成系统管理任务为实现这一目的,我们将引入一批工具,这批工具是 ...
- Puppet全面详解
1. 概述 puppet是一个开源的软件自动化配置和部署工具,它使用简单且功能强大,正得到了越来越多地关注,现在很多大型IT公司均在使用puppet对集群中的软件进行管理和部署,如google利用p ...
- 运维自动化工具---Puppet
案例环境:-----------------------------------------------------------------主机 操作系统 IP地址 主要软件--------- ...
随机推荐
- lambda一些查询语句
<!--得分数据结构-->1 <Score> <studentid>1</studentid> <courseid>1</course ...
- html script生成二维码
<div class="code" align="center"> <p >手机端扫描以下二维码直接观看(支持安卓Android/苹果i ...
- 安装docker-下载加速、失败、成功安装
前提:已装VMware虚拟机和Centos系统(具体安装包和过程可以百度) 先看这里:非root身份登录系统需要在下面的命令前加“sudo ”(sudo:代表给权限,用root登录则不需要输入) 一. ...
- python实例1-找质数/素数
质数定义:质数(prime number)又称素数.质数定义为在大于1的自然数中,除了1和它本身以外不再有其他因数. 示例解决方案1 有很多方法可以解决这个问题,下面是一些例子:这是一个不同的功能分解 ...
- 深入理解java:1. JVM虚拟机的构成
1.JVM虚拟机的构成 什么是Java虚拟机? 作为一个Java程序员,我们每天都在写Java代码,我们写的代码都是在一个叫做Java虚拟机的东西上执行的. 但是如果要问什么是虚拟机,恐怕很多人就会模 ...
- C语言第十周作业
这个作业属于哪个课程 C语言程序设计 这个作业的要求在哪里 https://edu.cnblogs.com/campus/zswxy/computer-scienceclass3-2018/h ...
- MySQL-快速入门(6)连接查询、子查询、正则表达式查询、数据的插入删除更新
1.内连接查询:inner join ... on 只有满足条件的记录才能够出现在结果关系中,即完全相等.自连接查询是一种特殊的内连接查询. 2.外连接查询: 1>左外连接 / 左连接:返回包括 ...
- 极*Java速成教程 - (6)
Java高级特性 String String是Java中的字符串类型,字符串类型在内存中是一个不可变的对象.如果要对字符串对象进行修改,如果是较少的修改可以使用+运算符,Java会自动进行优化,但如果 ...
- P2672跳石头
这是2015noip的一道二分答案的题目,看了题解才会,, 题目给出石头的位置并且让你踩着石头往前跳,最多删掉m个石头还可以顺利通过,求解最短跳跃距离的最大值. 那么二分什么呢:mid为跳跃的长度.那 ...
- windows10操作系统上使用virtualenv虚拟环境
前提win10上已经安装了Python环境! virtualenv库的使用: 安装 如果win10上同时安装了Python2和python3的安装virtualenv时用; Python2:pip i ...