安装
Server端
yum install -y puppetserver
service puppetserver start # 有些用的是puppetmaster,如果启动报内存限制,那么修改配置/etc/sysconfig/puppetserver将 JAVA_ARGS="-Xms512m -Xmx512m"修改为JAVA_ARGS="-Xms2g -Xmx2g"
Client端
sudo rpm -Uvh https://yum.puppetlabs.com/puppetlabs-release-pc1-el-7.noarch.rpm # 这里要注意版本是6还是7
yum install -y puppet-agent
dashboard的安装
1 | 首先得有数据库 |
Hello World举例
新建module
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17cd /opt/puppetlabs/puppet/modules/
mkdir -p helloworld/manifests/
vim helloworld/manifests/init.pp # 内容如下:
class helloworld {
notify { 'hello, world!': }
}
vim helloworld/manifests/motd.pp # 内容如下:
class helloworld::motd {
file { '/etc/motd':
owner => 'root',
group => 'root',
mode => '0644',
content => "hello, world!\n",
}
}将module添加到主配置文件
1
2
3
4
5
6cd /etc/puppetlabs/code/environments/production/manifests
vim site.pp # 内容如下:
node default{
class { 'helloworld': }
class { 'helloworld::motd': }
}
测试
分别在两个端启动puppet服务,然后客户端执行puppet agent -t
TroubleShooting
客户端显示”no certificate found and waitforcert is disabled”,可以首先在server端
puppet cert list
看看是否有客户端的认证请求,如果有,就在服务器端执行puppet cert sign agent_name
出现如下错误:
Exception in thread "main" java.lang.IllegalStateException: Cannot initialize master with partial state; need all files or none. Found: /etc/puppetlabs/puppet/ssl/private_keys/puppet.novalocal.pem Missing: /etc/puppetlabs/puppet/ssl/certs/puppet.novalocal.pem
这个问题一般是由于客户端比服务端先开启服务造成的
rm -rf /etc/puppetlabs/puppet/ssl/*