为使用Exported Resources,需要配置puppet支持stordconfig。
一、安装ruby1.8.7
因为RubyGems需要ruby1.8.7
We recommend Ruby 1.8.7 or Ruby 1.9.2 for use with Rails. Ruby 1.8.6 and earlier are not supported, neither is version 1.9.1.
关于ruby1.8.7的安装可以查看:
http://blog.chinaunix.net/space.php?uid=1838361&do=blog&id=2749872
二、安装RubyGems
wget http://rubyforge.org/frs/download.php/75229/rubygems-1.8.7.tgz
cd rubygems-1.8.7
ruby setup.rb
三、使用rubygems安装Rail
对于puppet2.7.3,需要Rail 2.2.2以上
gem install rails -v 2.3.5
注:如果之前已经安装了puppet,但是ruby版本不是1.8.7,需要重新安装puppet。
四、安装mysql
创建用户:
mysql> create database puppet;
mysql> grant all privileges on puppet.* to puppet@localhost identified by 'password';
五、安装mysql的gem模块
因为我的mysql是二进制的,而不是rpm的,所以:
gem install mysql -- --with-mysql-config=/usr/local/mysql/bin/mysql_config
六、配置puppet
1、服务器端
/etc/puppet/puppet.cof
[master]
storeconfigs = true
dbadapter = mysql
dbuser = puppet
dbpassword = password
dbserver = localhost
dbsocket = /tmp/mysql.sock
thin_storeconfigs = true
2、客户端
/etc/puppet/puppet.cof
[master]
storeconfigs = true
thin_storeconfigs = true
关于thin_storeconfigs = true:
This only collects and stores to the database exported resources, tags and host facts.
经测试:
storeconfigs = true必须放在[master]段下,否则报错:
Could not parse configuration file: StoreConfigs not supported without ActiveRecord 2.1 or higher
有些旧的文档写的是 [puppetmasterd]配置段,经测试,对于2.7.3,应该写为[master]:
You have configuration parameter $dbsocket specified in [puppetmasterd], which is a deprecated section. I'm assuming you meant [master]
七、重启master
/etc/init.d/puppetmasterd start
Starting puppetmaster: Failed to load feature test for rails: undefined method `alias_method_chainfor I18n::Backend::Simple:Class Could not parse configuration file: StoreConfigs not supported without ActiveRecord 2.1 or higher
[FAILED]
这个错误和iconv有关,解决办法:
# whereis libiconv.so
libiconv: /usr/local/lib/libiconv.so /usr/local/lib/libiconv.la
# ldd /usr/local/ruby/bin/ruby
linux-vdso.so.1 => (0x00007fff949fa000)
librt.so.1 => /lib64/librt.so.1 (0x0000003972e00000)
libdl.so.2 => /lib64/libdl.so.2 (0x0000003971e00000)
libcrypt.so.1 => /lib64/libcrypt.so.1 (0x0000003985800000)
libm.so.6 => /lib64/libm.so.6 (0x0000003972200000)
libc.so.6 => /lib64/libc.so.6 (0x0000003971a00000)
libpthread.so.0 => /lib64/libpthread.so.0 (0x0000003972600000)
/lib64/ld-linux-x86-64.so.2 (0x0000003971600000)
对于64位系统,可以看到,ruby从/lib64调用so文件,所以,做个软链接。
ln -s /usr/local/lib/libiconv.so /lib64/libiconv.so.2
[root@g ~]# /etc/init.d/puppetmasterd restart
Stopping puppetmaster: [ OK ]
Starting puppetmaster: [ OK ]
八、重启客户端
错误:
Could not retrieve catalog from remote server: Error 400 on SERVER: undefined method `fact_merge' for nil:NilClass
解决:重启master即可。
九、删除nagios某个客户端的配置
#!/usr/bin/perl -w
use strict;
use DBI;
my $ip=shift or die "input ip!";
sub connect_db {
my $host = "127.0.0.1";
my $port = "3306";
my $db = "puppet";
my $user = 'root';
my $pass = 'password';
my $dbh = DBI->connect("DBI:mysql:database=$db:host=$host:port=$port",
$user, $pass, {"RaiseError" => 1,
"AutoCommit" => 1}) or die $!;
return $dbh;
};
my $dbh = connect_db();
my $sql1="delete from puppet.hosts where ip='$ip'";
my $sql2="delete from puppet.resources where title like '%"."$ip'";
$dbh->do($sql1);
$dbh->do($sql2);
unlink "/usr/local/nagios/etc/objects/services/$ip.cfg";
十、性能调优
1、创建表的索引
To optimize some often run Puppet queries on your MySQL database, use the following index:
use puppet;
create index exported_restype_title on resources (exported, restype, title(50));
2、Installing Queuing Support for Storeconfigs
用于减轻puppet master的数据库的压力,我没有做这步。
http://projects.puppetlabs.com/projects/1/wiki/Using_Stored_Configuration
3、关于host增多后,可能造成mysql crash
下面的配置是在 8 CPUs and 12G RAM的服务器上做的配置,实际的参数结合自己的服务器进行调整
innodb_buffer_pool_size=2G
innodb_log_file_size=256M
innodb_log_buffer_size=64M
innodb_additional_mem_pool_size=20M
innodb_flush_method = O_DIRECT
一篇不错的文章:
http://www.masterzen.fr/2009/03/18/omg-storedconfigs-killed-my-database/
4、清除储存的配置
有时需要清除某个node存储的配置,这样做是无害的,因为下次client连接后会再次填充相应的配置。
下载脚本:
https://github.com/puppetlabs/puppet/raw/master/ext/puppetstoredconfigclean.rb
运行:
./puppetstoredconfigclean.rb host1.example.com
./puppetstoredconfigclean.rb --help
参考文章:
http://projects.puppetlabs.com/projects/1/wiki/Using_Stored_Configuration