centos7安装配置puppet系统

os centos7.6

puppet version: 3.6.2

 

两台机器:s0是master,s1是agent 

安装前准备:

准备好yum源,关闭selinux和防火墙或puppet master上防火墙需要开启tcp 8140端口;

ntp时间要同步

 

 

前期准备工作好了以后

 

s0 install puppet-server

s1 install puppet

 

s0:

vim /etc/puppet/puppet.conf,添加以下内容:

[agent]模块下添加内容:

server = s0

certname = cert.s0

添加[master]模块,编辑下列内容

[master]

certname = s0

 

s1修改/etc/puppet/puppet.conf

[agent]下添加

server = s0

certname = cert.s1

 

申请证书:

s1执行 puppet agent -t

 

 

Master注册证书

[root@s0 ~]# 

puppet cert --sign cert.s1

 

客户端再次请求

[root@s1 puppet]# puppet agent -t

Info: Caching certificate for cert.s1

Info: Caching certificate_revocation_list for ca

Info: Caching certificate for cert.s1

Info: Retrieving pluginfacts

Info: Retrieving plugin

Info: Caching catalog for cert.s1

Info: Applying configuration version '1590544793'

Info: Creating state file /var/lib/puppet/state/state.yaml

Notice: Finished catalog run in 0.01 seconds

 

第一次启动puppet,可以使用 

puppet agent -t --verbose --no-daemonize 命令测试。 

参数 --verbose使master输出详细的日志,而--no-daemonize参数使masteriS程运行在前台并将输出重定向到标准输出 。你还可以加上--debug参数 来产生更加详细的调 试输出 。 Puppet agent安装配置

查看监听状态 puppetmaster服务开启后,默认监听TCP 8140端口

[root@s0 ~]# netstat -nlatp | grep 8140

tcp        0      0 0.0.0.0:8140                0.0.0.0:*                   LISTEN      18524/ruby 

[root@s0 ~]# lsof -i:8140

COMMAND    PID   USER   FD   TYPE DEVICE SIZE/OFF NODE NAME

puppetmas 1976 puppet    5u  IPv4  14331      0t0  TCP *:8140 (LISTEN)

 

 

至此已安装配置好puppet。接下来举例说明如何使用puppet。

 

master(s0)端建立site文件。注意:site.pp文件中,node后的主机名,不能使用后缀,例如s1.maple.com,只能使用s1

touch /etc/puppet/site.pp

注意默认路径是/etc/puppet/manifests/,文件名是site.pp

node s1{

file {'hello':

path => '/root/hello.txt',

owner => 'root',

group => 'root',

mode => '655',

content => 'hello world from puppet!\n'

     }

}

 

客户端s1 手动测试一下

puppet agent -t

成功后/root/hello.txt按照s0 site.pp文件的定义创建成功

 

由于各种原因产出报错,比如修改了主机名或者配置文件,可重启后再次尝试。

 

s1启动puppet服务以后,默认每30分钟向master检测更新。如需修改,puppet.conf添加一行

[agent]
...
#同步更新价格,单位是秒
runinterval = 600

 

 

 

4、Client configuration
rpm –ivh puppetlabs-release-5-6.noarch.rpm
yum install puppet
/etc/puppet/puppet.conf     修改如下内容,值为puppet服务器的hostname
     PUPPET_SERVER=server.example.com
执行 /etc/init.d/puppet start

或者不修改配置文件,直接puppet agent –server=server.example.com

 

5、Commands
查看服务端证书

puppet cert list –all

查看模块位置

puppet config print modulepath

查看报告

Puppet agent –t –summarize

6、Certificate Register

客户端agent启动时候会给服务器发送证书申请
在服务器上有上述命令查看证书,然后签名

puppet cert sign station3.example.com

7、 Certificate Cancle

(1)注销证书

puppet cert revoke station3.example.com(只是让证书失效)
puppet cert clean station3.example.com (删除证书)

重启puppetmaster

此时,station3.exmaple.com不能连接到puppet server
(2)重新注册证书
在客户端

rm -f /var/lib/puppet/ssl/certs/station3.example.com.pem
rm -f /var/lib/puppet/ssl/certificate_requests/station3.example.com.pem

然后重启puppet,在服务器端执行puppet cert list就能看见重新申请证书。

(3)自动注册证书
可以设置master自动签发所有的证书,我们只需要在/etc/puppet 目录下创建 autosign.conf 文件。(不需要修改 /etc/puppet/puppet.conf文件,因为我默认的autosign.conf 文件的位置没有修改)

vim /etc/puppet/autosign.conf
*.exmaple.com

     这样所有来自example.com域上的所有客户端就自动注册了。

posted @ 2020-05-22 18:02  黑剑石清  阅读(407)  评论(0编辑  收藏  举报