本帖最后由 pig2 于 2014-7-18 00:40 编辑
问题导读
1、如何为Puppet环境添加一个图形用户界面(GUI)?
2、怎样使用分类工具来配置主机?
接上一篇CentOS5上Puppet安装配置(一)
6. Puppet Dashboard 配置
Puppet Dashboard可以为你的Puppet环境添加一个图形用户界面(GUI)。Puppet Dashboard可以显示主机上Puppet的运行结果,并且可以提供一个节点分类工具来配置你的主机。
Dashboard是一种运行在Rails上的Ruby应用程序,它还不是可以添加到系统版本中的程序包,但是我们可以从Puppet Labs以RPM或者DEB包的形式获得该软件。我们也可以选择使用yum进行安装。
下面我要介绍的是编译安装!
6.1升级安装ruby
ruby版本太低,下载企业版ruby-enterprise-1.8.7-2011.03.tar.gz
- wget http://rubyenterpriseedition.googlecode.com/files/ruby-enterprise-1.8.7-2011.03.tar.gz
-
- tar zxvf ruby-enterprise-1.8.7-2011.03.tar.gz
-
- cd ruby-enterprise-1.8.7
-
- ruby installer.rb # 进入一个菜单,按Enter继续
-
- # 默认安装在/opt/ruby-enterprise-1.8.7-2011.03/
-
- # export PATH=/opt/ruby-enterprise-1.8.7-2011.03/bin/:$PATH ##设置环境变量
-
- 并添加到/etc/profile
-
- export PATH=/opt/ruby-enterprise-1.8.7-2011.03/bin/:$PATH ##修改系统变量
复制代码
测试
- [root@server ruby-enterprise-1.8.7-2011.03]# ruby -v
-
- ruby 1.8.7 (2011-02-18 patchlevel 334) [x86_64-linux], MBARI 0x6770, Ruby Enterprise Edition 2011.03
-
- [root@server ruby-enterprise-1.8.7-2011.03]# rake -V
-
- rake, version 0.9.2.2
-
- [root@server ruby-enterprise-1.8.7-2011.03]# gem -v
-
- 1.5.2
复制代码
6.2安装rake和rubygems
安装ruby-enterprise会安装自动rake和rubygems
6.3 安装mysql
- # yum install -y mysql mysql-devel mysql-server ruby-mysql
复制代码
6.4 启动数据库服务
- # chkconfig mysqld on && service mysqld start
复制代码
6.5 下载安装Dashboard
- # wget http://puppetlabs.com/downloads/dashboard/puppet-dashboard-1.2.2.tar.gz
-
- #tar xzvf puppet-dashboard-1.2.2.tar.gz
-
- # mv puppet-dashboard-1.2.2 /opt/puppet-dashboard
-
- # groupadd puppet-dashboard
-
- # useradd -g puppet-dashboard puppet-dashboard
-
- # chown -R puppet-dashboard:puppet-dashboard /opt/puppet-dashboard
-
- # cd /opt/puppet-dashboard/config
-
- # cp database.yml{.example,}
-
- # cp settings.yml{.example,}
复制代码
6.6 给mysql创建一个mysql数据库,并且指定用户给puppet
- [root@sample ~]# mysql -u root ← 用root用户登录MySQL服务器
-
- mysql> select user,host,password from mysql.user; ← 查看用户信息
-
- mysql> set password for root@localhost=password('password'); ← 设置root密码
-
- mysql> exit
-
- [root@sample ~]# mysql -u root -p
复制代码
创建一个软连接(根据个人配置):
- #ln -s /tmp/mysql.sock /var/lib/mysql/mysql.sock (yum安装可免)
-
- mysql> create database dashboard default charset utf8;
-
- Query OK, 1 row affected (0.00 sec)
-
- mysql> use dashboard;
-
- Database changed
-
- mysql> grant all on dashboard.* to dashboard@localhost identified by 'dashboard';
-
- Query OK, 0 rows affected (0.02 sec)
-
- mysql> flush privileges;
-
- Query OK, 0 rows affected (0.00 sec)
复制代码
6.8 修改dashboard配置
先进入面板的安装目录,在进行下面的操作:
- #cd /opt/puppet-dashboard/config
-
- 修改database.yml,我们使用生产环境,所以在以下位置修改:
-
- production:
-
- database: dashboard
-
- username: dashboard
-
- password: dashboard
-
- encoding: utf8
-
- adapter: mysql
复制代码
6.9修改mysql配置
- # 修改单行最大容量
-
- vim /etc/my.cnf
-
- # [mysqld] 下加入下面这行
-
- max_allowed_packet = 32M
-
- 重启mysqld
-
- /etc/init.d/mysqld restart
复制代码
6.10 创建数据库表
- # 创建数据库表,注意当前目录仍然是/opt/puppet-dashboard/config
-
- # rake RAILS_ENV=production db:migrate
复制代码
6.11 测试
这个面板是使用内置的Webrick的作为web服务器,不需要再安装apache或者nginx.
现在可以启动了,
- # cd /opt/puppet-dashboard
-
- # script/server -e production
-
- # 找个浏览器,输入:
-
- http://your_ip:3000
-
- # 里面是空的,什么都显示0
复制代码
6.12管理Puppet dashboard
【puppet dashboard配置】:
Server端配置:
注:yum安装puppet的版本号是0.25.X,编译安装的版本号是2.6.X,配置略有不同请注意,
以下是2.7版本的配置。
- # puppetmasterd –configprint libdir
-
- # vi /etc/puppet/puppet.conf
-
- 在【main】添加以下内容:
-
- reports = store, http
-
- # vi /etc/sysconfig/puppetmaster
-
- 添加以下内容:
-
- PUPPETMASTER_EXTRA_OPTS="--reports puppet_dashboard"
-
- 修改显示的时间:
-
- 默认为UTC
-
- /opt/puppet-dashboard/config/environment.rb
-
- #config.time_zone = 'UTC'
-
- config.time_zone = 'Beijing'
-
- 区分大小写,可能不会立即生效。
-
- 启动puppetmaster
- /etc/init.d/puppetmaster restart
复制代码
client端配置:
- # vi /etc/puppet/puppet.conf
- 在【agent】添加以下内容:
- report = true
-
- # vi /etc/sysconfig/puppet
-
- 添加以下内容:
-
- PUPPET_SERVER=server.puppet.com
-
- PUPPET_PORT=8140
-
- PUPPET_LOG=/var/log/puppet/puppet.log
-
- PUPPET_EXTRA_OPTS=--waitforcert=500
-
- 启动puppet:
- /etc/init.d/puppet restart
-
- 或
- pkill puppet
-
- puppetd --test --server server.puppet.com
-
- # 刷新一下浏览器,可以在puppet dashboard上看到:
复制代码
1 pending tasks
在dashboard主机上再执行
- # mkdir -p /var/lib/puppet/lib/puppet/reports/
-
- #cp /opt/puppet-dashboard/ext/puppet/puppet_dashboard.rb /var/lib/puppet/lib/puppet/reports
-
- # rake RAILS_ENV=production reports:import 导入日志
复制代码
还要启动delayed_job这个进程,不然不会有报告数据显示的,用下面的命令启动,该命令启动4个进程
- #env RAILS_ENV=production /opt/puppet-dashboard/script/delayed_job -p dashboard -n 4 -m start
复制代码
或
- # env RAILS_ENV=production script/delayed_job -p dashboard -n 4 -m start
复制代码
关闭命令
- #env RAILS_ENV=production /opt/puppet-dashboard/script/delayed_job -p dashboard -n 4 -m stop
复制代码
6.13 puppet-dashbooard启动脚本
为方便puppet dashboard的启动与停止,我写好了相应的shell脚本,在本文后面提供下载。
- # vi /etc/init.d/puppet-dashboard
- #!/bin/bash
- # chkconfig: - 65 45
- #
- # description: the gui for the puppetmaster
- # Source function library.
- . /etc/rc.d/init.d/functions
- # Start the service Puppet Dashboard
- start() {
- echo -n "Starting Puppet Dashboard: "
- ### Create the lock file ###
- touch /var/lock/subsys/puppetdb
- success [ DISCUZ_CODE_17 ]quot;Puppet Dashboard startup"
- echo
- }
-
- # Restart the service Puppet Dashboard
- stop() {
- echo -n "Stopping Puppet Dashboard: "
- kill -9 `ps ax | grep "/opt/ruby-enterprise-1.8.7-2011.03/bin/ruby /opt/puppet-dashboard/script/serve
- r" | grep -v grep | awk '{ print $1 }'` >/dev/null 2>&1
- ### Now, delete the lock file ###
- rm -f /var/lock/subsys/puppetdb
- success [ DISCUZ_CODE_17 ]quot;Puppet Dashboard shutdown"
- echo
- }
-
- ### main logic ###
- case "$1" in
- start)
- start;;
- stop)
- stop;;
- status)
- status Puppet DB ;;
- restart|reload|condrestart)
- stop
- start
- ;;
- *)
- echo [ DISCUZ_CODE_17 ]quot;Usage: $0 {start|stop|restart|reload|status}"
- exit 1
- esac
- exit 0
复制代码
保存后
- # chmod 755 /etc/init.d/puppet-dashboard
复制代码
6.14 puppet dashboard常用操作命令
当puppet dashboard数据量过多的时候,需要优化数据库,可使用命令:
- # rake RAILS_ENV=production db:raw:optimize
复制代码
清量dashborad一个月之前的数据。可以使用
- # rake RAILS_ENV=production reports:prune upto=1 unit=mon
复制代码
备份puppet dashborad数据库,可以使用如下命令:
- # rake RAILS_ENV=production db:raw:dump
复制代码
备份sql并输出到文件:
- # rake RAILS_ENV=production FILE=/my/backup/file.sql db:raw:dump
复制代码
恢复puppet dashboard数据库,可以使用如下命令:
- # rake RAILS_ENV=production FILE=production.sql db:raw:restore
复制代码
|