puppet dashboard的安装与部署

发布时间:2020-05-14编辑:脚本学堂
puppet dashboard的安装与部署,供大家参考。

官方:
http://www.puppetlabs.com/puppet/related-projects/dashboard/
文档:
http://docs.puppetlabs.com/dashboard/index.html

一、依旧,需要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 模块
    wget http://rubyforge.org/frs/download.php/75229/rubygems-1.8.7.tgz
    cd rubygems-1.8.7
    ruby setup.rb
安装Rake
gem install rake

安装rack 1.1.0
gem install rack -v 1.1.0
三、安装mysql
安装mysql的gem模块
因为我安装的是二进制的mysql:
    gem install mysql -- --with-mysql-config=/usr/local/mysql/bin/mysql_config

创建数据库
    mysql> create database puppet_dashboard;
    mysql> grant all privileges on puppet_dashboard.* to puppet@localhost identified by 'password';

修改配置文件
/etc/my.cnf
    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
    wget http://downloads.puppetlabs.com/dashboard/puppet-dashboard-1.2rc9.tar.gz
    mv puppet-dashboard-1.2rc9 /usr/local/puppet-dashboard
    cd /usr/local/puppet-dashboard
    cp config/database.yml.example config/database.yml

修改database.yml:
    production:
    database: puppet_dashboard
    username: puppet
    password: password
    encoding: utf8
    adapter: mysql

注意: 冒号后面以空格分隔,而不能以tab分隔

创建表
    cd /usr/local/puppet-dashboard
    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:
    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.

    cd /usr/local/puppet-dashboard
    rake RAILS_ENV=production db:migrate

执行完成后,将在数据库中创建表

六、启动
有些博客上用这样的方法启动
    script/server -p 3100 -d

经测试,这样测试会造成找不到数据库:
[root@gh puppet-dashboard]# script/server -p 3100
=> Booting WEBrick
=> Rails 2.3.5 application starting on http://0.0.0.0:3100
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:
     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)
解决办法:
    ln -s /usr/local/lib/libiconv.so /lib64/libiconv.so.2

关于错误:
/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)
      from /usr/local/ruby/lib/ruby/site_ruby/1.8/rubygems/dependency.rb:256:in `to_spec'
      from /usr/local/ruby/lib/ruby/site_ruby/1.8/rubygems.rb:1200:in `gem'
      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).
详见:http://docs.rubygems.org/read/chapter/16

ok,启动完成:
[root@gh puppet-dashboard]# script/server -e production
=> Booting WEBrick
=> Rails 2.3.5 application starting on http://0.0.0.0:3000
=> 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
    [master]
    reports = store, http
    reporturl = http://1.4.9.18:3000/reports/upload

修改显示的时间:
默认为UTC
/usr/local/puppet-dashboard/config/environment.rb

    #config.time_zone = 'UTC'
     config.time_zone = 'Beijing'

区分大小写,可能不会立即生效。

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


3、导入已经存在的report
    cd /usr/local/puppet_dashboard
    rake RAILS_ENV=production reports:import
    Importing: 100% |##################################| Time: 00:37:21
    11708 of 11710 reports imported
    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

九、启动脚本
  

复制代码 代码如下:
  #!/bin/bash
    #
    # Get function from functions library
    . /etc/init.d/functions
    
    # Start the service Puppet Dashboard
    start() {
            echo -n "Starting Puppet Dashboard: "
            /usr/bin/ruby /usr/local/puppet-dashboard/script/server >/dev/null 2>&1 &
            ### Create the lock file ###
            touch /var/lock/subsys/puppetdb
            success $"Puppet Dashboard startup"
            echo
    }
    
    # Restart the service Puppet Dashboard
    stop() {
            echo -n "Stopping Puppet Dashboard: "
            kill -9 `ps ax | grep "/usr/bin/ruby /usr/local/puppet-dashboard/script/server" | grep -v grep | awk '{ print $1 }'` >/dev/null 2>&1
            ### Now, delete the lock file ###
            rm -f /var/lock/subsys/puppetdb
            success $"Puppet Dashboard shutdown"
            echo
    }
    
    ### main logic ###
    case "$1" in
      start)
            start
            ;;
      stop)
            stop
            ;;
      status)
            status Puppet DB
            ;;
      restart|reload|condrestart)
            stop
            start
            ;;
      *)
            echo $"Usage: $0 {start|stop|restart|reload|status}"
            exit 1
    esac
    
    exit 0


十、性能优化:
当master管理了大量主机,Puppet Dashboard的性能会下降,优化:
定期删除reports这张表的数据,比喻保持一周或者15天。
运行
    rake RAILS_ENV=production reports:prune upto=1 unit=mon

或者执行运行
    rake reports:prune

根据提示来选择删除1小时前、1天前或者一周前的记录,需要在puppet_dashboard目录。

十一、nginx验证
  

复制代码 代码如下:
  server{
    listen 80;
    server_name dashboard.test.com;
    auth_basic "admin";
    auth_basic_user_file /usr/local/nginx/httpassword.user;
      location ~* / {
         root /usr/local/puppet-dashboard/public;
         proxy_pass http://127.0.0.1:3000;
         proxy_redirect off;
         proxy_buffer_size 8k;
         proxy_buffers 4 32k;
         proxy_set_header Host $host;
         proxy_set_header X-Real-IP $remote_addr;
         proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
     }
    }

添加或删除node:
参考:http://docs.puppetlabs.com/dashboard/manual/1.2/rake_api.html

    cd /usr/local/puppet-dashboard
    rake RAILS_ENV=production node:del name=<NAME>

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

运行完成后:
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即可

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