server = node5.example.com
2.重启puppet agent
systemctl restart puppet
3.生成证书请求文件csr,并发送给puppet server
[root@node6 ~]# puppet agent -t
Exiting; no certificate found and waitforcert is disabled
4.puppet server签发(sign)
[root@node5 ~]#
+ "node5.example.com" (SHA256) 4D:C2:73:E8:97:3D:11:1F:D5:43:D6:DA:91:DE:9D:2C:87:0B:39:E9:46:1F:23:B2:4E:0A:01:E7:44:DE:1A:8E (alt names: "DNS:node5.example.com", "DNS:puppet", "DNS:puppet.example.com")
[root@node5 ~]#
Notice: Signed certificate request for node6.example.com
Notice: Removing file Puppet::SSL::CertificateRequest node6.example.com at '/var/lib/puppet/ssl/ca/requests/node6.example.com.pem'
5.从puppet server下载签发好的证书,注册完成
[root@node6 ~]# puppet agent -t
Exiting; no certificate found and waitforcert is disabled
[root@node6 ~]# puppet agent -t
Info: Caching certificate for node6.example.com
Info: Caching certificate_revocation_list for ca
Info: Caching certificate for node6.example.com
Warning: Unable to fetch my node definition, but the agent run will continue:
Warning: undefined method `include?' for nil:NilClass
Info: Retrieving pluginfacts
Info: Retrieving plugin
Info: Caching catalog for node6.example.com
Info: Applying configuration version '1477232225'
Info: Creating state file /var/lib/puppet/state/state.yaml
Notice: Finished catalog run in 0.01 seconds
第一次run会出现Warning
删除客户端证书
puppet cert clean node6.example.com
puppet cert clean --all #删除所有证书,包括puppet server本身
二.配置管理
说明:puppet默认会从site.pp开始执行,.pp配置定义完成后,客户端即时生效需要在客户端执行puppet agent -t
1.创建根pp文件---site.pp
touch /etc/puppet/manifests/site.pp
2.用户组
cat >>/etc/puppet/manifests/group.pp <<'EOF'
group{'test':
}
group{'testgroup1':
}
group{'testgroup2':
}
EOF
cat >>/etc/puppet/manifests/site.pp <<'EOF'
import
EOF
3.用户
cat >>/etc/puppet/manifests/user.pp <<'EOF'
$testgroup=['testgroup1','testgroup2']
user{'test':
}
EOF
cat >>/etc/puppet/manifests/site.pp <<'EOF'
import
EOF
提示:password的值必需是hash过的,如/etc/shadow中的password段
4.计划任务
cat >>/etc/puppet/manifests/cron.pp <<'EOF'
cron
}
EOF
cat >>/etc/puppet/manifests/site.pp <<'EOF'
import
EOF
5.exec & file(dir)
http://puppet.wikidot.com/file
cat >>/etc/puppet/manifests/exec.pp <<'EOF'
$PATH=['/bin','/sbin','/usr/bin','/usr/sbin','/usr/local/bin','usr/local/sbin']
file
}
file
}
exec
}
EOF
cat >>/etc/puppet/manifests/site.pp <<'EOF'
import
EOF
感觉puppet同步目录的效率不尽人意,可以考虑rsync
[root@node6 ~]# ls -ld /var/www/html/dedemcs/
drwxr-xr-x. 14
apache apache 4096 10月 23
20:46
6.类和子类
i.定义类
mkdir
-p
cat >>/etc/puppet/modules/lamp/manifests/init.pp <<'EOF'
class
}
class
}
class
}
class
}
EOF
ii.引用类
cat >>/etc/puppet/manifests/node6.pp <<'EOF'
node
}
EOF
cat >>/etc/puppet/manifests/site.pp <<'EOF'
import
EOF
说明:class名默认为/etc/puppet/modules下面的目录名,如上,我定义了一个叫lamp的class
首先需要在/etc/puppet/modules下创建lamp/{maniffests,files}目录
再定义class内容/etc/puppet/modules/lamp/manifests/init.pp, init.pp名字也是默认的,引用类时只需要include对应类的名字即可。这里定义了3个父类一个子类,是否有意义暂且不谈,这里只描述下子类继承的概念。
notify
[root@node6 ~]# puppet agent -t
Info: Retrieving pluginfacts
Info: Retrieving plugin
Info: Loading facts
Info: Caching catalog for node6.example.com
Info: Applying configuration version '1477223265'
Notice: /Stage[main]/Main/Exec[/root/test.sh]/returns: executed successfully
Notice: /Stage[main]/Lamp::Mariadb-sub/Exec[mariadb-test]/returns: executed successfully
Notice: Finished catalog run in 0.37 seconds
7.定义
http://puppet.wikidot.com/intro
补充
安装模块
puppet
module install
[root@node5 manifests]# puppet module install puppetlabs-apache
Notice: Preparing to install into /etc/puppet/modules ...
Notice: Downloading from https://forgeapi.puppetlabs.com ...
Notice: Installing -- do not interrupt ...
/etc/puppet/modules
└─┬ puppetlabs-apache (v1.10.0)
三.WebUI
以foreman为例:
请参看Foreman安装配置
另puppetdashboard,见