Chinaunix首页 | 论坛 | 博客
  • 博客访问: 570852
  • 博文数量: 434
  • 博客积分: 11187
  • 博客等级: 上将
  • 技术积分: 5221
  • 用 户 组: 普通用户
  • 注册时间: 2009-02-19 01:00
文章分类

全部博文(434)

文章存档

2016年(2)

2013年(1)

2012年(115)

2011年(195)

2010年(32)

2009年(89)

分类:

2012-06-01 12:29:22

原文地址:puppet配置支持storedconfig 作者:xjc2694

为了使用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的安装可以查看:

二、安装RubyGems
  1. wget http://rubyforge.org/frs/download.php/75229/rubygems-1.8.7.tgz
  2. cd rubygems-1.8.7
  3. ruby setup.rb
三、使用rubygems安装Rail
对于puppet2.7.3,需要Rail 2.2.2以上
  1. gem install rails -v 2.3.5
注:如果之前已经安装了puppet,但是ruby版本不是1.8.7,需要重新安装puppet。

四、安装mysql
创建用户:
  1. mysql> create database puppet;
  2. mysql> grant all privileges on puppet.* to puppet@localhost identified by 'password';

五、安装mysql的gem模块
因为我的mysql是二进制的,而不是rpm的,所以:
  1. gem install mysql -- --with-mysql-config=/usr/local/mysql/bin/mysql_config

六、配置puppet
1、服务器端
/etc/puppet/puppet.cof
  1. [master]
  2. storeconfigs = true
  3. dbadapter = mysql
  4. dbuser = puppet
  5. dbpassword = password
  6. dbserver = localhost
  7. dbsocket = /tmp/mysql.sock
  8. thin_storeconfigs = true
2、客户端
/etc/puppet/puppet.cof
  1. [master]
  2. storeconfigs = true
  3. 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
  1. /etc/init.d/puppetmasterd start
  2. 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
  3.                                                            [FAILED]
这个错误和iconv有关,解决办法:
  1. # whereis libiconv.so
  2. libiconv: /usr/local/lib/libiconv.so /usr/local/lib/libiconv.la
  1. # ldd /usr/local/ruby/bin/ruby
  2.         linux-vdso.so.1 => (0x00007fff949fa000)
  3.         librt.so.1 => /lib64/librt.so.1 (0x0000003972e00000)
  4.         libdl.so.2 => /lib64/libdl.so.2 (0x0000003971e00000)
  5.         libcrypt.so.1 => /lib64/libcrypt.so.1 (0x0000003985800000)
  6.         libm.so.6 => /lib64/libm.so.6 (0x0000003972200000)
  7.         libc.so.6 => /lib64/libc.so.6 (0x0000003971a00000)
  8.         libpthread.so.0 => /lib64/libpthread.so.0 (0x0000003972600000)
  9.         /lib64/ld-linux-x86-64.so.2 (0x0000003971600000)
对于64位系统,可以看到,ruby从/lib64调用so文件,所以,做个软链接。
  1. ln -s /usr/local/lib/libiconv.so /lib64/libiconv.so.2
  1. [root@g ~]# /etc/init.d/puppetmasterd restart
  2. Stopping puppetmaster: [ OK ]
  3. Starting puppetmaster: [ OK ]
八、重启客户端
错误:
Could not retrieve catalog from remote server: Error 400 on SERVER: undefined method `fact_merge' for nil:NilClass
解决:重启master即可。

九、删除nagios某个客户端的配置
  1. #!/usr/bin/perl -w
  2. use strict;
  3. use DBI;

  4. my $ip=shift or die "input ip!";

  5. sub connect_db {
  6.     my $host = "127.0.0.1";
  7.     my $port = "3306";
  8.     my $db = "puppet";
  9.         my $user = 'root';
  10.         my $pass = 'password';
  11.     my $dbh = DBI->connect("DBI:mysql:database=$db:host=$host:port=$port",
  12.                 $user, $pass, {"RaiseError" => 1,
  13.                         "AutoCommit" => 1}) or die $!;
  14.     return $dbh;
  15. };


  16. my $dbh = connect_db();
  17. my $sql1="delete from puppet.hosts where ip='$ip'";
  18. my $sql2="delete from puppet.resources where title like '%"."$ip'";

  19. $dbh->do($sql1);
  20. $dbh->do($sql2);

  21. 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;
  1. 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的服务器上做的配置,实际的参数结合自己的服务器进行调整
  1. innodb_buffer_pool_size=2G
  2. innodb_log_file_size=256M
  3. innodb_log_buffer_size=64M
  4. innodb_additional_mem_pool_size=20M
  5. 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

更多puppet配置及使用日志,正在整理中,转载请注明出处,谢谢。
阅读(1356) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~