Puppet安装配置使用

Standard

记得以前看过,貌似感觉cfengin比较好,不过既然老外那边已经用了这个,那花些时间再看看熟熟手。

vi /etc/hosts
192.168.0.10 puppetserver
192.168.0.11 puppetclient1
#yemaosheng.com
yum -y install ruby ruby-libs ruby-rdoc
wget http://yum.puppetlabs.com/el/6/products/i386/puppetlabs-release-6-7.noarch.rpm
yum install puppetlabs-release-6-7.noarch.rpm
[server] yum -y install puppet-server
[server] service puppetmaster start
 
[client] yum -y install puppet
[client] puppet agent --no-daemonize --onetime --verbose --debug --server=puppetserver
 
[server] puppet cert list --all #会看到一个前面没有+号的client key
[server] puppet cert --sign puppetclient1 #确认client的key

在puppetclient1上新建一个helloworld.txt文件

[server] vi /etc/puppet/manifests/site.pp
node default {
  file {
    "/tmp/helloworld.txt": content => "hello, world";
  }
}
[client] puppet agent --test --server=puppetserver

在puppetclient1上安装tree

[server] vi /etc/puppet/manifests/site.pp
import 'nodes.pp'
[server] vi /etc/puppet/manifests/nodes.pp
node 'puppetclient1' {
      include tree
}
[server] vi /etc/puppet/puppet.conf
modulepath=/etc/puppet/modules:/var/lib/puppet/modules:/opt/modules
[server] mkdir -p /etc/puppet/modules/tree/{files,manifests,templates}
[server] vi /etc/puppet/modules/tree/manifests/init.pp
class tree {
  package { tree:
    ensure => present,
  }
  #类型 { 标题:
  #  属性 => 值,
  #  }
  #}
}
[client] puppet agent --no-daemonize --verbose --debug --server=puppetserver

在puppetclient1上安装memcached并同步配置文件

[server] mkdir -p /etc/puppet/modules/memcached/{files,manifests,templates}
[server] cp /etc/sysconfig/memcached /etc/puppet/modules/memcached/files/
[server] vi /etc/puppet/modules/memcached/manifests/init.pp
class memcached {
  package { memcached:
    ensure => present,
  }
  file { '/etc/sysconfig/memcached':
    notify => Service['memcached']
    mode => '644',
    owner => 'root',
    group => 'root',
    source => 'puppet:///modules/memcached/memcached',
  }
  service { 'memcached':
    ensure => 'running',
    enable => 'true',
  }
}
[client] puppet agent --server=puppetserver

从master主动发指命让agent同步

[client] vi /etc/puppet/auth.conf
path /
auth any
allow *
 
[client] vi /etc/puppet/puppet.conf
...
listen = true
...
 
[server] puppet kick --host puppetclient1

安装配置Mcollective

[server] yum -y install activemq mcollective mcollective-client
[server] vi /etc/activemq/activemq.xml #修改默认用户名及密码
[server] service atcivemq start
[server] vi /etc/mcollective/server.cfg #修改plugin.stomp.*默认值连接到activemq
[server] service mcollective start
 
[server] mkdir -p /etc/puppet/modules/mcollective/{files,manifests,templates}
[server] cp /etc/mcollective/server.cfg /etc/puppet/modules/mcollective/files/
[server] chmod 644 /etc/puppet/modules/mcollective/files/server.cfg
[server] vi /etc/puppet/modules/mcollective/manifests/init.pp
class mcollective {
  package { mcollective:
    ensure => present,
  }
  file { '/etc/mcollective/server.cfg':
    notify => Service['mcollective']
    mode => '640',
    owner => 'root',
    group => 'root',
    source => 'puppet:///modules/mcollective/server.cfg',
  }
  service { 'mcollective':
    ensure => 'running',
    enable => 'true',
  }
}
 
[server] mco find
puppetserver
puppetclient1
 
[client] yum -y install mcollective-service-agent
[client] service mcollective restart
[server] yum -y install mcollective-service-client
[server] mco rpc service start service=httpd -v #启动puppetclient1机上的httpd服务
[server] mco rpc service stop service=httpd -v #停止puppetclient1机上的httpd服务
 
[client] yum -y install mcollective-puppet-agent
[client] service mcollective restart
[server] yum -y install mcollective-puppet-client
[server] mco puppet status

安装Dashboard

[server] yum -y install puppet-dashboard
mysql> create database dashboard default charset utf8;
mysql> use dashboard;
mysql> grant all on dashboard.* to dashboard@localhost identified by 'dashboard' ;
mysql> flush privileges;
[server] vi /usr/share/puppet-dashboard/config/database.yml
production:
  database: dashboard
  username: dashboard
  password: dashboard
  encoding: utf8
  adapter: mysql
  #用ruby的rake命令创建数据库和创建表
[server] cd /usr/share/puppet-dashboard/
[server] rake RAILS_ENV=production db:create
[server] rake RAILS_ENV=production db:migrate
 
#运行puppet-dashboard
[server] /usr/share/puppet-dashboard/script/server -e production
#或是
[server] /etc/init.d/puppet-dashboard start
#这样将用3000端口运行自带的webrick服务器。

官方文档:http://docs.puppetlabs.com/puppet/3/reference/
中文wiki:http://puppet.wikidot.com

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.