master端收到之后首先(classify)分类识别来请求的是哪个客户端和这个客户端要哪些东西,因而master端就在本地根据定义的站点清单给这个agent端声明哪些类。前端
Ps:每个agent端必须向master端明确的发送本身的nodename。node
https通信的构建过程:客户端发请求服务端把证书扔给客户端,客户端验证这个这个证书。而在puppet中 是双向认证的,master要验证agent端的证书,agent还要验证master端的证书。也就意味着agent端发请求会把本身的证书扔给master端的,master要根据agent本身声明的名字和agent本身发过来的证书来验证两者之间是否一致的,若是能保持一致,那么咱们就认为这是经过的,更重要的是master端还保存着ca证书,所以它还要使用ca去验证此证书各个方面的有效性,这一切都经过了,双方才能够创建基于ssl通讯会话的。这里面的通讯过程agent要发送本身的节点名,而agent向master请求时尽可能使用master的节点名称而不要使用ip地址。所以在咱们的puppet工做环境中,DNS服务相当重要。每个节点都必需要有一个尽量惟一的名字。经过dns服务可以解析,并且能彼此之间经过解析后可以互相通讯才能够.mysql
ssl xmlrpc, https
8140/tcp
master : puppet , puppet-server, facter
agent : puppet facter
服务端启动puppet-server ,监听端口8140
agent端启动puppet, 不监听端口,每隔固定时间向master端请求本身相关的catelognginx
master端安装:web
sudo yum install puppet-server puppet facter
安装master必备的两个包,puppet 和puppet-server,若是本机也须要请求catelog那就须要安装facter,这里咱们想让master同时也作agent端,因此上面yum安装了 这三个包。正则表达式
查看puppet-server安装包sql
$ rpm -ql puppet-server-3.6.2-3.el7.noarch /etc/puppet/fileserver.conf /etc/puppet/manifests /usr/lib/systemd/system/puppetmaster.service /usr/share/man/man8/puppet-kick.8.gz /usr/share/man/man8/puppet-master.8.gz /usr/share/man/man8/puppet-queue.8.gz
从安装路能够看出:puppet-server并无什么可执行文件,只有几个目录、文件以及使用手册。这就说明master的执行程序也是puppet提供的子命令。
这里简单说明下:centos
fileserver.conf是提供fileserver功能的配置文件 /etc/puppet/manifests 目录是存放站点清单的目录
安装puppet-server以后,就可使用puppet-server的功能了。服务器
puppet的配置文件
查看配置文件目录:restful
$ ls /etc/puppet/ auth.conf fileserver.conf manifests modules puppet.conf
主配置文件 puppet.conf ,是init的配置文件类型,像mysql服务的配置文件,一个配置文件同时有mysqlclient和mysqld的配置项,咱们来看看默认配置文件内容:
$ cat /etc/puppet/puppet.conf [main] # The Puppet log directory. # The default value is '$vardir/log'. logdir = /var/log/puppet # Where Puppet PID files are kept. # The default value is '$vardir/run'. rundir = /var/run/puppet # Where SSL certificates are kept. # The default value is '$confdir/ssl'. ssldir = $vardir/ssl [agent] # The file in which puppetd stores a list of the classes # associated with the retrieved configuratiion. Can be loaded in # the separate ``puppet`` executable using the ``--loadclasses`` # option. # The default value is '$confdir/classes.txt'. classfile = $vardir/classes.txt # Where puppetd caches the local configuration. An # extension indicating the cache format is added automatically. # The default value is '$confdir/localconfig'. localconfig = $vardir/localconfig
咱们看配置文件中并无puppet-server的配置内容,能够用puppet config命令对配置文件进行操做
[main] 表示agent和master均可以使用的配置
[agent] agent进程的配置
puppet config 命令使用
查看命令帮助
$ puppet help config ... ACTIONS: print Examine Puppet's current settings. set Set Puppet's settings. See 'puppet man config' or 'man puppet-config' for full help.
可使用print查看当前puppet的配置(包括master, agent, main)
$ puppet config print confdir = /home/ops-manager/.puppet vardir = /home/ops-manager/.puppet/var name = config logdir = /home/ops-manager/.puppet/var/log log_level = notice disable_warnings = [] priority = trace = false profile = false autoflush = true ... 下面有不少配置项,就不贴出来了
可使用set 来单独设置某一个配置项
经过 puppet print列出的配置项都是默认的配置项。但展现出来的并无说明某一个配置项的含义。并且也不知道哪些配置是master端的,哪些是agent端的。这个print也只能用于管理员确认某一个配置项时使用。那么咱们想看配置文件说明怎么办? -- 用puppet doc 子命令,doc自命令分段、分类介绍。可使用puppet doc --list查看分为哪几个段,如:
$ puppet doc --list configuration - A reference for all settings function - All functions available in the parser indirection - Indirection types and their terminus classes metaparameter - All Puppet metaparameters and all their details providers - Which providers are valid for this machine report - All available transaction reports type - All Puppet resource types and all their details
使用puppet doc --reference configuration 能够查看配置文件相关的文档
# Configuration Reference **This page is autogenerated; any changes will get overwritten** *(last generated on 2018-03-27 05:38:24 +0000)* ## Configuration Settings * Each of these settings can be specified in `puppet.conf` or on the command line. * When using boolean settings on the command line, use `--setting` and `--no-setting` instead of `--setting (true|false)`. * Settings can be interpolated as `$variables` in other settings; `$environment` is special, in that puppet master will interpolate each agent node's environment instead of its own. * Multiple values should be specified as comma-separated lists; multiple directories should be separated with the system path separator (usually a colon). ... 一样是一堆内容,能够做为往后查找手册
puppet config print命令 和puppet doc --reference configuration命令内容都不太适合刚入手查看。
有更适合新手的查看方法:
puppet master --genconfig 显示master的相关配置 puppet agent --genconfig 显示agent的相关配置
使用上面两个命令能够帮助咱们了解master、agent端的默认配置项。若是我想改这些默认配置项,能够把内容放到puppet.conf文件中,但要注意的是,puppet master --genconfig 和 puppet agent --genconfig命令都是经过调用puppet.conf文件进行显示的,因此你千万不能直接就把puppet.conf文件给覆盖了,这样会有很大问题的。正确的作法都是先将显示的内容输出到一个新建的文件中,而后在不puppet.conf 重命名为puppet.conf_default,在把那个新文件命名为puppet.conf。
puppet master --genconfig > puppet_new.conf puppet agent --genconfig >> puppet_new.conf注意: (1) 生产新的配置以前不能删除或移动原有的puppet.conf; (2) 生成的配置中,有的参数已经被废弃,与现有puppet版本不兼容,所以还需进行手动排查。
(3) 有的参数的默认值与如今的版本所支持值可能不相兼容。
所以若是咱们本身不想麻烦的话,最好不要本身手动生成配置文件,只要修改部分想修改的相关项便可。
puppet配置文件的组成部分:
[main] [master] [agent]
运行puppet master puppet agent
puppet master/agent各节点是强依赖主机名的,因此在启动meter/agent工做模式时,要确保各节点之间能够经过FQDN彻底限定名可以互相解析。
以服务方式启动命令 : puppet master
建议第一次启动,使用参数让master在前端运行:
puppet master --no-daemonize -v -v 表示工做在详细模式 --no-daemonize 不工做在守护模式下 -d 调试信息模式,可能会有一些干扰信息,咱们这里就不使用它。
如下是运行结果
若是咱们看到上面的信息,没有什么错误信息的话,其实咱们就能够直接把puppet master服务启动了,不用进行更改配置了。即便用它的默认配置就能够工做起来。同时咱们能够看到默认证书存放的位置/var/lib/puppet/ssl。
若是此次生成的内容不想要了,如何作的呢?
只要删除刚刚生成的证书目录便可:
rm -rf /var/lib/puppet/ssl/*
而后再次运行puppet master --no-daemonize -v 重新生成一遍。若是没有问题就能够启动在后台。在centos7上有专门的unit file,如:
# ls /usr/lib/systemd/system/puppet puppetagent.service puppetmaster.service puppet.service
这里puppetagent.service 是链接到 puppet.service 都是启动puppet agent的
puppetmaster.service 是启动 puppet master的
[root@ops ssl]# systemctl start puppetmaster.service 使用ss -tnl查看端口
接着咱们就要安装 、 配置agent端
安装就简单了
sudo yum install epel-realese sudo yum install agent facter
配置文件是 /etc/puppet/puppet.conf 中的 [agent] 段
默认配置文件中内容很少,咱们想首先 配置的应该是指明master端的 FQDN彻底限定名
若是咱们不在配置文件中指定,也可使用puppet agent命令指定
puppet agent --server puppet-master.my.com
注意若是命令执行了,agent端会自动生成一个ssl私钥,并生成一个证书签署请求然后发送给master端,并等待master端给它作签署,在签署完成以前双方是不能够进行通讯的。所以咱们第一次作的时候,对于agent端而言 仍是同样 咱们先作测试,看能不能正常经过。命令以下:
puppet agent --server ops-zabbix.blockshine.com --noop --test -v --no-daemonize -v 显示 --noop 表示dry run ,预演的意思 --test 表示测试
输出结果如图:
接下来把--noop 和 --test 选项去掉
执行后界面卡住以下:
签署证书
打开master端,使用puppet help cert命令查看帮助
puppet cert <action> [-h|--help] [-V|--version] [-d|--debug] [-v|--verbose] [--digest <digest>] [<host>] Action list 查看全部待签署证书 sign 签署证书 puppet cert list 显示未签发的 puppet cert list --all 显示已经签发和未签发的 puppet sign 节点 签发指定节点 puppet sign --all 签发全部
上面显示已经完成了为节点签署证书,客户端再次启动就显示以下:
在master端:
(1)安装全部要用到的模块:
puppet module install 自建
(2)定义site manifest:
/etc/puppet/manifests/site.pp node 'NODE_NAME' { ... puppet code ... } 例如: node 'node3.my.com'{ include nginx::proxy } include直接跟类名,由于模块中的类能够全局进行直接调用的
当完成以上配置,而且运行master/agent后,agent每隔30分钟会想master端索取catelog,但有时候要马上执行,那么能够在master端进行推送,推送命令稍后说。
其实到这一步骤,基本上就够咱们使用了,接下来就是一些比较好的实例用法。
站点清单高级定义方式
site.pp定义节点的方式:
(1) 以主机名直接给出其相关定义:
node 'NODE_NAME' { 节点变量$web_port = 8088 ... puppet code ... } (2) 把功能相近的主机事先按统一格式命名,按统一格式调用: node /^web\d+\.my\.com/ { ... puppet code ... } (3) 假如公司维护的节点有上千个,主机命名要依照 命名规范 进行命名 假如如今全部节点都须要进行ntp 时间同步,那么有没有比较方便的定义方法?这就是定义基节点,然后每个节点去继承基节点。 node basenode { include ntp } node web.my.com inherits basenode { include nginx::proxy } 当某一模块被多数主机所共用时,能够经过定义基节点的方式,让其余节点经过继承的方式获取这个公共配置。 (4)无论怎么讲,咱们把上千个节点的配置放在site.pp文件中,也显得臃肿,不方便查找。能够经过对节点配置进行分段管理。 /etc/puppet/manifests/ site.pp import "webservers/*.pp" webservers/ unicom.pp telecom.pp cacheservers/ appservers/ (5) 模块当中,若是manifest/init.pp 下要定义的类太多的话,也能够采用分段切割,放在多个文件中,可是在init.pp中要把他们给import 进来,道理和节点分段管理同样的。
角色-运营商-机房名-IP.管理域名
web1-unicom-sh-1.1.1.1.magedu.com
依赖于主机名称互相通讯
DNS
主机名命令规范:
角色-运营商-机房名-IP.管理域名
web1-unicom-sh-1.1.1.1.magedu.com
定义节点:
node 'NODE_NAME' { 变量 声明类 } 定义在站点清单:/etc/puppet/manifests/site.pp
节点名称定义亦能够继承:
node basenode { $dbport = 3306 include baseserver } node "node2.magedu.com" inherits basenode { include nginx } node "node3.magedu.com" inherits basenode { $dbport = 3307 include mysql } 目的:为全部节点应用相同的全局变量,以及完成节点的初始化; 节点定义方式: 一、每节点单独定义; 二、在节点名称中使用正则表达式; node "/node[0-9]+\.magedu\.com/" { }
puppet进程的配置文件:puppet.conf
生成配置:puppet master --genconfig > /etc/puppet/puppet.conf
puppet agent --genconfig >> /etc/puppet/puppet.conf
[main], [master], [agent] 了解配置文件路径:puppet doc --configprint confdir
master端而言:/etc/puppet/manifests/site.pp
站点清单
认证配置文件:auth.conf 应用于puppet的restful风格的API的访问受权; 名称空间访问认证配置文件:namespaceauth.conf [puppetmaster] allow *.magedu.com autosign.conf
配置puppet master支持多种不一样的环境:
puppet.conf [master] environment = development, testing, production [development] manifests = /etc/puppet/manifests/development/site.pp modulepath = /etc/puppet/modules/development/:/usr/share/modules/development fileserverconfig = /etc/puppet/fileserver.conf.development [testing] manifests = /etc/puppet/manifests/testing/site.pp modulepath = /etc/puppet/modules/testing/:/usr/share/modules/testing fileserverconfig = /etc/puppet/fileserver.conf.testing [production] manifests = /etc/puppet/manifests/production/site.pp modulepath = /etc/puppet/modules/production/:/usr/share/modules/production fileserverconfig = /etc/puppet/fileserver.conf.production puppet agent: [agent] environment = development
模块管理:
Puppet Forge: puppet维护模块仓库,大部分由第三方做者提供
puppet module list search install
Puppet kick机制:
紧急推送配置时使用。
puppet架构扩展:
单台master节点可能会出现瓶颈之处:
认证功能 文件服务 网络 解决思路:单机扩展 Nginx+Mongrel Apache+Passenger Nginx+Passenger 解决思路:多机扩展
mcollective
Foreman