有关puppet agent端三种备份恢复方案探讨研究

有关puppetagent端备份恢复方案探讨:

备份方案一、通过自定义facter结合元素backup进行备份恢复
一、facter部署
1、创建目录结构
[root@puppetserver modules]# mkdirpublic/{modules,manifests,files,lib/facter} -p


2、打开模块中的插件功能
[root@puppetserver public]# vim/etc/puppet/puppet.conf
[main]
pluginsync = true
3、编写自定义fact
[root@puppetserver public]# vim/etc/puppet/modules/public/lib/facter/backup_date.rb
# backup_date.rb
#
Facter.add("backup_date") do
setcode do
Facter::Util::Resolution.exec('/bin/date +%Y%m%d%H%M%S')
end
end


4、建立环境变量(测试用)
[root@puppetserver public]# exportFACTERLIB=/etc/puppet/modules/public/lib/facter


5、测试fact(如果不正常,会显示调试信息)
[root@puppetserver puppet]# facterbackup_date
201307241552


6、客户端查看facter是否被下载生效
notice: Starting Puppet client version2.7.21
info: Retrieving plugin
notice:/File[/var/lib/puppet/lib/facter/backup_date.rb]/ensure: defined content as'{md5}91d97be10a35ab7971f77a2be9696031'
info: Loading downloaded plugin/var/lib/puppet/lib/facter/backup_date.rb
info: Loading facts in /var/lib/puppet/lib/facter/backup_date.rb
info: Caching catalog foragent1.bsgchina.com
info: Applying configuration version'1374652447'
notice: Finished catalog run in 1.47seconds
info: Retrieving plugin
info: Loading facts in/var/lib/puppet/lib/facter/backup_date.rb
info: Caching catalog foragent1.bsgchina.com
info: Applying configuration version'1374652447'
notice: Finished catalog run in 1.36seconds


[root@agent1 ssh]# ll/var/lib/puppet/lib/facter/
total 8
-rw-r--r-- 1 root root 138 Jul 24 16:13backup_date.rb
[root@agent1 ssh]#


二、使用backup调用自定义变量
1、在模块的config.pp文件中添加元素backup
[root@puppetserver manifests]# vim/etc/puppet/modules/ssh/manifests/config.pp
class ssh::config{
file { $ssh::params::ssh_service_config:
ensure => present,
owner => 'root',
group => 'root',
mode => 0440,
source =>"puppet:///modules/ssh/etc/ssh/sshd_config",
backup =>".$backup_date.bak",\\添加信息
require =>Class["ssh::install"],
notify =>Class["ssh::service"],
}
}


2、在节点查看对应目录下是否有按日期备份的文件
[root@agent1 ssh]# ll sshd*
-rw-r----- 1 root root 3134 Jul 24 16:20sshd_config
-r--r----- 1 root root 3190 Jul 24 16:17sshd_config.20130724162024.bak
-r--r----- 1 root root 3173 Jul 24 16:20sshd_config.20130724162039.bak

方案二、通过filebucket实现备份的集中化管理,通过节点或者puppetserver进行恢复
1、在site.pp中添加filebucket资源
[root@puppetserver ssh]# vim/etc/puppet/manifests/site.pp


import 'nodes/*'
$puppetserver ='puppetserver.bsgchina.com'


filebucket { 'main':
path => false,#设置agent节点本地不需要保存
#path => "/var/lib/puppet/databackup",
server => 'puppetserver.bsgchina.com'#设置将文件更改过之前的版本保存到远程服务器puppetserver.bsgchina.com上
}


2、在puppetmaster上修改模块配置文件
[root@puppetserver ssh]# vim/etc/puppet/modules/mysql/manifests/config.pp


class mysql::config{
file { "/etc/my.cnf":
ensure => present,
owner => 'mysql',
group => 'mysql',
mode => 0644,
source =>"puppet:///modules/mysql/etc/my.cnf",
backup => 'main',#设置backup备份方式为之前site.pp中定义的main方式
#backup =>".$backup_date.bak",
require =>Class["mysql::install"],
notify =>Class["mysql::service"],
}


file { "/var/lib/mysql":
group => 'mysql',
owner => 'mysql',
recurse => 'true',
require =>File["/etc/my.cnf"],
}


}
3、修改测试文件模拟新版本发布
vim/etc/puppet/modules/mysql/files/etc/my.cnf


4、节点进行监听
[root@agent1 ssh]# puppet agent --server=puppetserver.bsgchina.com--verbose --no-daemonize
info: Retrieving plugin
info: Loading facts in backup_date
info: Loading facts in backup_date
info: Caching catalog foragent3.bsgchina.com
info: Applying configuration version'1374659257'
info: /Stage[main]/Mysql::Config/File[/etc/my.cnf]:Filebucketed /etc/my.cnf to main with sum fef73d96a75424c782191962f5aaf8ee
notice:/Stage[main]/Mysql::Config/File[/etc/my.cnf]/content: content changed '{md5}fef73d96a75424c782191962f5aaf8ee' to '{md5}09fb95f5505056b5a40c4905af3d636e'
info:/Stage[main]/Mysql::Config/File[/etc/my.cnf]: Scheduling refresh ofService[mysqld]
notice:/Stage[main]/Mysql::Service/Service[mysqld]: Triggered 'refresh' from 1 events
notice: Finished catalog run in 4.34seconds
结果:可以看到my.cnf被修改之前的版本MD5为fef73d96a75424c782191962f5aaf8ee

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:http://www.heiqu.com/f748a66da3f56218cf2a5773a02a8547.html