Puppet控制台:Puppet Dashboard 搭建详解

Puppet Dashboard 是一个Ruby on Rails程序,用于显示Puppet masteragent的相关信息,它允许你从一个或这个多个Puppet Master 汇总的图形和报告数据。它同时从一个或者多个Puppet master上收集来自于Puppet agent的资产数据(主机的Fact和其他信息),它也能作为一个ENC来配置Puppet节点,并指定这些节点上的类和参数

安装puppet dashboard 需要一些基本的先决条件,包括ruby1.8以及一个用于存储数据的MYSQL数据库

一:安装环境准备

1. 通过使用YUM来安装一些需要依赖和使用的包

yum install -y ruby ruby-devel ruby-irb ruby-mysql ruby-rdoc ruby-ri rubygems rubygem-rake  rubygem-rails

2. 安装MYSQL

yum install mysql mysql-server mysql-devel

安装MYSQL 遇到问题

yum install mysql mysql-devel mysql-server

Error: Package: mysql-server-5.1.61-1.el6_2.1.x86_64 (updates)

          Requires: libmysqlclient_r.so.16()(64bit)

          Available: mysql-libs-5.1.52-1.el6_0.1.x86_64 (base)

              libmysqlclient_r.so.16()(64bit)

          Available: mysql-libs-5.1.61-1.el6_2.1.x86_64 (updates)

              libmysqlclient_r.so.16()(64bit)

          Installed: mysql-libs-5.5.29-1.el6.x86_64 (@base)

              Not found

解决办法:可能是因为更新了YUM源,提示版本有冲突,先把之前安装的MYSQL插件都给卸载掉,再重新安装

rpm -e mysql-5.5.29-1.el6.x86_64 --nodeps

rpm -e mysql-libs-5.5.29-1.el6.x86_64 --nodeps

rpm -e mysql-devel-5.5.29-1.el6.x86_64 --nodeps

之后重新安装mysql

yum install mysql mysql-server mysql-devel -y

service mysqld start  会自动去初始化MYSQL

设置root用户的密码

mysqladmin  -u root password "passwd"    ###设置密码

3. 配置MYSQL

创建数据库和用户

create database dashboard default charset utf8;

mysql> grant all privileges on dashboard.* to dashboard@localhost identified by 'passwd';

Query OK, 0 rows affected (0.00 sec)

mysql> flush privileges;

Query OK, 0 rows affected (0.00 sec)

4.安装puppet-dashboard

 1.git clone git://github.com/puppetlabs/puppet-dashboard.git

或者

 2. Yum install puppet-dashboard

或者

 3. wget http://puppetlabs.com/downloads/dashboard/puppet-dashboard-1.2.0.tar.gz

通过上面的三种方法都可以安装puppet-dashboard

puppet dashboard 安装好以后,需要创建一个数据库来存储dashboard的数据,然后在dashboard中配置这个数据库,并使用合适的表来填充,目前后端只支持MYSQL

分三步:

编辑YAML配置文件(database.yml)来指定数据库

使用rubyrake命令基于编辑好的配置文件创建数据库“dashboard

填充数据


 如果使用了第二种方法,yum 安装会把puppet-dashboard放在/usr/share/目录下

 如果使用第一种方法,尽量就在/usr/share/ 目录下执行,前提是需要提前安装git工具(yum install -y git

 如果使用了第三种,将下载好的压缩包解决,之后:

 mv puppet-dashboard-1.2.0 /usr/share/puppet-dashboard

5.配置dashboard

/usr/share/puppet-dashboard/config 

 cp database.yml.example database.yml

 cp settings.yml.example  settings.yml

编辑 vi database.yml

修改如下

production:

 database: dashboard database name

 username: dashboard  username

 password: passwd     passwd

 encoding: utf8

 adapter: mysql

Database.yml 文件包含了不同Rails环境的一系列数据库配置。在每一个环境的配置块中我们都需要指定舒勇的数据库的名字、用于连接数据库的用户名和密码,已经编码格式和数据库类型。

之前的MYSQL配置中已经创建了库,用rubyrake命令来创建表

config]# rake RAILS_ENV=production db:migrate(在 /usr/share/puppet-dashboard/config下执行这条命令)

(in /usr/share/puppet-dashboard)

rake aborted!

no such file to load -- openssl

解决办法:

cd /tmp/ruby-1.8.7/ext/openssl/

ruby  extconf.rb  && make && make install

遇到ERROR: # gem install rake

ERROR:  Loading command: install (LoadError)

no such file to load -- zlib

ERROR:  While executing gem ... (NameError)

uninitialized constant Gem::Commands::InstallCommand

解决办法:

/tmp/ruby-1.8.7/ext/zlib  

ruby  extconf.rb  && make && make install

解决问题后,继续执行

# rake RAILS_ENV=production db:migrate

ERROR : !!! The bundled mysql.rb driver has been removed from Rails 2.2. Please install the mysql gem and try again: gem install mysql.

rake aborted!

no such file to load -- mysql

执行命令: gem install mysql

提示ERROR:到目录:/usr/local/lib/ruby/gems/1.8/gems/mysql-2.9.1/ext/mysql_api 执行

ruby extconf.rb  --with-mysql-config=/usr/lib64/mysql/mysql_config

checking for mysql_ssl_set()... no

checking for rb_str_set_len()... no

checking for rb_thread_start_timer()... no

checking for mysql.h... no

checking for mysql/mysql.h... no

*** extconf.rb failed ***

Could not create Makefile due to some reason, probably lack of

necessary libraries and/or headers.  Check the mkmf.log file for more

details.  You may need configuration options.

通过mkmf.log看详细日志,提示

conftest.c:1:25: 错误:mysql/mysql.h:没有那个文件或目录

解决办法:

Yum install mysql-devel

之后重新编译:

ruby extconf.rb  --with-mysql-config=/usr/lib64/mysql/mysql_config

&& make && make install

没有问题之后,继续执行命令,创建表

# rake RAILS_ENV=production db:migrate

提示ERROR:

no such file to load — mysql (日志文件很长,截取一部分)

/usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `gem_original_require

/usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `require

/usr/lib/ruby/gems/1.8/gems/activesupport-2.3.2/lib/active_support/dependencies.rb:156:in `require

/usr/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/connection_adapters/mysql_adapter.rb:65:in `mysql_connection’ no such file to load — mysql

/usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `gem_original_require

/usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `require

解决办法:修改mysql_adapter.rb的配置文件

vi /usr/share/puppet-dashboard/vendor/rails/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb

修改:require_library_or_gem(mysql替换为:

require_library_or_gem('/usr/local/lib/ruby/gems/1.8/gems/mysql-2.9.1/ext/mysql_api/mysql_api.so')

之后保存,退出!再次执行创建表命令:

# rake RAILS_ENV=production db:migrate  ####无错误提示

登录数据库产看:

puppet-dashboard]# mysql -u dashboard -ppasswd  -D dashboard -e "show tables;"

+------------------------------+

| Tables_in_dashboard          |

+------------------------------+

| delayed_job_failures         |

| delayed_jobs                 |

| metrics                      |

| node_class_memberships       |

| node_classes                 |

| node_group_class_memberships |

OK,有表被创建了

二:运行puppet dashboard

/usr/share/puppet-dashboard/script/server -e production

=> Booting WEBrick

=> Rails 2.3.12 application starting on http://0.0.0.0:3000

=> Call with -d to detach

=> Ctrl-C to shutdown server

[2014-02-26 22:36:18] INFO  WEBrick 1.3.1

[2014-02-26 22:36:18] INFO  ruby 1.8.7 (2008-05-31) [x86_64-linux]

[2014-02-26 22:36:18] INFO  WEBrick::HTTPServer#start: pid=24155 port=3000

这样启动,是在3000端口上运行Webrick 服务器,现在就可以通过

http://puppet-dashboard:3000/ 来查看Dashboard,防火墙要开放3000端口

三:结合passenger运行puppet dashboard

因为passenger Webrick复杂得多,也比Webrick具有更好的性能,还能和APACHE或者Nginx 组合在一起,使用passenger的主要优势是:对于dashboard 的引擎来说,它比Webrick快很多并且具有更好的性能

1.安装依赖的软件包

.yum install -y ruby ruby-libs ruby-devel httpd httpd-devel

2. Gem 安装passengerpassenger 不能在Redhat上以包的形式安装

[root@]# gem install passenger

Fetching: daemon_controller-1.1.8.gem (100%)

Fetching: rack-1.5.2.gem (100%)

Fetching: passenger-4.0.37.gem (100%)

提示error:  install Curl development headers with SSL support:

  Please install it with yum install curl-devel

执行yum install curl-devel -y ,之后再次执行 gem install passenger

3.加载Apache passenger 模块

需要使用passenger-install-apache2-module脚本来创建所需要的Apache Passenger模块

执行命令:passenger-install-apache2-module


之后 一直回车(enter),会有提示:

LoadModule passenger_module /usr/local/lib/ruby/gems/1.8/gems/passenger-4.0.37/buildout/apache2/mod_passenger.so

  <IfModule mod_passenger.c>

    PassengerRoot /usr/local/lib/ruby/gems/1.8/gems/passenger-4.0.37

    PassengerDefaultRuby /usr/local/bin/ruby

  </IfModule>

4.配置Apache的虚拟主机,通过同IP不同端口来(808080

vi /etc/httpd/conf/httpd.conf

    添加一行: listen 8080

Load 模块下添加如下代码

LoadModule  passenger_module /usr/local/lib/ruby/gems/1.8/gems/passenger-4.0.37/buildout/apache2/mod_passenger.so

PassengerRoot /usr/local/lib/ruby/gems/1.8/gems/passenger-4.0.37

PassengerDefaultRuby /usr/local/bin/ruby

这些代码都是之前你脚本获取到的:passenger-install-apache2-module

编辑  vi /etc/httpd/conf.d/vhost.conf

案例一:

<VirtualHost *:80>
     ServerName puppetmaster.xxb.cn
     DocumentRoot  /usr/share/puppet-dashboard/public/
     <Directory /usr/share/puppet-dashboard/public/>
        # This relaxes Apache security settings.
        AllowOverride all
        # MultiViews must be turned off.
        Options -MultiViews
     </Directory>
</VirtualHost>

案例二:

Listen 8080

<VirtualHost 10.10.10.118:8080>

     ServerName 10.10.10.118:8080

     DocumentRoot  /usr/share/puppet-dashboard/public/

     <Directory /usr/share/puppet-dashboard/public/>

        # This relaxes Apache security settings.

        AllowOverride all

        # MultiViews must be turned off.

        Options -MultiViews

     </Directory>

</VirtualHost>

这两个一个是通过域名,一个是通过IP:PORT来访问的

这样就可以看到puppet-dashboard 的主页了wKioL1MNsK2h45TFAALC_kiuGt8816.jpg

目前,dashboard工具的一个局限是缺乏身份验证、授权和加密

可以通过iptables 配置一个基于主机和网络的防火墙来限制dashboard的访问

后面的文章会继续写puppet-dashboard的一些功能,以及同样是Puppet GUI的另外一个项目:Foreman






      本文转自天真花语  51CTO博客,原文链接: http://blog.51cto.com/caibird/1363880 ,如需转载请自行联系原作者


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值