1. 环境准备 OS:CentOS 6.4 关闭selinux和iptables
部署Puppet:1.0 Puppet 3.7部署 安装Puppet源:http://yum.puppetlabs.com/puppetlabs-release-el-6.noarch.rpm
Dashboard是Puppet官方提供的一个简易的Web UI,可以很方便的做Puppet报告的展示和ENC的管理.但是很功能和简易。后面会更新一个更强大的Foreman,敬请期待..
2. 安装Dashboard
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
| #安装dashboard包和mysql数据库
yum install puppet-dashboard mysql-server mysql -y
/etc/init.d/mysqld start
chkconfig mysqld on
#初始化数据库相关...
mysql -e 'CREATE DATABASE dashboard_production CHARACTER SET utf8;'
mysql -e "CREATE USER 'dashboard'@'localhost' IDENTIFIED BY 'dbsa.cn';"
mysql -e "GRANT ALL PRIVILEGES ON dashboard_production.* TO 'dashboard'@'localhost';"
mysql -e 'set GLOBAL max_allowed_packet = 33554432;'
#在/etc/my.cnf中增加以下参数
[mysqld]
max_allowed_packet = 32M
#执行表迁移任务,会生成相关的数据库表..
cd /usr/share/puppet-dashboard/
sed -i 's/UTC/Beijing/' config/environment.rb #修改显示时区
sed -ri 's/s+password:.*/ password: dbsa.cn/' config/database.yml #修改默认的数据库密码..
rake RAILS_ENV=production db:migrate
cp /usr/share/puppet-dashboard/ext/puppet/puppet_dashboard.rb /usr/lib/ruby/site_ruby/1.8/puppet/reports
#使用默认的WEBrick服务运行dashboard测试以下...
cd /usr/share/puppet-dashboard/
./script/server -e production
#访问dashboard...
http://ip:3000/
|
3. 配置Puppet
配置由dashaboard分析Puppet的报告
1
2
3
4
5
| #在Puppet Master上配置...
/etc/puppet/puppet.conf
[master]
reports = store, http
reporturl = http://localhost:3000/reports/upload #localhost是发往dashboard的地址
|
配置由dashboard管理class和parameters
1
2
3
4
5
6
| #在Puppet Master上配置...
/etc/puppet/puppet.conf
[master]
node_terminus = exec
#localhost是发往dashboard的地址
external_nodes = /usr/bin/env PUPPET_DASHBOARD_URL=http://localhost:3000 /usr/share/puppet-dashboard/bin/external_node
|
4. 配置Nginx替代默认的WEBrick
安装Ningx和passenger
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
| yum install ruby-devel rubygems gcc gcc-c++ make -y
yum install curl-devel openssl-devel zlib-devel pcre-devel -y
gem install rake -v 10.4.0 -V
gem install rack -v 1.5.2 -V
gem install passenger -v 3.0.19 -V
#更换gem 源为淘宝的,国内因为gfw更新可能会失败并且很慢.
gem sources -a
gem sources --remove http://rubygems.org/
gem sources -l
#安装nginx...
cd /tmp
wget http://mirrors.sohu.com/nginx/nginx-1.6.2.tar.gz
tar xf nginx-1.6.2.tar.gz
#使用passenger编译Nginx
passenger-install-nginx-module
#选择1,在选择2,
然后在分别输入:
/tmp/nginx-1.6.2
/usr/local/nginx
一路回车...
#puppet rack
mkdir -p /etc/puppet/rack/public
cp /usr/share/puppet/ext/rack/config.ru /etc/puppet/rack
chown -R puppet.puppet /etc/puppet/rack
|
Nginx配置文件:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
| cat > /usr/local/nginx/conf/nginx.conf <<eof
user root;
worker_processes 1;
events {
worker_connections 1024;
}
http {
passenger_root /usr/lib/ruby/gems/1.8/gems/passenger-3.0.19;
passenger_ruby /usr/bin/ruby;
passenger_max_pool_size 32;
include mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"'
'$upstream_addr $upstream_cache_status $upstream_status';
sendfile on;
keepalive_timeout 65;
include /usr/local/nginx/conf/puppet.conf; #如果按照 1.0 在本机部署了Puppet这个就不用注释...
include /usr/local/nginx/conf/dashboard.conf;
}
EOF
cat > /usr/local/nginx/conf/dashboard.conf <<eof
server {
listen 3000;
server_name localhost;
root /usr/share/puppet-dashboard/public;
passenger_enabled on;
access_log /usr/local/nginx/logs/access-3000.log main;
}
EOF
#启动dashboard服务
/usr/local/nginx/sbin/nginx -s reload
touch /usr/share/puppet-dashboard/log/production.log
chown -R puppet-dashboard.puppet-dashboard /usr/share/puppet-dashboard/log
chown -R puppet-dashboard.puppet-dashboard /usr/share/puppet-dashboard/tmp
chmod 666 /usr/share/puppet-dashboard/log/production.log
/etc/init.d/puppet-dashboard-workers start
|
报告处理过程:
1. Puppet Master在收到Agent的报告的时候,会通过http往自身的/reports/upload 接口POST一份..
2. dashboard接收到post来的报告会保存到/usr/share/puppet-dashboard/spool
3. 启动puppet-dashboard-workers 会开始处理报告..。
默认puppet-dashboard-workers 启动两个进程处理,如果报告很多, 可以再配置进程数量.
1
2
3
| cat >> /etc/sysconfig/puppet-dashboard <<eof
CPUS=`cat /proc/cpuinfo |grep process|wc -l`
EOF
|
4. 处理完成的报告会写入数据库
5. 节点管理(ENC)
在前面的master puppet.conf中配置使用enc。
1
2
3
4
5
| #下面是一个测试..
cat > /etc/puppet/manifests/site.pp <<eof
node default {
}
EOF
|
1. 在Dashboard 添加一个class。。(base的class在之前的blog中已经创建过,可以查看1.0 Puppet安装)
2. 选择一个主机..
3. 给这个主机添加class和parameters
4. 查看添加的类和参数..
5. 通过执行命令,查询配置
1
2
3
4
5
6
7
| [iyunv@master ~]# /usr/bin/env PUPPET_DASHBOARD_URL=http://localhost:3000 /usr/share/puppet-dashboard/bin/external_node agent1.dbsa.cn
---
classes:
- base
parameters:
aa: bb
name: agent1.dbsa.cn
|
6. 常用维护命令
导入现有的日志
1
2
| cd /usr/share/puppet-dashboard;rake RAILS_ENV=production reports:import
cd /usr/share/puppet-dashboard;rake RAILS_ENV=production reports:import REPORT_DIR=/path/to/your/reports
|
当数据量过大时,优化数据库
1
| cd /usr/share/puppet-dashboard;rake RAILS_ENV=production db:raw:optimize
|
删除一个月之前的日志
1
| cd /usr/share/puppet-dashboard;rake RAILS_ENV=production reports:prune upto=1 unit=mon
|
删除15天前的日志
1
| cd /usr/share/puppet-dashboard;rake RAILS_ENV=production reports:prune upto=15 unit=day
|
备份数据库
1
| mysqldump --add-locks --create-options --disable-keys --extended-insert --quick --set-charset --user=dashboard --password=dbsa.cn dashboard > production.sql
|
恢复数据库
1
| rake RAILS_ENV=production FILE=production.sql db:raw:restore
|
|