一、安装环境

  需要两台计算机或虚拟机;一台是server,一台是client;具体配置如下:

cat /etc/hosts

127.0.0.1       localhost.localdomain localhost

192.168.*.200 server.example.com  server

192.168.*.180 client.example.com  client

Note:主机名必须是字母和数字组合,不能有特殊符号如 _ ;否则在调试阶段出现莫名其妙问题;

Note:所有主机要求时钟同步

yum install ntp

chkconfig ntp on

ntpdate pool.ntp.org

Note:配置epel源

rpm -ivh https://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm

yum-config-manager --enable epel

yum update


二、安装Puppet服务

1、服务端

yum install ruby ruby-libs ruby-rdoc #Puppet需要Ruby支持,查看命令行帮助需安装ruby-rdoc

yum install puppet-server

chkconfig puppet on

/etc/init.d/puppetmaster start

关闭iptables和Selinux

2、客户端

yum install puppet

在/etc/puppet/puppet.conf中[agent]加server = server.example.com指定服务端

3、在服务端配置自动签发证书设置

cat /etc/puppet/autosign.conf 

*.example.com

在/etc/puppet/puppet.conf中[main]加autosign = true使autosign.conf生效

/etc/init.d/puppetmaster restart

4、在客户端进行debug测试生成证书

puppet agent --no-daemonize --onetime --verbose --debug

5、在服务端查看证书信息

puppet cert list -all

  "server.example.com"     (25:11:E6:A6:21:55:A3:4F:30:E4:C7:50:92:4C:63:50) (alt names: "DNS:puppet", "DNS:puppet.example.com", "DNS:server.example.com")

+ "client.example.com" (9C:DA:6F:89:C3:5C:4E:73:5A:9F:A6:35:66:FE:53:8E)

前面带“+”表示证书签发成功

6、例子测试

服务端

cat /etc/puppet/manifests/site.pp 

node default {

    file {

        "/tmp/helloworld.txt": content => "hello, world";

    }

}

Note:

err: Could not retrieve catalog from remote server: Error 400 on SERVER: Could not find default node or by name with 'client.example.com, client.example, client' on node client.example.com

warning: Not using cache on failed catalog

err: Could not retrieve catalog; skipping run

可能是/etc/puppet/manifests/site.pp 这个文件书写格式有问题

客户端

puppet agent --test --server=server.example.com

cat /tmp/helloworld.txt 

hello, world


三、在服务端安装Puppet的dashboard工具

1、安装设置mysql

yum install mysql mysql-devel mysql-server -y


在/etc/my.cnf中[mysqld]下加入max_allowed_packet = 32M

/etc/init.d/mysqld start

chkconfig mysqld on

mysqladmin -u root password '123456' 

cat create_dashboard.sql #创建数据库

CREATE DATABASE dashboard CHARACTER SET utf8;

CREATE USER 'dashboard'@'localhost' IDENTIFIED BY '123456';

GRANT ALL PRIVILEGES ON dashboard.* TO 'dashboard'@'localhost';

FLUSH PRIVILEGES;


2、设置yum源和安装puppet-dashboard

由于puppet-dashboard不在centos官方及epel源里,因此要添加puppetlabs源

rpm -ivh http://yum.puppetlabs.com/el/6.4/products/x86_64/puppetlabs-release-6-12.noarch.rpm

yum install puppet-dashboard


3、配置puppet-dashboard

vi /usr/share/puppet-dashboard/config/database.yml

 46 production:

 47   database: dashboard                                            48   username: dashboard

 49   password: 123456

 50   encoding: utf8

 51   adapter: mysql

vi /usr/share/puppet-dashboard/config/environment.rb

 52   config.time_zone = 'Beijing' 

分别是修改数据库配置,时区;

初始化数据库:

rake RAILS_ENV=production db:migrate

检查是否导入成功:

mysql> show tables;

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

| Tables_in_dashboard          |

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

| delayed_job_failures         |

| delayed_jobs                 |

| metrics                      |

| node_class_memberships       |

| node_classes                 |

| node_group_class_memberships |

| node_group_edges             |

| node_group_memberships       |

| node_groups                  |

| nodes                        |

| old_reports                  |

| parameters                   |

| report_logs                  |

| reports                      |

| resource_events              |

| resource_statuses            |

| schema_migrations            |

| timeline_events              |

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

18 rows in set (0.00 sec)


4、启动并运行dashboard(WEBrick方式)

/etc/init.d/puppetmaster restart

/etc/init.d/puppet-dashboard start

访问http://server.example.com:3000/


5、启动并运行dashboard(passenger方式)

rpm -qa httpd httpd-devel apr-util-devel apr-devel mod_ssl
rpm -qa ruby-devel ruby-libs rubygems libcurl-devel
gem install rake --version=10.0.1
gem install rack --version=1.5.2
gem install --local passenger-4.0.19.gem
gem list
以上是安装passenger
passenger-install-apache2-module #安装apache模块
配置passenger
cat /etc/httpd/conf.d/passenger.conf
LoadModule passenger_module /usr/lib/ruby/gems/1.8/gems/passenger-4.0.19/buildout/apache2/mod_passenger.so
PassengerRoot /usr/lib/ruby/gems/1.8/gems/passenger-4.0.19
PassengerDefaultRuby /usr/bin/ruby
PassengerHighPerformance on
PassengerMaxPoolSize 12
PassengerPoolIdleTime 1500
PassengerStatThrottleRate 120

<VirtualHost *:80>
    DocumentRoot /usr/share/puppet-dashboard/public
    <Directory /usr/share/puppet-dashboard/public>
        Options None
        AllowOverride AuthConfig
        Order allow,deny
        allow from all
    </Directory>
    ErrorLog /var/log/httpd/dashboard.error.log
    LogLevel warn
    CustomLog /var/log/httpd/dashboard.access.log combined
</VirtualHost>
启动服务
/etc/init.d/httpd start
/etc/init.d/puppetmaster status
puppetmasterd (pid  29922) is running...
服务端配置实施汇总puppet报告
cat /etc/puppet/puppet.conf 
[main]
    # The Puppet log directory.
    # The default value is '$vardir/log'.
    logdir = /var/log/puppet
    # Where Puppet PID files are kept.
    # The default value is '$vardir/run'.
    rundir = /var/run/puppet
    # Where SSL certificates are kept.
    # The default value is '$confdir/ssl'.
    ssldir = $vardir/ssl
    autosign = true
    reports = http
    reporturl = http://192.168.*.200:80/reports
[agent]
    # The file in which puppetd stores a list of the classes
    # associated with the retrieved configuratiion.  Can be loaded in
    # the separate ``puppet`` executable using the ``--loadclasses``
    # option.
    # The default value is '$confdir/classes.txt'.
    classfile = $vardir/classes.txt
    # Where puppetd caches the local configuration.  An
    # extension indicating the cache format is added automatically.
    # The default value is '$confdir/localconfig'.
    localconfig = $vardir/localconfig

/etc/rc.d/init.d/httpd restart    
#运行“Delayed Job Workers”,使其在后台为我们处理报告日志
rake RAILS_ENV=production jobs:work &