手机版
你好,游客 登录 注册
背景:
阅读新闻

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

[日期:2013-07-26] 来源:Linux社区  作者:dreamfire [字体: ]

有关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


5、查看设置的远程服务器端是否正常保存
[root@puppetserver bucket]# ll/var/lib/puppet/bucket/#默认保存路径
total 12
drwxrwx---. 4 puppet puppet 4096 Jul 2417:56 0
drwxrwx---. 3 puppet puppet 4096 Jul 2417:46 e
drwxrwx---. 3 puppet puppet 4096 Jul 2417:48 f


[root@puppetserver bucket]# tree f/
f/
└── e
└── f
└── 7
└── 3
└── d
└── 9
└── 6
└──fef73d96a75424c782191962f5aaf8ee
├── contents
└── paths


8 directories, 2 files
结果:保存成功,保存结果为以上目录结构


6、只恢复某一个节点到上一个版本
[root@agent1 modules]# puppet filebucketrestore /etc/my.cnffef73d96a75424c782191962f5aaf8ee#节点上操作


7、通过调试模式查看节点动态信息
[root@agent1 ssh]# puppet agent--server=puppetserver.bsgchina.com --verbose --no-daemonize
info: Retrieving plugin
info: Loading facts in/var/lib/puppet/lib/facter/backup_date.rb
info: Caching catalog for agent1.bsgchina.com
info: Applying configuration version'1374659257'
info: /File[/etc/my.cnf]: Filebucketed/etc/my.cnf to main with sum fef73d96a75424c782191962f5aaf8ee
notice: /File[/etc/my.cnf]/content: contentchanged '{md5}fef73d96a75424c782191962f5aaf8ee'to '{md5}09fb95f5505056b5a40c4905af3d636e'
info: /File[/etc/my.cnf]: Schedulingrefresh of Class[Mysql::Service]
info: Class[Mysql::Service]: Schedulingrefresh of Service[mysqld]
notice:/Stage[main]/Mysql::Service/Service[mysqld]: Triggered 'refresh' from 1 events
notice: Finished catalog run in 3.65seconds
结果:可正常恢复到上一个版本(由于我这里设置了5秒钟同步puppetserver端,可以看到以上my.cnf被修改过,而且MD5值与上一版本吻合)


8、恢复所有节点到上一个版本
[root@puppetserver etc]# puppet filebucketrestore --local/etc/puppet/modules/mysql/files/etc/my.cnffef73d96a75424c782191962f5aaf8ee


9、通过调试模式查看节点动态信息
[root@agent1 ssh]# puppet agent--server=puppetserver.bsgchina.com --verbose --no-daemonize
notice: Starting Puppet client version2.7.21
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'1374659257'
info: /File[/etc/my.cnf]: Filebucketed/etc/my.cnf to main with sum 09fb95f5505056b5a40c4905af3d636e
notice: /File[/etc/my.cnf]/content: contentchanged '{md5}09fb95f5505056b5a40c4905af3d636e' to '{md5}fef73d96a75424c782191962f5aaf8ee'
info: /File[/etc/my.cnf]: Schedulingrefresh of Class[Mysql::Service]
info: Class[Mysql::Service]: Schedulingrefresh of Service[mysqld]
结果:节点配置文件的MD5值更新为上一个版本的MD5值,恢复成功。


备份方案三、通过本地MD5文件进行备份恢复
[root@agent1 modules]# ll/var/lib/puppet/clientbucket/
total 40
drwxrwx--- 3 root root 4096 Jul 24 10:51 3
drwxrwx--- 3 root root 4096 Jul 22 14:55 7
drwxrwx--- 3 root root 4096 Jul 24 15:31 8
drwxrwx--- 4 root root 4096 Jul 24 10:52 e
drwxrwx--- 3 root root 4096 Jul 22 15:10 f
备份方案三为备份方案二的一部分,实验过程略。

相关阅读:

CentOS 6.3下Puppet安装配置笔记 http://www.linuxidc.com/Linux/2013-05/84738.htm

搭建Puppet负载均衡之Nginx+passenger http://www.linuxidc.com/Linux/2013-04/83567.htm

Puppet自动化Nginx+Mongrel负载均衡配置 http://www.linuxidc.com/Linux/2012-12/76280.htm

linux
相关资讯       Puppet 
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款