首页 > 自动化 > puppet > puppet的安装和配置
2015
07-31

puppet的安装和配置

1、安装Puppet-server、puppet和facter
yum -y install facter puppet puppet-server
2、配置puppet.conf
[root@puppetmaster ~]# vim /etc/puppet/puppet.conf #注释已经删除
[main]
logdir = /var/log/puppet #默认日志存放路径
rundir = /var/run/puppet #pid存放路径
ssldir = $vardir/ssl #证书存放目录,默认$vardir为/var/lib/puppet
[agent]
classfile = $vardir/classes.txt
localconfig = $vardir/localconfig
server = master.hadoop #设置agent认证连接master端的服务器名称,注意这个名字必须能够被节点解析
 
[master]
reports = store, http 
3、创建site.pp文件
site.pp文件是puppet读取所有模块pp文件的开始,在3.0版本以前必须设置,否则服务无法启动。
vim /etc/puppet/manifests/site.pp
$puppetserver = 'puppetmaster.kisspuppet.com' #设置全局变量
node 'puppetmaster_cert.kisspuppet.com'{
  include  motd
}
 
二、安装Agent
1、安装puppet和facter
1
[root@slave2 ~]# yum install puppet facter #系统会自己安装一些ruby依赖包环境
2、配置puppet.conf
 
server = master.hadoop #指向puppetmaster端
3、通过调试模式启动节点向Puppetmaster端发起认证
5># puppet agent --test
info: Creating a new SSL key for slave2.hadoop
info: Caching certificate for ca
info: Creating a new SSL certificate request for slave2.hadoop
info: Certificate Request fingerprint (SHA256): A7:36:3F:99:58:D0:97:43:80:A1:9D:D5:5E:E1:D4:11:65:6D:64:CD:AB:FE:71:47:73:6A:C7:31:5D:4A:C6:BC
Exiting; no certificate found and waitforcert is disabled
4、服务器端确定认证
5># puppet cert --list --all
  "slave2.hadoop" (A8:50:F0:CE:82:05:A7:16:2E:86:B2:C3:16:75:41:2A)
+ "master.hadoop" (B8:66:FA:8D:BA:BC:44:9B:18:61:4F:7D:F9:8F:FC:E1) (alt names: "DNS:master.hadoop", "DNS:puppet", "DNS:puppet.hadoop")
26># puppet cert --sign slave2.hadoop #注册slave2.hadoop 
notice: Signed certificate request for slave2.hadoop
notice: Removing file Puppet::SSL::CertificateRequest slave2.hadoop at '/var/lib/puppet/ssl/ca/requests/slave2.hadoop.pem'
---------------------------------------------------------------------------------------------
 
[11:14:56] PWD => /etc/puppet
27># puppet cert --list --all        
+ "master.hadoop" (B8:66:FA:8D:BA:BC:44:9B:18:61:4F:7D:F9:8F:FC:E1) (alt names: "DNS:master.hadoop", "DNS:puppet", "DNS:puppet.hadoop")
+ "slave2.hadoop" (4A:70:E1:49:42:9E:FC:A9:A3:E0:93:07:A4:31:6F:FB)   #已经注册成功
5、其它节点一起认证
在其它的slave节点安装好后
都执行下 ># puppet agent --test
 
在master查看所有节点认证
># puppet cert --list --all
  "slave1.hadoop" (DF:54:E3:07:D8:5E:BA:52:2A:D4:9F:BC:40:38:81:74)
  "slave3.hadoop" (E4:C8:A6:38:1E:B2:04:9E:BB:D0:C6:96:26:2F:BA:12)
  "slave4.hadoop" (22:0C:00:B9:1D:CE:C9:EC:47:AE:8F:2F:DC:CE:C5:A5)
+ "master.hadoop" (B8:66:FA:8D:BA:BC:44:9B:18:61:4F:7D:F9:8F:FC:E1) (alt names: "DNS:master.hadoop", "DNS:puppet", "DNS:puppet.hadoop")
+ "slave2.hadoop" (4A:70:E1:49:42:9E:FC:A9:A3:E0:93:07:A4:31:6F:FB)
 
>#  puppet cert --sign --all #注册所有请求的节点
notice: Signed certificate request for slave1.hadoop
notice: Removing file Puppet::SSL::CertificateRequest slave1.hadoop at '/var/lib/puppet/ssl/ca/requests/slave1.hadoop.pem'
notice: Signed certificate request for slave4.hadoop
notice: Removing file Puppet::SSL::CertificateRequest slave4.hadoop at '/var/lib/puppet/ssl/ca/requests/slave4.hadoop.pem'
notice: Signed certificate request for slave3.hadoop
notice: Removing file Puppet::SSL::CertificateRequest slave3.hadoop at '/var/lib/puppet/ssl/ca/requests/slave3.hadoop.pem'
---------------------------------------------------------------------------------------------
三、编写简单的motd模块
1、创建模块目录结构
注意:再未指定modulepath搜索路径的情况下,会有默认搜索路径的,可通过以下方式查看到
 
[root@puppetmaster ~]# puppet master --genconfig >/etc/puppet/puppet.conf.out
[root@puppetmaster ~]# cat /etc/puppet/puppet.conf.out | grep modulepath
    modulepath = /etc/puppet/modules:/usr/share/puppet/modules
[root@puppetmaster modules]# tree /etc/puppet/modules/
/etc/puppet/modules/
└── motd
    ├── files  #存放文件目录
    │   └── etc
    │       └── motd
    ├── manifests  #存放模块pp配置文件目录
    │   └── init.pp
    └── templates #存放模板目录
5 directories, 2 files
2、编写pp文件
 
vim /etc/puppet/modules/motd/manifests/init.pp 
class motd{                 #定义一个类叫motd
  package{ 'setup':    #定义package资源
    ensure => present,  #要求setup这个包处于被安装状态
  }
  file{ '/usr/local/spark/conf/spark-env.sh':  #定义file资源
    ensure  => present,  #要求file文件处于存在状态
    owner   => 'hadoop', #要求file文件属主为root
    group   => 'hadoop', #要求file文件属组为root
    mode    => '0644', #要求file文件权限为644
    source  => "puppet://$puppetserver/modules/motd/spark-env.sh", #要求file文件从puppetmaster端服务器下载
    require => Package['setup'], #要求文件被配置之前先执行package资源
  }
}
 
class motd{                 #定义一个类叫motd
 
  file{ '/usr/local/spark/conf/slaves':  #定义file资源
    ensure  => present,  #要求file文件处于存在状态
    owner   => 'hadoop', #要求file文件属主为root
    group   => 'hadoop', #要求file文件属组为root
    mode    => '0644', #要求file文件权限为644
    source  => "puppet://$puppetserver/modules/motd/slaves", #要求file文件从puppetmaster端服务器下载
    require => Package['setup'], #要求文件被配置之前先执行package资源
  }
}
 
我是想把spark的配置文件推送过去,把 slaves  spark-env.sh 文件放到/etc/puppet/modules/motd/files/
3、编写site.pp文件
 
vim /etc/puppet/manifests/site.pp 
node 'slave1.hadoop'{
  include  motd
}
node 'slave2.hadoop'{
  include  motd
}
node 'slave3.hadoop'{
  include  motd
}
node 'slave4.hadoop'{
  include  motd
}
 
四、测试motd模块
 
[root@slave1.hadoop]  # puppet agent --test
info: Caching catalog for slave1.hadoop
info: Applying configuration version '1434610115'
notice: /Stage[main]/Motd/File[/usr/local/spark/conf/spark-env.sh]/mode: mode changed '0755' to '0644'
notice: /Stage[main]/Motd/File[/usr/local/spark/conf/slaves]/content: 
--- /usr/local/spark/conf/slaves        2015-06-17 18:38:45.632168667 +0800
+++ /tmp/puppet-file20150618-24226-13vm4mn-0    2015-06-18 14:52:20.897168668 +0800
@@ -1,2 +1,5 @@
 # A Spark Worker will be started on each of the machines listed below.
 slave1.hadoop
+slave2.hadoop
+slave3.hadoop
+slave4.hadoop
 
info: FileBucket adding {md5}51e87787a634c96c1eaa88ca994048f4
info: /Stage[main]/Motd/File[/usr/local/spark/conf/slaves]: Filebucketed /usr/local/spark/conf/slaves to puppet with sum 51e87787a634c96c1eaa88ca994048f4
notice: /Stage[main]/Motd/File[/usr/local/spark/conf/slaves]/content: content changed '{md5}51e87787a634c96c1eaa88ca994048f4' to '{md5}14ca075cbc84d15a65dc07e9857c34c7'
info: Creating state file /var/lib/puppet/state/state.yaml
notice: Finished catalog run in 0.70 seconds
最后编辑:
作者:saunix
大型互联网公司linux系统运维攻城狮,专门担当消防员

留下一个回复