Chinaunix首页 | 论坛 | 博客
  • 博客访问: 3049122
  • 博文数量: 535
  • 博客积分: 15788
  • 博客等级: 上将
  • 技术积分: 6507
  • 用 户 组: 普通用户
  • 注册时间: 2007-03-07 09:11
文章分类

全部博文(535)

文章存档

2016年(1)

2015年(1)

2014年(10)

2013年(26)

2012年(43)

2011年(86)

2010年(76)

2009年(136)

2008年(97)

2007年(59)

分类: LINUX

2011-09-08 16:03:35

官方:
文档:

一、依旧,需要ruby1.8.7
Ruby or Ruby Enterprise Edition version 1.8.7 — Dashboard 1.2 no longer supports older versions of Ruby, and Ruby 1.9.2 is not yet fully supported.
关于安装ruby1.8.7可以查看我的puppet安装部署的文档。

二、安装RubyGems及gem 模块
  1. wget
  2. cd rubygems-1.8.7
  3. ruby setup.rb

安装Rake
gem install rake

安装rack 1.1.0
gem install rack -v 1.1.0
三、安装mysql
安装mysql的gem模块
因为我安装的是二进制的mysql:
  1. gem install mysql -- --with-mysql-config=/usr/local/mysql/bin/mysql_config
创建数据库
  1. mysql> create database puppet_dashboard;
  2. mysql> grant all privileges on puppet_dashboard.* to puppet@localhost identified by 'password';
修改配置文件
/etc/my.cnf
  1. max_allowed_packet = 32M
四、检查gem的模块
#gem list
*** LOCAL GEMS ***

actionmailer (2.3.5, 2.3.4)
actionpack (2.3.5, 2.3.4)
activerecord (2.3.5)
activeresource (2.3.5, 2.3.4)
activesupport (2.3.5, 2.3.4)
mysql (2.8.1)
rack (1.1.0, 1.0.1)
rails (2.3.5)
rake (0.9.2)

五、安装并配置dashboard
  1. wget http://downloads.puppetlabs.com/dashboard/puppet-dashboard-1.2rc9.tar.gz
  2. mv puppet-dashboard-1.2rc9 /usr/local/puppet-dashboard
  3. cd /usr/local/puppet-dashboard
    cp config/database.yml.example config/database.yml

修改database.yml:
  1. production:
  2. database: puppet_dashboard
  3. username: puppet
  4. password: password
  5. encoding: utf8
  6. adapter: mysql
注意: 冒号后面以空格分隔,而不能以tab分隔

创建表
  1. cd /usr/local/puppet-dashboard
  2. rake install
关于:
NOTE: Gem::SourceIndex#add_spec is deprecated, use Specification.add_spec. It will be removed on or after 2011-11-01.
解决:
For now, downgrade rubygems: 
  1. gem update --system 1.6.2

关于:
rake aborted!
No Rakefile found (looking for: rakefile, Rakefile, rakefile.rb, Rakefile.rb)
很明显,需要在有rakefile的目录执行,即puppet_dashboard目录。

关于:
DEPRECATION WARNING: Rake tasks in vendor/plugins/delayed_job/tasks are deprecated. Use lib/tasks instead.
 (called from /usr/local/puppet-dashboard/vendor/rails/railties/lib/tasks/rails.rb:10)
Please see the README.markdown file for installation instructions.
这个提示可以忽略
2.3.8 attempts to give deprecation notices for things which will go away in
Rails 3.0 & later. In this case it is saying that several of your plugins
should place their rake tasks into the lib directory. While this won't cause
any problems in your app, it is good to start resolving the warnings to be
better prepared for future updates. You may also want to consider using the
gem versions of those plugins if available as that will also eliminate the
deprecation notices. Also with Bundler, the days of needing to vendor gems are
for the most part gone. You can use Bundler with 2.3.8 (I am) & it can make
things much easier for you in terms of dependency management.


  1. cd /usr/local/puppet-dashboard
  2. rake RAILS_ENV=production db:migrate
执行完成后,将在数据库中创建表

六、启动
有些博客上用这样的方法启动
  1. script/server -p 3100 -d
经测试,这样测试会造成找不到数据库:
[root@gh puppet-dashboard]# script/server -p 3100
=> Booting WEBrick
=> Rails 2.3.5 application starting on
Database isn't the current migration version: expected 20110130010154, got 0
You must either run 'rake db:migrate' or set environmental variable NO_MIGRATION_CHECK

应该使用database.yml里的启动方法:
Starting a server with:
  1.  scipt/server -e production
关于错误:
/usr/local/ruby/lib/ruby/1.8/x86_64-linux/iconv.so: libiconv.so.2: cannot open shared object file: No such file or directory - /usr/local/ruby/lib/ruby/1.8/x86_64-linux/iconv.so (LoadError)
解决办法:
  1. ln -s /usr/local/lib/libiconv.so /lib64/libiconv.so.2
关于错误:
  1. /usr/local/ruby/lib/ruby/site_ruby/1.8/rubygems/dependency.rb:247:in `to_specs': Could not find rack (~> 1.1.0) amongst [actionmailer-2.3.5, actionmailer-2.3.4, actionpack-2.3.5, actionpack-2.3.4, activerecord-2.3.5, activeresource-2.3.5, activeresource-2.3.4, activesupport-2.3.5, activesupport-2.3.4, mysql-2.8.1, rack-1.3.2, rack-1.0.1, rails-2.3.5, rake-0.9.2] (Gem::LoadError)
  2.         from /usr/local/ruby/lib/ruby/site_ruby/1.8/rubygems/dependency.rb:256:in `to_spec'
  3.         from /usr/local/ruby/lib/ruby/site_ruby/1.8/rubygems.rb:1200:in `gem'
  4.         from /usr/local/puppet-dashboard/vendor/rails/actionpack/lib/action_controller.rb:
解决办法:
安装rack 1.1.0
gem install rack -v 1.3.2
我的gem list
actionmailer (2.3.12, 2.3.5, 2.3.4)
actionpack (2.3.12, 2.3.5, 2.3.4)
activerecord (2.3.12, 2.3.5)
activeresource (2.3.12, 2.3.5, 2.3.4)
activesupport (2.3.12, 2.3.5, 2.3.4)
cgi_multipart_eof_fix (2.5.0)
daemons (1.1.4)
fastthread (1.0.7)
gem_plugin (0.2.3)
mongrel (1.1.5)
mysql (2.8.1)
rack (1.3.2, 1.1.0, 1.0.1)
rails (2.3.12, 2.3.5)
rake (0.9.2)
rdoc (3.9.3)
rubygems-update (1.6.2)


关于 rack (~> 1.1.0)
>=1.1.0并且 <1.2
运算法则:去掉最后一个数字,然后+1就是要小于的版本号.
例如:gem 'library', '~> 2.2'
Notice that we only include 2 digits of the version. The operator will drop the final digit of a version, then increment the remaining final digit to get the upper limit version number. Therefore ‘~> 2.2’ is equivalent to: [‘>= 2.2’, ‘< 3.0’]. Had we said ‘~> 2.2.0’, it would have been equivalent to: [‘>= 2.2.0’, ‘< 2.3.0’]. The last digit specifies the level of granularity of version control. (Remember, you can alway supply an explicit upper limit if the pessimistic operator is too limited for you).
详见:


ok,启动完成:
[root@gh puppet-dashboard]# script/server -e production
=> Booting WEBrick
=> Rails 2.3.5 application starting on
=> Call with -d to detach
=> Ctrl-C to shutdown server
[2011-08-26 10:21:46] INFO  WEBrick 1.3.1
[2011-08-26 10:21:46] INFO  ruby 1.8.7 (2011-06-30) [x86_64-linux]
[2011-08-26 10:21:46] INFO  WEBrick::HTTPServer#start: pid=30710 port=3000

八、配置report
有些文章中写到要复制puppet_dashboard.rb,这步骤对于2.6以上版本不需要做,官方的文档里写得很清楚。
1、服务器端
/etc/puppet/puppet.conf
  1. [master]
  2. reports = store, http
  3. reporturl = http://1.4.9.18:3000/reports/upload
修改显示的时间:
默认为UTC
/usr/local/puppet-dashboard/config/environment.rb
  1. #config.time_zone = 'UTC'
  2.  config.time_zone = 'Beijing'
区分大小写,可能不会立即生效。

2、客户端
/etc/puppet/puppet.conf
  1. [agent]
  2.     report = true

3、导入已经存在的report
  1. cd /usr/local/puppet_dashboard
  2. rake RAILS_ENV=production reports:import
  3. Importing: 100% |##############################################################################################| Time: 00:37:21
  4. 11708 of 11710 reports imported
  5. 2 reports skipped

4、重启客户端及服务器端
关于错误
err: Could not send report: Error 400 on SERVER: private method `gsub' called for true:TrueClass
puppet master里配置有问题:
report = true 
而不是
reports = true 

九、启动脚本
  1. #!/bin/bash
  2. # Get function from functions library
  3. . /etc/init.d/functions
  4.  
  5. # Start the service Puppet Dashboard
  6. start() {
  7.         echo -n "Starting Puppet Dashboard: "
  8.         /usr/bin/ruby /usr/local/puppet-dashboard/script/server >/dev/null 2>&1 &
  9.         ### Create the lock file ###
  10.         touch /var/lock/subsys/puppetdb
  11.         success $"Puppet Dashboard startup"
  12.         echo
  13. }
  14.  
  15. # Restart the service Puppet Dashboard
  16. stop() {
  17.         echo -n "Stopping Puppet Dashboard: "
  18.         kill -9 `ps ax | grep "/usr/bin/ruby /usr/local/puppet-dashboard/script/server" | grep -v grep | awk '{ print $1 }'` >/dev/null 2>&1
  19.         ### Now, delete the lock file ###
  20.         rm -f /var/lock/subsys/puppetdb
  21.         success $"Puppet Dashboard shutdown"
  22.         echo
  23. }
  24.  
  25. ### main logic ###
  26. case "$1" in
  27.   start)
  28.         start
  29.         ;;
  30.   stop)
  31.         stop
  32.         ;;
  33.   status)
  34.         status Puppet DB
  35.         ;;
  36.   restart|reload|condrestart)
  37.         stop
  38.         start
  39.         ;;
  40.   *)
  41.         echo $"Usage: $0 {start|stop|restart|reload|status}"
  42.         exit 1
  43. esac
  44.  
  45. exit 0

十、性能优化:
当master管理了大量主机,Puppet Dashboard的性能会下降,优化:
定期删除reports这张表的数据,比喻保持一周或者15天。
运行
  1. rake RAILS_ENV=production reports:prune upto=1 unit=mon
或者执行运行
  1. rake reports:prune
根据提示来选择删除1小时前、1天前或者一周前的记录,需要在puppet_dashboard目录。

十一、nginx验证
  1. server{
  2. listen 80;
  3. server_name dashboard.test.com;
  4. auth_basic "admin";
  5. auth_basic_user_file /usr/local/nginx/httpassword.user;
  6.   location ~* / {
  7.      root /usr/local/puppet-dashboard/public;
  8.      proxy_pass
  9.      proxy_redirect off;
  10.      proxy_buffer_size 8k;
  11.      proxy_buffers 4 32k;
  12.      proxy_set_header Host $host;
  13.      proxy_set_header X-Real-IP $remote_addr;
  14.      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  15.  }
  16. }

更多puppet配置及使用日志,正在整理中,转载请注明出处,谢谢。


添加或删除node:
参考:
  1. cd /usr/local/puppet-dashboard
  2. rake RAILS_ENV=production node:del name=


dashboard 1.2需要运行
另外:puppet dashboard里,background task中的pending task只增不减,就是这个问题造成的
cd /usr/local/puppet-dashboard;env =production script/delayed_job -p dashboard -n 4 -m start
关于-n 4,每个cpu core有一个,4个cpu就是4
详见:


运行完成后:
root 2304 1 0 09:26 ? 00:00:00 delayed_job.0_monitor 
root 2305 1 0 09:26 ? 00:00:01 dashboard/delayed_job.0 
root 2309 1 0 09:26 ? 00:00:00 delayed_job.1_monitor 
root 2310 1 0 09:26 ? 00:00:00 dashboard/delayed_job.1 
root 2314 1 0 09:26 ? 00:00:00 delayed_job.2_monitor 
root 2315 1 0 09:26 ? 00:00:00 dashboard/delayed_job.2 
root 2319 1 0 09:26 ? 00:00:00 delayed_job.3_monitor 
root 2320 1 0 09:26 ? 00:00:00 dashboard/delayed_job.3
如何关闭?stop即可

重启服务器后,也需要运行




阅读(4666) | 评论(0) | 转发(1) |
给主人留下些什么吧!~~