介绍
foreman是一个puppet的生命周期管理系统,类似puppet-dashboard,通过它可以很直观的查看puppet所有客户端的同步状态与facter参数,当前只有Ohad Levy, Frank Sweetser, Paul Kelly三位在默默无闻的管理开发这个项目,更多资料请参见foreman官方站: http://theforeman.org
官方截图: http://theforeman.org/projects/foreman/wiki/Screenshots
本文介绍下foreman安装步骤,供各位研究puppet的朋友参考之用。
系统环境:CentOS5.4
yum源: 光盘iso、dag-rpmforge、fedora-epel (mirrors.sohu.com)
puppet版本:puppet-0.25.4.rpm
前提准备
安装rake
yum install rubygem-rake rubygem-rack-1.0.1-1 rubygem-sqlite3-ruby
下载foreman最新tar包
cd /opt
http://theforeman.org/attachments/download/104/foreman-0.1-5.tar.bz2
tar -jxf foreman-0.1-5.tar.bz2
也可以通过git下载
cd /opt
git clone git://github.com/ohadlevy/foreman.git foreman
cd foreman
git submodule init
git submodule update
复制foreman-report脚本
cp extras/puppet/foreman/files/foreman-report.rb /usr/lib/ruby/site_ruby/1.8/puppet/reports/foreman.rb
添加foreman用户
useradd foreman -d /opt/foreman -M -s /sbin/nologin
安装foreman
cd /opt/foreman
rake Rakefile && rake
# foreman默认使用sqlite数据库,不需要改动数据库配置,
如果你更喜欢MySQL的话,请手动创建
foreman、
foremandevel、
foremantest
三个库,然后
修改数据库配置文件 foreman/config/database.yml 为以下内容。
production:
adapter: mysql
database: foreman
username: root
password:
host: localhost
socket: "/var/lib/mysql/mysql.sock"
development:
adapter: mysql
database: foremandevel
username: root
password:
host: localhost
socket: "/var/lib/mysql/mysql.sock"
test:
adapter: mysql
database: foremantest
username: root
password:
host: localhost
socket: "/var/lib/mysql/mysql.sock"
建立数据库表结构
RAILS_ENV=production rake db:migrate
导入节点与facter信息
# This will import your facts (only new facts) every time you run the script.
rake puppet:import:hosts_and_facts RAILS_ENV=production
# This will create all required settings from your facts.
rake puppet:migrate:populate_hosts RAILS_ENV=production
创建服务文件 /etc/sysconfig/foreman
# the location where foreman is installed
#FOREMAN_HOME=/usr/share/foreman
# the port which foreman web server is running at
# note that if the foreman user is not root, it has to be a > 1024
#FOREMAN_PORT=3000
# the user which runs the web interface
#FOREMAN_USER=foreman
# the rails environment in which foreman runs
#FOREMAN_ENV=production
创建服务启动脚本 /etc/init.d/foreman
#!/bin/bash
#
# Init script for foreman
#
# chkconfig: - 85 15
# description: Init script for foreman
# Source function library.
. /etc/rc.d/init.d/functions
if [ -f /etc/sysconfig/foreman ]; then
. /etc/sysconfig/foreman
fi
prog=foreman
RETVAL=0
# open port 80 need root user
FOREMAN_PORT=${FOREMAN_PORT:-3000}
FOREMAN_USER=${FOREMAN_USER:-root}
FOREMAN_HOME=${FOREMAN_HOME:-/opt/foreman}
FOREMAN_ENV=${FOREMAN_ENV:-production}
FOREMAN_PID=${FOREMAN_PID:-${FOREMAN_HOME}/tmp/pids/server.pid}
start() {
echo -n $"Starting $prog: "
daemon --user ${FOREMAN_USER} /usr/bin/ruby ${FOREMAN_HOME}/script/server -p ${FOREMAN_PORT} -e ${FOREMAN_ENV} -d > /dev/null
# daemon /usr/bin/ruby ${FOREMAN_HOME}/script/server -p 80 -e ${FOREMAN_ENV} -d >/dev/null
RETVAL=$?
if [ $RETVAL = 0 ]
then
echo_success
else
echo_failure
fi
echo
return $RETVAL
}
stop() {
echo -n $"Stopping $prog: "
if [ -f ${FOREMAN_PID} ]; then
killproc -p ${FOREMAN_PID}
RETVAL=$?
else
echo -n $"Foreman was not running.";
failure $"Foreman was not running.";
echo
return 1
fi
echo
return $RETVAL
}
# See how we were called.
case "$1" in
start)
start
;;
stop)
stop
;;
status)
echo -n "Foreman"
status -p $FOREMAN_PID
RETVAL=$?
;;
restart)
stop
start
;;
*)
echo $"Usage: $prog {start|stop|restart}"
exit 1
esac
exit $RETVAL
chmod 755 /etc/init.d/foreman
修改puppetmaster的puppet.conf
reports=log, foreman
配置邮件报警 config/email.yaml
# Outgoing email settings
# config/email.yaml
production:
delivery_method: :smtp
smtp_settings:
address: mail.example.com
port: 25
domain: example.com
authentication: :none
修改基本配置 config/settings.yaml
:modulepath: /etc/puppet/modules/
:tftppath: tftp/
:rrd_report_url: report/
#:ldap: true
#your default puppet server - can be overridden in the host level
#if none specified, plain "puppet" will be used.
:puppet_server: puppet
:unattended: false
#use the following setting to override the default 30 minutes puppet run interval - value must be in minutes
:puppet_interval: 10
:document_root: /var/www
#:puppetrun: true
:administrator:
[email protected]
:failed_report_email_notification: true
启动服务
service foreman start
使用firefox、chrome浏览http://localhost:3000